From f40f74568d8fbce6d94ba5196a8f962e2cc473ed Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 5 Feb 2026 08:16:22 +0000 Subject: [PATCH] Bug 35612: (QA follow-up) Add test for undefined LostChargesControl preference Adds test coverage for the case where LostChargesControl system preference is not set (returns undef). This ensures the code handles this gracefully and defaults to ItemHomeLibrary behavior. The test verifies that: - No warnings are generated when the preference is undefined - The default behavior (ItemHomeLibrary) is applied correctly - The correct branch (item homebranch) is recorded in accountlines This improves test coverage and prevents regression of the fix for uninitialized value warnings. --- t/db_dependent/Accounts.t | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t index 1f98dfafcff..d81191ac6f8 100755 --- a/t/db_dependent/Accounts.t +++ b/t/db_dependent/Accounts.t @@ -679,7 +679,7 @@ subtest "C4::Accounts::chargelostitem tests" => sub { my $procfee; subtest "Bug 35612: chargelostitem records branch context in accountlines.branchcode" => sub { - plan tests => 7; + plan tests => 8; t::lib::Mocks::mock_preference( 'LostChargesControl', 'ItemHomeLibrary' ); t::lib::Mocks::mock_preference( 'HomeOrHoldingBranch', 'homebranch' ); @@ -809,6 +809,30 @@ subtest "C4::Accounts::chargelostitem tests" => sub { 1, "Dedupes LOST charges for same itemnumber + issue_id (no item_id regression)" ); + + # Test undefined LostChargesControl (should default to ItemHomeLibrary behavior) + Koha::Account::Lines->search( + { borrowernumber => $patron->borrowernumber, itemnumber => $item->itemnumber, debit_type_code => 'LOST' } ) + ->delete; + + t::lib::Mocks::mock_preference( 'LostChargesControl', undef ); + t::lib::Mocks::mock_preference( 'HomeOrHoldingBranch', 'homebranch' ); + + C4::Accounts::chargelostitem( + $patron->borrowernumber, $item->itemnumber, 6.12, "Lost test undefined pref", + { issue_id => $issue_id } + ); + + $lost = Koha::Account::Lines->find( + { + borrowernumber => $patron->borrowernumber, itemnumber => $item->itemnumber, debit_type_code => 'LOST', + issue_id => $issue_id + } + ); + is( + $lost->branchcode, $lib_home, + "LOST uses item homebranch when LostChargesControl is undefined (defaults to ItemHomeLibrary)" + ); }; subtest "fee application tests" => sub { -- 2.52.0