From cd2e1583c9cc1f17d8620a0426864b351fc7c4cc Mon Sep 17 00:00:00 2001 From: Laura_Escamilla Date: Mon, 2 Feb 2026 21:17:33 +0000 Subject: [PATCH] Bug 35612: Unit test - Overdues.t Signed-off-by: Trevor Diamond --- t/db_dependent/Overdues.t | 75 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Overdues.t b/t/db_dependent/Overdues.t index f17ee28d18e..9084a1d04ed 100755 --- a/t/db_dependent/Overdues.t +++ b/t/db_dependent/Overdues.t @@ -165,12 +165,85 @@ $schema->storage->txn_rollback; subtest 'UpdateFine tests' => sub { - plan tests => 75; + plan tests => 83; $schema->storage->txn_begin; t::lib::Mocks::mock_preference( 'MaxFine', '100' ); + # Branch context tests for OVERDUE fines (Bug 35612) + my $lib_home = $builder->build_object( { class => 'Koha::Libraries' } ); + my $lib_hold = $builder->build_object( { class => 'Koha::Libraries' } ); + my $lib_issue = $builder->build_object( { class => 'Koha::Libraries' } ); + my $lib_patron = $builder->build_object( { class => 'Koha::Libraries' } ); + + my $context_patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { branchcode => $lib_patron->branchcode } + } + ); + + # Helper to create a scenario checkout/item and assert the resulting fine's branchcode + my $assert_overdue_branchcode = sub { + my ( $circ_control, $hoh, $expected_branchcode, $label ) = @_; + + t::lib::Mocks::mock_preference( 'CircControl', $circ_control ); + t::lib::Mocks::mock_preference( 'HomeOrHoldingBranch', $hoh ) if defined $hoh; + + my $item = $builder->build_sample_item(); + $item->homebranch( $lib_home->branchcode )->holdingbranch( $lib_hold->branchcode )->store; + + my $checkout = $builder->build_object( + { + class => 'Koha::Checkouts', + value => { + itemnumber => $item->itemnumber, + borrowernumber => $context_patron->borrowernumber, + branchcode => $lib_issue->branchcode, + } + } + ); + + UpdateFine( + { + issue_id => $checkout->issue_id, + itemnumber => $item->itemnumber, + borrowernumber => $context_patron->borrowernumber, + amount => '1', + due => $checkout->date_due, + } + ); + + my $fine = Koha::Account::Lines->search( + { issue_id => $checkout->issue_id, debit_type_code => 'OVERDUE' }, + { order_by => { -desc => 'accountlines_id' } } + )->next; + + ok( $fine, "$label: fine created" ); + is( $fine->branchcode, $expected_branchcode, "$label: branchcode recorded correctly" ); + }; + + $assert_overdue_branchcode->( + 'PatronLibrary', undef, $lib_patron->branchcode, + 'CircControl=PatronLibrary' + ); + + $assert_overdue_branchcode->( + 'PickupLibrary', undef, $lib_issue->branchcode, + 'CircControl=PickupLibrary' + ); + + $assert_overdue_branchcode->( + 'ItemHomeLibrary', 'homebranch', $lib_home->branchcode, + 'CircControl=ItemHomeLibrary + HomeOrHoldingBranch=homebranch' + ); + + $assert_overdue_branchcode->( + 'ItemHomeLibrary', 'holdingbranch', $lib_hold->branchcode, + 'CircControl=ItemHomeLibrary + HomeOrHoldingBranch=holdingbranch' + ); + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); my $item1 = $builder->build_sample_item(); my $item2 = $builder->build_sample_item(); -- 2.39.5