From c832ac3cae416c7bb6fdd19b18735e06d13afb19 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 28 May 2021 12:02:09 +0000 Subject: [PATCH] Bug 28482: Unit test Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer Signed-off-by: Kyle M Hall (cherry picked from commit 1df303de77bbaa555b9dc8c0349fae8fb2990c4f) Signed-off-by: Fridolin Somers --- t/db_dependent/Koha/Account/Line.t | 52 +++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Account/Line.t b/t/db_dependent/Koha/Account/Line.t index dcc08aaae0..504436abec 100755 --- a/t/db_dependent/Koha/Account/Line.t +++ b/t/db_dependent/Koha/Account/Line.t @@ -175,7 +175,7 @@ subtest 'is_credit() and is_debit() tests' => sub { subtest 'apply() tests' => sub { - plan tests => 26; + plan tests => 27; $schema->storage->txn_begin; @@ -358,6 +358,56 @@ subtest 'apply() tests' => sub { $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } ); is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' ); + t::lib::Mocks::mock_preference( 'MarkLostItemsAsReturned', 'onpayment'); + my $loser = $builder->build_object( { class => 'Koha::Patrons' } ); + my $loser_account = $loser->account; + + my $lost_item = $builder->build_sample_item(); + my $lost_checkout = Koha::Checkout->new( + { + borrowernumber => $loser->id, + itemnumber => $lost_item->id, + date_due => $five_weeks_ago, + branchcode => $library->id, + issuedate => $seven_weeks_ago + } + )->store(); + + $lost_item->itemlost(1)->store; + my $processing_fee = Koha::Account::Line->new( + { + issue_id => $lost_checkout->id, + borrowernumber => $loser->id, + itemnumber => $lost_item->id, + branchcode => $library->id, + date => \'NOW()', + debit_type_code => 'PROCESSING', + status => undef, + interface => 'intranet', + amount => '15', + amountoutstanding => '15', + } + )->store(); + my $lost_fee = Koha::Account::Line->new( + { + issue_id => $lost_checkout->id, + borrowernumber => $loser->id, + itemnumber => $lost_item->id, + branchcode => $library->id, + date => \'NOW()', + debit_type_code => 'LOST', + status => undef, + interface => 'intranet', + amount => '12.63', + amountoutstanding => '12.63', + } + )->store(); + my $pay_lost = $loser_account->add_credit({ amount => 27.630000, user_id => $loser->id, interface => 'intranet' }); + my $pay_lines = [ $processing_fee, $lost_fee ]; + $pay_lost->apply( { debits => $pay_lines, offset_type => 'Credit applied' } ); + + is( $loser->checkouts->next, undef, "Item has been returned"); + $schema->storage->txn_rollback; }; -- 2.39.5