From d0792dd7387fd831adaecbbbea3009549d26168d Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 6 Apr 2021 08:48:38 +0100 Subject: [PATCH] Bug 25508: Add Unit Tests Enhance the unit tests to check for the return values of Koha::Account->pay. Test plan 1/ Apply just this patch 2/ Run t/db_dependent/Koha/Account.t and watch it fail 3/ Apply the rest of the patch series 4/ Run t/db_dependent/Koha/Account.t and watch it pass 5/ Signoff Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Nick Clemens --- t/db_dependent/Koha/Account.t | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t index 90ffc351cf..81869447ad 100755 --- a/t/db_dependent/Koha/Account.t +++ b/t/db_dependent/Koha/Account.t @@ -924,7 +924,7 @@ subtest 'pay() handles lost items when paying by amount ( not specifying the los subtest 'pay() renews items when appropriate' => sub { - plan tests => 1; + plan tests => 7; $schema->storage->txn_begin; @@ -975,7 +975,7 @@ subtest 'pay() renews items when appropriate' => sub { my $module = Test::MockModule->new('C4::Circulation'); $module->mock('AddRenewal', sub { $called = 1; }); $module->mock('CanBookBeRenewed', sub { return 1; }); - $account->pay( + my $result = $account->pay( { amount => '1', library_id => $library->id, @@ -983,6 +983,37 @@ subtest 'pay() renews items when appropriate' => sub { ); is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' ); + is(ref($result->{renew_result}), 'ARRAY', "Pay result contains 'renew_result' ARRAY" ); + is( scalar @{$result->{renew_result}}, 1, "renew_result contains one renewal result" ); + is( $result->{renew_result}->[0]->{itemnumber}, $item->id, "renew_result contains itemnumber of renewed item" ); + + # Reset test by adding a new overdue + Koha::Account::Line->new( + { + issue_id => $checkout->id, + borrowernumber => $patron->id, + itemnumber => $item->id, + date => \'NOW()', + debit_type_code => 'OVERDUE', + status => 'UNRETURNED', + interface => 'cli', + amount => '1', + amountoutstanding => '1', + } + )->store(); + $called = 0; + + t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 0 ); + $result = $account->pay( + { + amount => '1', + library_id => $library->id, + } + ); + + is( $called, 0, 'C4::Circulation::AddRenew NOT called when RenewAccruingItemWhenPaid disabled' ); + is(ref($result->{renew_result}), 'ARRAY', "Pay result contains 'renew_result' ARRAY" ); + is( scalar @{$result->{renew_result}}, 0, "renew_result contains no renewal results" ); $schema->storage->txn_rollback; }; -- 2.11.0