From 300f121b661f3e17f14e282282bdae8f20041694 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. Signed-off-by: Lucas Gass --- 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 1f98dfafcf..d81191ac6f 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 {