From 7451f12f7e9da73406ebbc0a2d65ac0b8f823b49 Mon Sep 17 00:00:00 2001 From: Hammat Wele Date: Mon, 8 Apr 2024 16:43:06 +0000 Subject: [PATCH] Bug 33237: (follow-up) Unit tests Signed-off-by: Martin Renvoize --- t/db_dependent/Letters.t | 66 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index 18c39a24d14..1efa4903bdb 100755 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -882,7 +882,7 @@ subtest 'GetPreparedLetter' => sub { subtest 'TranslateNotices' => sub { - plan tests => 4; + plan tests => 7; t::lib::Mocks::mock_preference( 'TranslateNotices', '1' ); @@ -944,6 +944,70 @@ subtest 'TranslateNotices' => sub { is( $letter->{title}, 'a test', 'GetPreparedLetter should return the default notice if pref disabled but additional language exists' ); + my $amount = -20; + my $accountline = $builder->build( + { + source => 'Accountline', + value => { + borrowernumber => $borrowernumber, + amount => $amount, + amountoutstanding => $amount, + credit_type_code => 'PAYMENT', + } + } + ); + $dbh->do( + q| + INSERT INTO letter (module, code, branchcode, name, title, content, message_transport_type, lang) VALUES + ('test_payment', 'code', '', 'Account payment', 'Account payment', "[% PROCESS 'accounts.inc' %][% PROCESS account_type_description account=credit %][% credit.description %]", 'print', 'default'); + | + ); + + $tables = { + borrowers => $borrowernumber, + credits => $accountline->{accountlines_id}, + }; + + $letter = C4::Letters::GetPreparedLetter( + module => 'test_payment', + letter_code => 'code', + message_transport_type => 'print', + tables => $tables, + lang => 'fr-CA', + ); + like( + $letter->{content}, qr/Paiement/, + 'GetPreparedLetter should return the notice in patron\'s preferred language' + ); + + my $context = Test::MockModule->new('C4::Context'); + $context->mock( 'interface', 'intranet' ); + + Koha::Cache::Memory::Lite->get_instance()->clear_from_cache('getlanguage'); + t::lib::Mocks::mock_preference( 'language', 'fr-CA,en' ); + + $letter = C4::Letters::GetPreparedLetter( + module => 'test_payment', + letter_code => 'code', + message_transport_type => 'print', + tables => $tables, + lang => 'default', + ); + like( $letter->{content}, qr/Paiement/, 'GetPreparedLetter should return the notice in the interface language' ); + + $context->mock( 'interface', 'cron' ); + + $letter = C4::Letters::GetPreparedLetter( + module => 'test_payment', + letter_code => 'code', + message_transport_type => 'print', + tables => $tables, + lang => 'default' + ); + like( + $letter->{content}, qr/Paiement/, + 'GetPreparedLetter should return the notice in the first language in language system preference' + ); }; subtest 'Test SMS handling in SendQueuedMessages' => sub { -- 2.44.0