From 666c9a1d5ca39322fa977cbc1d7fe836a0ad6f2f Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Mon, 20 Oct 2025 20:31:37 +0000 Subject: [PATCH] Bug 40255: Unit test --- t/db_dependent/Koha/Account/Line.t | 96 +++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Account/Line.t b/t/db_dependent/Koha/Account/Line.t index 30b623d0901..5e6da391fd1 100755 --- a/t/db_dependent/Koha/Account/Line.t +++ b/t/db_dependent/Koha/Account/Line.t @@ -20,7 +20,7 @@ use Modern::Perl; use Test::NoWarnings; -use Test::More tests => 16; +use Test::More tests => 17; use Test::Exception; use Test::MockModule; @@ -1470,4 +1470,98 @@ subtest "cancel() tests" => sub { $schema->storage->txn_rollback; }; +subtest 'debit description from notice' => sub { + plan tests => 3; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + + # Create a debit type + my $debit_type = $builder->build_object( + { + class => 'Koha::Account::DebitTypes', + value => { + code => 'LUKEG_WAS_HERE', + description => 'Default description', + is_system => 0, + } + } + ); + + # Create a notice for this debit type + my $notice = $builder->build_object( + { + class => 'Koha::Notice::Templates', + value => { + module => 'debit_description', + code => 'LUKEG_WAS_HERE', + name => 'Test fee', + content => 'You owe big time buddy, pay up: $[% accountline.amount | format("%.2f") %]', + branchcode => '', + message_transport_type => 'email', + lang => 'default', + } + } + ); + + # Create an account line - description should be set from notice + my $account_line = Koha::Account::Line->new( + { + borrowernumber => $patron->borrowernumber, + debit_type_code => 'LUKEG_WAS_HERE', + amount => 10.50, + amountoutstanding => 10.50, + interface => 'commandline', + } + )->store; + + is( $account_line->description, 'You owe big time buddy, pay up: $10.50', 'Description set from notice template' ); + + # Create another line without a notice + $notice->delete; + + my $account_line2 = Koha::Account::Line->new( + { + borrowernumber => $patron->borrowernumber, + debit_type_code => 'LUKEG_WAS_HERE', + amount => 5.00, + amountoutstanding => 5.00, + interface => 'commandline', + } + )->store; + + is( $account_line2->description, undef, 'No notice, no description' ); + + # Create a line with explicit description - should not be overridden + my $notice2 = $builder->build_object( + { + class => 'Koha::Notice::Templates', + value => { + module => 'debit_description', + code => 'LUKEG_WAS_HERE', + content => 'From notice', + branchcode => '', + message_transport_type => 'email', + lang => 'default', + } + } + ); + + my $account_line3 = Koha::Account::Line->new( + { + borrowernumber => $patron->borrowernumber, + debit_type_code => 'LUKEG_WAS_HERE', + description => 'Manual description', + amount => 3.00, + amountoutstanding => 3.00, + interface => 'commandline', + } + )->store; + + is( $account_line3->description, 'Manual description', 'System defined description is used' ); + + $schema->storage->txn_rollback; +}; + 1; -- 2.39.5