From 007f00ca85a15f38451a4994c7a0bfab55ac8225 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 23 Apr 2024 13:42:46 +0100 Subject: [PATCH] Bug 33237: (QA follow-up) Clarify tests This patch tries to clarify the tests a little and expand their coverage. I've added notes where I think we still need a little work, especially in regards to having them pass in the jenkins runs as we don't have translations installed there and thus at the moment the tests will fail without manual intervention to install the translated includes. --- t/db_dependent/Letters.t | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index b40b38cec46..4b25205c14c 100755 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -876,7 +876,7 @@ subtest 'GetPreparedLetter' => sub { subtest 'TranslateNotices' => sub { - plan tests => 7; + plan tests => 10; t::lib::Mocks::mock_preference( 'TranslateNotices', '1' ); @@ -938,6 +938,8 @@ subtest 'TranslateNotices' => sub { is( $letter->{title}, 'a test', 'GetPreparedLetter should return the default notice if pref disabled but additional language exists' ); + t::lib::Mocks::mock_preference( 'TranslateNotices', '1' ); + my $amount = -20; my $accountline = $builder->build( { @@ -953,25 +955,31 @@ subtest 'TranslateNotices' => sub { $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'); + ('test', 'payment', '', 'Paiement du compte', 'Paiement du compte', "[% PROCESS 'accounts.inc' %][% PROCESS account_type_description account=credit %][% credit.description %]", 'print', 'fr-CA'), + ('test', 'payment', '', 'Default payment notice', 'Default payment notice', "[% PROCESS 'accounts.inc' %][% PROCESS account_type_description account=credit %][% credit.description %]", 'print', 'default'); | ); + # Note: How can we mock the above used includes being installed in fr-CA language so we don't have to actually install + # them for the tests to run :S + $tables = { borrowers => $borrowernumber, credits => $accountline->{accountlines_id}, }; $letter = C4::Letters::GetPreparedLetter( - module => 'test_payment', - letter_code => 'code', + module => 'test', + letter_code => 'payment', message_transport_type => 'print', tables => $tables, lang => 'fr-CA', ); + is( $letter->{title}, 'Paiement du compte', + 'GetPreparedLetter should return the notice in patron\'s preferred language' ); like( $letter->{content}, qr/Paiement/, - 'GetPreparedLetter should return the notice in patron\'s preferred language' + 'Template includes should use the patron\'s preferred language too' ); my $context = Test::MockModule->new('C4::Context'); @@ -981,27 +989,36 @@ subtest 'TranslateNotices' => sub { t::lib::Mocks::mock_preference( 'language', 'fr-CA,en' ); $letter = C4::Letters::GetPreparedLetter( - module => 'test_payment', - letter_code => 'code', + module => 'test', + letter_code => 'payment', message_transport_type => 'print', tables => $tables, lang => 'default', ); + is( $letter->{title}, 'Default payment notice', + 'GetPreparedLetter should return the notice in default language' ); 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', + module => 'test', + letter_code => 'payment', message_transport_type => 'print', tables => $tables, lang => 'default' ); + is( $letter->{title}, 'Default payment notice', + 'GetPreparedLetter should return the notice in default language' ); like( $letter->{content}, qr/Paiement/, 'GetPreparedLetter should return the notice in the first language in language system preference' ); + + t::lib::Mocks::mock_preference( 'TranslateNotices', '0' ); + + # Note: What should happen when TranslateNotices is disabled? The default might be translated and thus we need to ensure we're + # using the right template + includes consistently again }; subtest 'Test SMS handling in SendQueuedMessages' => sub { -- 2.44.0