diff options
author | ivan <ivan> | 2006-10-18 23:11:55 +0000 |
---|---|---|
committer | ivan <ivan> | 2006-10-18 23:11:55 +0000 |
commit | 39541291959ba143c5a9e8272b45d49aea654f35 (patch) | |
tree | bf457467de08ab63b2188ade1f851d31e947686c /t | |
parent | 613a646d7362d686c7b1f241b1bb47db50968de7 (diff) |
update test to use Test::More and add hardcoded test account from auth.net, RT#22076
Diffstat (limited to 't')
-rw-r--r-- | t/bop.t | 10 | ||||
-rw-r--r-- | t/capture.t | 71 | ||||
-rw-r--r-- | t/check.t | 33 | ||||
-rw-r--r-- | t/credit_card.t | 31 | ||||
-rw-r--r-- | t/lib/test_account.pl | 28 | ||||
-rw-r--r-- | t/load.t | 10 | ||||
-rw-r--r-- | t/test_account | 2 |
7 files changed, 105 insertions, 80 deletions
@@ -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; @@ -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) = <TEST_ACCOUNT>; + 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; @@ -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 |