From 44f19b9d67b1d2365fd7089c1095edbbc8237fc0 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 9 Mar 2018 09:51:52 -0500 Subject: [PATCH] Bug 18626: Add unit tests --- t/db_dependent/Koha/Patrons.t | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 2323d21..c494241 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -19,10 +19,11 @@ use Modern::Perl; -use Test::More tests => 25; +use Test::More tests => 26; use Test::Warn; use Time::Fake; use DateTime; +use JSON; use C4::Biblio; use C4::Circulation; @@ -1121,6 +1122,24 @@ subtest 'is_child | is_adult' => sub { $retrieved_patron_1->delete; is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); +subtest 'Log cardnumber change' => sub { + plan tests => 3; + + t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); + my $patron = $builder->build( { source => 'Borrower' } ); + + my $cardnumber = $patron->{cardnumber}; + $patron->{cardnumber} = 'TESTCARDNUMBER'; + ModMember(%$patron); + + my @logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'MODIFY', object => $patron->{borrowernumber} } ); + my $log_info = from_json( $logs[0]->info ); + is( $log_info->{cardnumber_replaced}->{new_cardnumber}, 'TESTCARDNUMBER', 'Got correct new cardnumber' ); + is( $log_info->{cardnumber_replaced}->{previous_cardnumber}, $cardnumber, 'Got correct old cardnumber' ); + is( scalar @logs, 2, 'With BorrowerLogs, Change in cardnumber should be logged, as well as general alert of patron mod.' ); +}; + + $schema->storage->txn_rollback; # TODO Move to t::lib::Mocks and reuse it! -- 2.10.2