From 6a5131483e49745346d685a3f7da3ddc2a3bd2c5 Mon Sep 17 00:00:00 2001 From: Laura_Escamilla Date: Wed, 15 Oct 2025 15:17:58 +0000 Subject: [PATCH] Bug 35612: Unit tests for Overdues.t --- t/db_dependent/Overdues.t | 101 +++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Overdues.t b/t/db_dependent/Overdues.t index f17ee28d18..1ef4b30969 100755 --- a/t/db_dependent/Overdues.t +++ b/t/db_dependent/Overdues.t @@ -1,7 +1,7 @@ #!/usr/bin/perl; use Modern::Perl; -use Test::More tests => 19; +use Test::More tests => 20; use Test::NoWarnings; use Test::Warn; @@ -163,6 +163,105 @@ is_deeply( \@overdue_branches, [ 'CPL', 'MPL' ], 'If only 2 specific rules exist $schema->storage->txn_rollback; +subtest 'branch_for_fee_context' => sub { + plan tests => 8; + $schema->storage->txn_begin; + + my $br_home = $builder->build( { source => 'Branch' } )->{branchcode}; + my $br_hold = $builder->build( { source => 'Branch' } )->{branchcode}; + my $br_pat = $builder->build( { source => 'Branch' } )->{branchcode}; + + my $pat1 = $builder->build_object( + { + class => 'Koha::Patrons', + value => { branchcode => $br_pat } + } + ); + + my $item1 = $builder->build_object( + { + class => 'Koha::Items', + value => { homebranch => $br_home, holdingbranch => $br_hold } + } + ); + + my $issue1 = $builder->build_object( + { + class => 'Koha::Checkouts', + value => { + itemnumber => $item1->itemnumber, + borrowernumber => $pat1->borrowernumber, + branchcode => $br_hold, + } + } + ); + + t::lib::Mocks::mock_preference( 'HomeOrHoldingBranch', 'homebranch' ); + t::lib::Mocks::mock_preference( 'CircControl', 'PatronLibrary' ); + is( + C4::Overdues::branch_for_fee_context( + fee_type => 'OVERDUE', patron => $pat1, item => $item1, issue => $issue1 + ), + $br_pat, + 'OVERDUE: PatronLibrary => patron home' + ); + + t::lib::Mocks::mock_preference( 'CircControl', 'PickupLibrary' ); + is( + C4::Overdues::branch_for_fee_context( + fee_type => 'OVERDUE', patron => $pat1, item => $item1, issue => $issue1 + ), + $br_hold, + 'OVERDUE: PickupLibrary => issuing branch' + ); + + t::lib::Mocks::mock_preference( 'CircControl', 'ItemHomeLibrary' ); + t::lib::Mocks::mock_preference( 'HomeOrHoldingBranch', 'homebranch' ); + is( + C4::Overdues::branch_for_fee_context( + fee_type => 'OVERDUE', patron => $pat1, item => $item1, issue => $issue1 + ), + $br_home, + 'OVERDUE: ItemHomeLibrary/homebranch => item home' + ); + + t::lib::Mocks::mock_preference( 'HomeOrHoldingBranch', 'holdingbranch' ); + is( + C4::Overdues::branch_for_fee_context( + fee_type => 'OVERDUE', patron => $pat1, item => $item1, issue => $issue1 + ), + $br_hold, + 'OVERDUE: ItemHomeLibrary/holdingbranch => item holding' + ); + + t::lib::Mocks::mock_preference( 'LostChargesControl', 'PatronLibrary' ); + t::lib::Mocks::mock_preference( 'HomeOrHoldingBranch', 'homebranch' ); + is( + C4::Overdues::branch_for_fee_context( fee_type => 'LOST', patron => $pat1, item => $item1, issue => $issue1 ), + $br_pat, 'LOST: PatronLibrary => patron home' + ); + + t::lib::Mocks::mock_preference( 'LostChargesControl', 'PickupLibrary' ); + is( + C4::Overdues::branch_for_fee_context( fee_type => 'LOST', patron => $pat1, item => $item1, issue => $issue1 ), + $br_hold, 'LOST: PickupLibrary => issuing branch' + ); + + t::lib::Mocks::mock_preference( 'LostChargesControl', 'ItemHomeLibrary' ); + t::lib::Mocks::mock_preference( 'HomeOrHoldingBranch', 'homebranch' ); + is( + C4::Overdues::branch_for_fee_context( fee_type => 'LOST', patron => $pat1, item => $item1, issue => $issue1 ), + $br_home, 'LOST: ItemHomeLibrary/homebranch => item home' + ); + + t::lib::Mocks::mock_preference( 'HomeOrHoldingBranch', 'holdingbranch' ); + is( + C4::Overdues::branch_for_fee_context( fee_type => 'LOST', patron => $pat1, item => $item1, issue => $issue1 ), + $br_hold, 'LOST: ItemHomeLibrary/holdingbranch => item holding' + ); + $schema->storage->txn_rollback; +}; + subtest 'UpdateFine tests' => sub { plan tests => 75; -- 2.39.5