From a74cdce1b6cd3c390ac2fc5a26a6b0d12e6bd62f Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Sat, 13 Sep 2014 16:13:53 -0700 Subject: [PATCH] add tests for processing agreement / country functionality, 0.33 --- Changes | 3 +- CreditCard.pm | 4 +-- t/agreements.t | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 t/agreements.t diff --git a/Changes b/Changes index 9a90f30..14b9183 100644 --- a/Changes +++ b/Changes @@ -1,10 +1,11 @@ Revision history for Perl extension Business::CreditCard. -0.33 unreleased +0.33 Sat Sep 13 16:13:15 PDT 2014 - With $Country explicity to CA, fix identification of JCB 3529-3589 as Discover - Allow use of our subroutines as class methods, patch from Adam Kennedy, thanks! + - Add tests for processing agreement / country functionality 0.32 Thu Feb 21 16:02:42 PST 2013 - Add Israeli Isracard (no checksum yet) diff --git a/CreditCard.pm b/CreditCard.pm index 4fdcebd..cfc3be4 100644 --- a/CreditCard.pm +++ b/CreditCard.pm @@ -5,7 +5,7 @@ use vars qw( @ISA $VERSION $Country ); @ISA = qw( Exporter ); -$VERSION = "0.33_01"; +$VERSION = "0.33"; $Country = 'US'; @@ -267,7 +267,7 @@ sub generate_last_digit { ## this (GPLed) code from Business::CCCheck is apparantly 4x faster than ours ## ref http://neilb.org/reviews/luhn.html#Comparison -## maybe see if we can spped ours up a bit +## maybe see if we can speed ours up a bit # my @ccn = split('',$ccn); # my $even = 0; # $ccn = 0; diff --git a/t/agreements.t b/t/agreements.t new file mode 100644 index 0000000..ad146fb --- /dev/null +++ b/t/agreements.t @@ -0,0 +1,102 @@ +use Test::More tests => 5; +use Business::CreditCard; + +#w + +ok ( test_card_id_us() ); +ok ( test_card_id_ca() ); +ok ( test_card_id_mx() ); +ok ( test_card_id_cn() ); +ok ( test_card_id_base() ); + +sub test_card_id_us { + local($Business::CreditCard::Country) = 'US'; + + my %cards = ( + '3528000000000007' => 'Discover card', + '3589000000000003' => 'Discover card', + '30000000000004' => 'Discover card', + '30500000000003' => 'Discover card', + '30950000000000' => 'Discover card', + #'6200000000000005' => 'Discover card', #is 620 a valid CUP now? + '6220000000000008' => 'Discover card', + ); + + test_cards(\%cards); +} + +sub test_cards { + my $cards = shift; + while( my ($k, $v)=each(%$cards) ){ + if(cardtype($k) ne $v){ + warn "Card $k - should be $v for $Business::CreditCard::Country ". + " but cardtype returns ". cardtype($k). "\n"; + return; + } + } + return 1; +} + +sub test_card_id_ca { + local($Business::CreditCard::Country) = 'CA'; + + my %cards = ( + '3528000000000007' => 'Discover card', + '3589000000000003' => 'Discover card', + '30000000000004' => 'Discover card', + '30500000000003' => 'Discover card', + '30950000000000' => 'Discover card', + #'6200000000000005' => 'Discover card', #is 620 a valid CUP now? + '6220000000000008' => 'Discover card', + ); + test_cards(\%cards); +} + +#"all other countries" +sub test_card_id_mx { + local($Business::CreditCard::Country) = 'MX'; + + my %cards = ( + '3528000000000007' => 'JCB', + '3589000000000003' => 'JCB', + '30000000000004' => 'Discover card', + '30500000000003' => 'Discover card', + '30950000000000' => 'Discover card', + #'6200000000000005' => 'Discover card', #is 620 a valid CUP now? + '6220000000000008' => 'Discover card', + ); + test_cards(\%cards); +} + +sub test_card_id_cn { + local($Business::CreditCard::Country) = 'CN'; + + my %cards = ( + '3528000000000007' => 'JCB', + '3589000000000003' => 'JCB', + '30000000000004' => 'Discover card', + '30500000000003' => 'Discover card', + '30950000000000' => 'Discover card', + #'6200000000000005' => 'Discover card', #is 620 a valid CUP now? + '6220000000000008' => 'China Union Pay', + ); + test_cards(\%cards); +} + +sub test_card_id_base { + local($Business::CreditCard::Country) = ''; + + my %cards = ( + '3528000000000007' => 'JCB', + '3589000000000003' => 'JCB', + '30000000000004' => 'Discover card', + '30500000000003' => 'Discover card', + '30950000000000' => 'Discover card', + #'6200000000000005' => 'Discover card', #is 620 a valid CUP now? + + #XXX this is technically an issue ("base" for CUP is still CUP) + ##'6220000000000008' => 'China Union Pay', #but module will say "Discover card" + + ); + test_cards(\%cards); +} -- 2.11.0