diff --git a/Supporters/Makefile.PL b/Supporters/Makefile.PL index ed14fd7..9ec2ecd 100644 --- a/Supporters/Makefile.PL +++ b/Supporters/Makefile.PL @@ -5,7 +5,7 @@ use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Supporters', VERSION_FROM => 'lib/Supporters.pm', # finds $VERSION, requires EU::MM from perl >= 5.5 - PREREQ_PM => { DBI => 1.6, 'Test::Exception' => 0.35, 'Mail::RFC822::Address' => 0.3 }, + PREREQ_PM => { DBI => 1.6, 'Sub::Override' => 0.09, 'Test::Exception' => 0.35, 'Mail::RFC822::Address' => 0.3 }, ABSTRACT_FROM => 'lib/Supporters.pm', # retrieve abstract from module AUTHOR => 'Bradley M. Kuhn ', LICENSE => 'agpl_3', diff --git a/Supporters/lib/Supporters.pm b/Supporters/lib/Supporters.pm index 87a4783..47fc9ea 100644 --- a/Supporters/lib/Supporters.pm +++ b/Supporters/lib/Supporters.pm @@ -359,6 +359,28 @@ sub getPreferredEmailAddress($$) { return $emailAddress; } } + +###################################################################### + +=begin getLedgerEntityId + +Arguments: + +=over + +=item $donorId + + Valid donor id number currently in the database. die() will occur if + the id number is not in the database already as a donor id. + +=back + +Returns the ledger_entity_id of the donor. Since the method die()s for an +invalid donor id, undef should never be returned and callers need not test +for it. + +=cut + ###################################################################### =begin addPostalAddress diff --git a/Supporters/t/Supporters.t b/Supporters/t/Supporters.t index fa8dd5c..dc2b4d4 100644 --- a/Supporters/t/Supporters.t +++ b/Supporters/t/Supporters.t @@ -8,8 +8,9 @@ use strict; use warnings; -use Test::More tests => 189; +use Test::More tests => 193; use Test::Exception; +use Sub::Override; use Scalar::Util qw(looks_like_number reftype); use POSIX qw(strftime); @@ -105,6 +106,26 @@ ok((defined $val and defined $val->{$olsonId}{email_address_id} and $val->{$olso my $olsonFirstEmailId = $val->{$olsonId}{email_address_id}; +=item getLedgerEntityId + +=cut + +dies_ok { my $ledgerId = $sp->getLedgerEntityId(0); } + "getLedgerEntityId: fails when rows are not returned but _verifyId() somehow passed"; + +# Replace _verifyId() to always return true + +my $overrideSub = Sub::Override->new( 'Supporters::_verifyId' => sub ($$) { return 1;} ); +dies_ok { my $ledgerId = $sp->getLedgerEntityId(0); } + "getLedgerEntityId: fails when rows are not returned but _verifyId() somehow passed"; +$overrideSub->restore; + +my $olsonLedgerEntity; +lives_ok { $olsonLedgerEntity = $sp->getLedgerEntityId($olsonId); } + "getLedgerEntityId: lives when valid id is given..."; + +is($olsonLedgerEntity, "Olson-Margaret", "getLedgerEntityId: ...and return value is correct."); + =item addEmailAddress =cut @@ -736,6 +757,7 @@ dies_ok { $tempSP->addSupporter({ display_name => "Roger Sterling", email_address_type => 'home' }) } "addSupporter: dies when email_address table does not exist & email adress given"; + $tempDBH->disconnect; $tempDBH = reopen_test_dbh(); $val = $tempDBH->selectall_hashref("SELECT id FROM donor;", 'id'); @@ -743,6 +765,9 @@ $val = $tempDBH->selectall_hashref("SELECT id FROM donor;", 'id'); ok( (defined $val and reftype $val eq "HASH" and keys(%{$val}) == 0), "addSupporter: fails if email_address given but email cannot be inserted"); +$tempDBH->disconnect; $tempDBH = reopen_test_dbh(); + + =back