From 39b5b4cdc89b7af53b578f9263b243a30983fb4f Mon Sep 17 00:00:00 2001 From: Laura_Escamilla Date: Thu, 18 Sep 2025 17:17:24 +0000 Subject: [PATCH] Bug 35612: Tests run perl t/db_dependent/Koha/Account.t --- t/db_dependent/Koha/Account.t | 53 ++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t index 057c3e9eda..c40cd9ed49 100755 --- a/t/db_dependent/Koha/Account.t +++ b/t/db_dependent/Koha/Account.t @@ -20,7 +20,7 @@ use Modern::Perl; use Test::NoWarnings; -use Test::More tests => 16; +use Test::More tests => 17; use Test::MockModule; use Test::Exception; use Test::Warn; @@ -466,6 +466,57 @@ subtest 'add_debit() tests' => sub { $schema->storage->txn_rollback; }; +subtest 'add_debit() populates branchcode according to AccountLinesBranchSource' => sub { + plan tests => 4; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $item_homebranch = $builder->build_object( { class => 'Koha::Libraries' } )->branchcode; + my $checkout_branch = $builder->build_object( { class => 'Koha::Libraries' } )->branchcode; + + my $item = $builder->build_sample_item( { homebranch => $item_homebranch } ); + + my $checkout = Koha::Checkout->new( + { + borrowernumber => $patron->id, + itemnumber => $item->itemnumber, + branchcode => $checkout_branch, + date_due => \'NOW()', + issuedate => \'NOW()', + } + )->store(); + my %branch_tests = ( + 'checkoutbranch' => $checkout_branch, + 'itemhomebranch' => $item_homebranch, + 'patronhomebranch' => $patron->branchcode, + 'none' => undef, + ); + for my $pref ( keys %branch_tests ) { + t::lib::Mocks::mock_preference( 'AccountLinesBranchSource', $pref ); + + my $account = $patron->account; + + my $line = $account->add_debit( + { + amount => 5, + description => "Test $pref", + type => 'OVERDUE', + interface => 'commandline', + item_id => $item->itemnumber, + issue_id => $checkout->id, + } + ); + + is( + $line->branchcode, + $branch_tests{$pref}, + "branchcode is set correctly for AccountLinesBranchSource = $pref" + ); + } + $schema->storage->txn_rollback; +}; + subtest 'lines() tests' => sub { plan tests => 1; -- 2.39.5