From ebdfb0725ab755eac7f0b504ec9072ba1c219a28 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 28 Jan 2026 21:08:54 +0000 Subject: [PATCH] Bug 41730: Unit tests --- t/db_dependent/Circulation.t | 83 +++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 540108a3c1d..58d698b9f22 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -19,7 +19,7 @@ use Modern::Perl; use utf8; use Test::NoWarnings; -use Test::More tests => 84; +use Test::More tests => 85; use Test::Exception; use Test::MockModule; use Test::Deep qw( cmp_deeply ); @@ -6185,7 +6185,8 @@ subtest 'Lost status does not change when preferences are set to 0' => sub { )->store(); # Test for UpdateItemLostStatusWhenPaid - t::lib::Mocks::mock_preference( 'UpdateItemLostStatusWhenPaid', 0 ); + t::lib::Mocks::mock_preference( 'UpdateItemLostStatusWhenPaid', 0 ); + t::lib::Mocks::mock_preference( 'UpdateItemWithdrawnStatusWhenPaid', 0 ); my $paymentLine = Koha::Account::Line->new( { @@ -6313,6 +6314,84 @@ subtest 'Update lost item to authorized value on payment of balance' => sub { } }; +# Test for UpdateItemWithdrawnStatusWhenPaid +subtest 'Update lost item to authorized value on payment of balance' => sub { + plan tests => 8; + + my $library = $builder->build_object( { class => "Koha::Libraries" } ); + my $manager = $builder->build_object( { class => "Koha::Patrons" } ); + t::lib::Mocks::mock_userenv( { patron => $manager, branchcode => $manager->branchcode } ); + + my $biblio = $builder->build_sample_biblio; + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + + my @prefs = ( + { withdrawn => 0, paid => 0, writeoff => 0 }, + { withdrawn => 0, paid => 1, writeoff => 0 }, + { withdrawn => 0, paid => 1, writeoff => 1 }, + { withdrawn => 0, paid => 0, writeoff => 1 }, + { withdrawn => 1, paid => 0, writeoff => 0 }, + { withdrawn => 1, paid => 1, writeoff => 0 }, + { withdrawn => 1, paid => 1, writeoff => 1 }, + { withdrawn => 1, paid => 0, writeoff => 1 } + ); + foreach my $pref (@prefs) { + t::lib::Mocks::mock_preference( 'UpdateItemWithdrawnStatusWhenPaid', $pref->{withdrawn} ); + t::lib::Mocks::mock_preference( 'UpdateItemLostStatusWhenPaid', $pref->{paid} ); + t::lib::Mocks::mock_preference( 'UpdateItemLostStatusWhenWriteoff', $pref->{writeoff} ); + + my $item = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + library => $library->branchcode, + replacementprice => 99, + itype => $itemtype, + itemlost => 1, + } + ); + + my $debitCharge = Koha::Account::Line->new( + { + borrowernumber => $patron->borrowernumber, + debit_type_code => 'LOST', + status => undef, + itemnumber => $item->itemnumber, + amount => 12, + amountoutstanding => 12, + interface => 'something', + } + )->store(); + + my $paymentLine = Koha::Account::Line->new( + { + borrowernumber => $patron->borrowernumber, + credit_type_code => 'CREDIT', + status => undef, + itemnumber => $item->itemnumber, + amountoutstanding => 0 - 12, + amount => 0 - 12, + interface => 'something', + } + )->store(); + + my $offset = Koha::Account::Offset->new( + { + credit_id => $paymentLine->id, + debit_id => $debitCharge->id, + type => 'APPLY', + amount => 0 + } + )->store(); + + $paymentLine->apply( { debits => [$debitCharge] } ); + + is( + Koha::Items->find( $item->itemnumber )->withdrawn, $pref->{withdrawn}, + "Payment should set withdrawn to status $pref->{withdrawn}" + ); + } +}; + # Test for UpdateItemLostStatusWhenWriteOff subtest 'Update lost item to authorized value on write-off of balance' => sub { plan tests => 5; -- 2.39.5