From 39541291959ba143c5a9e8272b45d49aea654f35 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 18 Oct 2006 23:11:55 +0000 Subject: [PATCH] update test to use Test::More and add hardcoded test account from auth.net, RT#22076 --- Changes | 1 + Makefile.PL | 5 +--- t/bop.t | 10 ++++---- t/capture.t | 71 +++++++++++++++++++++++---------------------------- t/check.t | 33 ++++++++++++++---------- t/credit_card.t | 31 ++++++++++------------ t/lib/test_account.pl | 28 ++++++++++++++++++++ t/load.t | 10 ++++---- t/test_account | 2 ++ 9 files changed, 107 insertions(+), 84 deletions(-) create mode 100644 t/lib/test_account.pl create mode 100644 t/test_account diff --git a/Changes b/Changes index 1e858de..b9d57b7 100644 --- a/Changes +++ b/Changes @@ -12,6 +12,7 @@ Revision history for Perl extension Business::OnlinePayment::AuthorizeNet. - Quiet an uninit value warning when customer_org is not set. - Fix t/credit_card.t test to use a date 11 months in the future as the expiration date, and to print the error message on failure. + - Update tests to use Test::More 3.15 Wed Mar 16 01:10:51 PST 2005 - Ask for ',' delimiter and '"' quote explicitly to prevent problems diff --git a/Makefile.PL b/Makefile.PL index 6563db8..1f9c265 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,15 +1,12 @@ use ExtUtils::MakeMaker; -# See lib/ExtUtils/MakeMaker.pm for details of how to influence -# the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Business::OnlinePayment::AuthorizeNet', 'VERSION_FROM' => 'AuthorizeNet.pm', # finds $VERSION 'AUTHOR' => 'Ivan Kohler ', #really just #the maintainer - #'NORECURS' => 1, # dont descend into subdirectories 'PREREQ_PM' => { 'Net::SSLeay' => 0, 'Text::CSV_XS' => 0, 'Business::OnlinePayment' => 0, + 'Test::More' => 0.42, }, - #'dist' => {CI => 'ci -l'}, ); diff --git a/t/bop.t b/t/bop.t index 64332c5..68f5f98 100644 --- a/t/bop.t +++ b/t/bop.t @@ -1,5 +1,5 @@ -BEGIN { $| = 1; print "1..1\n"; } -END {print "not ok 1\n" unless $loaded;} -use Business::OnlinePayment; -$loaded = 1; -print "ok 1\n"; +#!/usr/bin/perl -w + +use Test::More tests => 1; + +use_ok 'Business::OnlinePayment'; diff --git a/t/capture.t b/t/capture.t index 7c40e9a..8e1d913 100644 --- a/t/capture.t +++ b/t/capture.t @@ -1,17 +1,19 @@ -BEGIN { $| = 1; print "1..2\n"; } +#!/usr/bin/perl -w -#testing/testing is valid and seems to work... (but not for auth + capture) -print "ok 1 # Skipped: need a valid Authorize.Net login/password to test\n"; -print "ok 2 # Skipped: need a valid Authorize.Net login/password to test\n"; -exit; +use Test::More; +require "t/lib/test_account.pl"; -use Business::OnlinePayment; +my($login, $password) = test_account_or_skip(); +plan tests => 4; -my $tx = new Business::OnlinePayment("AuthorizeNet"); +use_ok 'Business::OnlinePayment'; + +my $tx = Business::OnlinePayment->new("AuthorizeNet"); +$tx->server('test.authorize.net'); $tx->content( type => 'VISA', - login => 'testing',# CHANGE THESE TO TEST - password => 'testing',# + login => $login, + password => $password, action => 'Authorization Only', description => 'Business::OnlinePayment visa test', amount => '49.95', @@ -24,41 +26,32 @@ $tx->content( state => 'UT', zip => '84058', card_number => '4007000000027', - expiration => '08/06', + expiration => expiration_date(), ); $tx->test_transaction(1); # test, dont really charge $tx->submit(); -unless($tx->is_success()) { - print "not ok 1\n"; - print "not ok 2\n"; -} else { - my $order_number = $tx->order_number; - warn $order_number; - print "ok 1\n"; +ok($tx->is_success()) or diag $tx->error_message; - my $settle_tx = new Business::OnlinePayment("AuthorizeNet"); - $settle_tx->content( - type => 'VISA', - login => 'testing', # CHANGE THESE TO TEST - password => 'testing', # - action => 'Post Authorization', - description => 'Business::OnlinePayment visa test', - amount => '49.95', - invoice_number => '100100', - order_number => '111', - card_number => '4007000000027', - expiration => '08/06', - ); +my $order_number = $tx->order_number; +like $order_number, qr/^\d+$/; - $settle_tx->test_transaction(1); # test, dont really charge - $settle_tx->submit(); +my $settle_tx = Business::OnlinePayment->new("AuthorizeNet"); +$settle_tx->server('test.authorize.net'); +$settle_tx->content( + type => 'VISA', + login => $login, + password => $password, + action => 'Post Authorization', + description => 'Business::OnlinePayment visa test', + amount => '49.95', + invoice_number => '100100', + order_number => '111', + card_number => '4007000000027', + expiration => expiration_date(), +); - if($settle_tx->is_success()) { - print "ok 2\n"; - } else { - warn $settle_tx->error_message; - print "not ok 2\n"; - } +$settle_tx->test_transaction(1); # test, dont really charge +$settle_tx->submit(); -} +ok($settle_tx->is_success()) || diag $settle_tx->error_message; diff --git a/t/check.t b/t/check.t index 29344f6..140dace 100644 --- a/t/check.t +++ b/t/check.t @@ -1,32 +1,39 @@ -BEGIN { $| = 1; print "1..1\n"; } +#!/usr/bin/perl -w -print "ok 1 # Skipped: testing account won't accept ACH transactions\n"; exit; +use Test::More; +require "t/lib/test_account.pl"; -use Business::OnlinePayment; +my($login, $password) = test_account_or_skip(); +plan tests => 2; -# checks are broken it seems -my $ctx = new Business::OnlinePayment("AuthorizeNet"); +use_ok 'Business::OnlinePayment'; + +my $ctx = Business::OnlinePayment->new("AuthorizeNet"); +$ctx->server('test.authorize.net'); $ctx->content( type => 'CHECK', - login => 'testing', - password => 'testing', + login => $login, + password => $password, action => 'Normal Authorization', amount => '49.95', invoice_number => '100100', customer_id => 'jsk', first_name => 'Tofu', last_name => 'Beast', + account_name => 'Tofu Beast', account_number => '12345', - routing_code => '123456789', + routing_code => '111000025', # BoA in Texas taken from Wikipedia bank_name => 'First National Test Bank', + account_type => 'Checking', + license_num => '12345678', + license_state => 'OR', + license_dob => '1975-05-21', ); $ctx->test_transaction(1); # test, dont really charge $ctx->submit(); -print $ctx->is_success()."\n"; +SKIP: { + skip $ctx->error_message, 1 if $ctx->result_code == 18; -if($ctx->is_success()) { - print "ok 1\n"; -} else { - print "not ok 1 (".$ctx->error_message().")\n"; + ok( $ctx->is_success() ) || diag $ctx->error_message; } diff --git a/t/credit_card.t b/t/credit_card.t index 0063804..8cade30 100644 --- a/t/credit_card.t +++ b/t/credit_card.t @@ -1,19 +1,19 @@ -BEGIN { $| = 1; print "1..1\n"; } +#!/usr/bin/perl -w -#testing/testing is valid and seems to work... -#print "ok 1 # Skipped: need a valid Authorize.Net login/password to test\n"; exit; +use Test::More; +require "t/lib/test_account.pl"; -use Business::OnlinePayment; +my($login, $password) = test_account_or_skip(); +plan tests => 2; + +use_ok 'Business::OnlinePayment'; -my($month, $year) = (localtime)[4,5]; -$year++; # So we expire next year. -$year %= 100; # y2k? What's that? - -my $tx = new Business::OnlinePayment("AuthorizeNet"); +my $tx = Business::OnlinePayment->new("AuthorizeNet"); +$tx->server('test.authorize.net'); $tx->content( type => 'VISA', - login => 'testing', - password => 'testing', + login => $login, + password => $password, action => 'Normal Authorization', description => 'Business::OnlinePayment visa test', amount => '49.95', @@ -26,14 +26,9 @@ $tx->content( state => 'UT', zip => '84058', card_number => '4007000000027', - expiration => sprintf("%02d/%02d", $month, $year), + expiration => expiration_date(), ); $tx->test_transaction(1); # test, dont really charge $tx->submit(); -if($tx->is_success()) { - print "ok 1\n"; -} else { - warn $tx->error_message; - print "not ok 1\n"; -} +ok($tx->is_success()) or diag $tx->error_message; diff --git a/t/lib/test_account.pl b/t/lib/test_account.pl new file mode 100644 index 0000000..b86082b --- /dev/null +++ b/t/lib/test_account.pl @@ -0,0 +1,28 @@ +sub test_account_or_skip { + my($login, $password) = test_account(); + + unless( defined $login ) { + plan skip_all => "No test account"; + } + + return($login, $password); +} + +sub test_account { + open TEST_ACCOUNT, "t/test_account" or return; + my($login, $password) = ; + chomp $login; + chomp $password; + + return($login, $password); +} + +sub expiration_date { + my($month, $year) = (localtime)[4,5]; + $year++; # So we expire next year. + $year %= 100; # y2k? What's that? + + return sprintf("%02d/%02d", $month, $year); +} + +1; diff --git a/t/load.t b/t/load.t index 5d2dfc1..2e4c366 100644 --- a/t/load.t +++ b/t/load.t @@ -1,5 +1,5 @@ -BEGIN { $| = 1; print "1..1\n"; } -END {print "not ok 1\n" unless $loaded;} -use Business::OnlinePayment::AuthorizeNet; -$loaded = 1; -print "ok 1\n"; +#!/usr/bin/perl -w + +use Test::More tests => 1; + +use_ok 'Business::OnlinePayment::AuthorizeNet'; diff --git a/t/test_account b/t/test_account new file mode 100644 index 0000000..304a31f --- /dev/null +++ b/t/test_account @@ -0,0 +1,2 @@ +cnpdev6024 +authnet001 -- 2.11.0