Bug 33237: (QA follow-up) Clarify tests and Mock

This patch tries to clarify the tests a little and expand their
coverage whilst also adding some defualt translated includes to the test
area and mocking the config to allow the tests to run without installing
translations.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit a773770f73)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Martin Renvoize 2024-04-23 13:42:46 +01:00 committed by Fridolin Somers
parent a0e041be8f
commit 92a6638fa5
5 changed files with 2827 additions and 9 deletions

View File

@ -870,7 +870,7 @@ subtest 'GetPreparedLetter' => sub {
subtest 'TranslateNotices' => sub {
plan tests => 7;
plan tests => 10;
t::lib::Mocks::mock_preference( 'TranslateNotices', '1' );
@ -893,6 +893,7 @@ subtest 'TranslateNotices' => sub {
'a test',
'GetPreparedLetter should return the default one if the lang parameter is not provided'
);
# Note: What about includes, which language should be assumed 'default' here?
$letter = C4::Letters::GetPreparedLetter(
module => 'test',
@ -932,6 +933,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(
{
@ -947,25 +950,30 @@ 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');
|
);
t::lib::Mocks::mock_config( 'intrahtdocs', '/kohadevbox/koha/t/mock_templates/intranet-tmpl' );
$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');
@ -975,23 +983,27 @@ 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'

View File

@ -0,0 +1,61 @@
[%- BLOCK account_type_description -%]
[%- IF account.credit_type_code -%]
[%- PROCESS credit_type_description credit_type = account.credit_type -%]
[%- ELSIF account.debit_type_code -%]
[%- PROCESS debit_type_description debit_type = account.debit_type -%]
[%- END -%]
[%- PROCESS account_status_description account=account -%]
[%- END -%]
[%- BLOCK debit_type_description -%]
[%- SWITCH debit_type.code -%]
[%- CASE 'ACCOUNT' -%]<span>Account creation fee</span>
[%- CASE 'ACCOUNT_RENEW' -%]<span>Account renewal fee</span>
[%- CASE 'ARTICLE_REQUEST' -%]<span>Article request fee</span>
[%- CASE 'LOST' -%]<span>Lost item</span>
[%- CASE 'MANUAL' -%]<span>Manual fee</span>
[%- CASE 'NEW_CARD' -%]<span>New card</span>
[%- CASE 'OVERDUE' -%]<span>Fine</span>
[%- CASE 'PROCESSING' -%]<span>Lost item processing fee</span>
[%- CASE 'RENT' -%]<span>Rental fee</span>
[%- CASE 'RENT_DAILY' -%]<span>Daily rental fee</span>
[%- CASE 'RENT_RENEW' -%]<span>Renewal of rental item</span>
[%- CASE 'RENT_DAILY_RENEW' -%]<span>Renewal of daily rental item</span>
[%- CASE 'RESERVE' -%]<span>Hold fee</span>
[%- CASE 'RESERVE_EXPIRED' -%]<span>Hold waiting too long</span>
[%- CASE 'PAYOUT' -%]<span>Payment from library to patron</span>
[%- CASE 'VOID' -%]<span>Credit has been voided</span>
[%- CASE -%]<span>[% debit_type.description | html %]</span>
[%- END -%]
[%- END -%]
[%- BLOCK credit_type_description -%]
[%- SWITCH credit_type.code -%]
[%- CASE 'CANCELLATION' -%]<span>Cancelled charge</span>
[%- CASE 'CREDIT' -%]<span>Credit</span>
[%- CASE 'DISCOUNT' -%]<span>Discount</span>
[%- CASE 'FORGIVEN' -%]<span>Forgiven</span>
[%- CASE 'LOST_FOUND' -%]<span>Lost item fee refund</span>
[%- CASE 'OVERPAYMENT' -%]<span>Overpayment refund</span>
[%- CASE 'PAYMENT' -%]<span>Payment</span>
[%- CASE 'PROCESSING_FOUND' -%]<span>Lost item processing fee refund</span>
[%- CASE 'PURCHASE' -%]<span>Purchase</span>
[%- CASE 'REFUND' -%]<span>Refund</span>
[%- CASE 'WRITEOFF' -%]<span>Writeoff</span>
[%- CASE -%]<span>[% credit_type.description | html %]</span>
[%- END -%]
[%- END -%]
[%- BLOCK account_status_description -%]
[%- SWITCH account.status -%]
[%- CASE 'UNRETURNED' -%]<span> (Accruing)</span>
[%- CASE 'RETURNED' -%]<span> (Returned)</span>
[%- CASE 'REPLACED' -%]<span> (Replaced)</span>
[%- CASE 'REFUNDED' -%]<span> (Refunded)</span>
[%- CASE 'FORGIVEN' -%]<span> (Forgiven)</span>
[%- CASE 'VOID' -%]<span> (Voided)</span>
[%- CASE 'LOST' -%]<span> (Lost)</span>
[%- CASE 'CANCELLED' -%]<span> (Cancelled)</span>
[%- CASE -%]
[%- END -%]
[%- END -%]

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,61 @@
[%- BLOCK account_type_description -%]
[%- IF account.credit_type_code -%]
[%- PROCESS credit_type_description credit_type = account.credit_type -%]
[%- ELSIF account.debit_type_code -%]
[%- PROCESS debit_type_description debit_type = account.debit_type -%]
[%- END -%]
[%- PROCESS account_status_description account=account -%]
[%- END -%]
[%- BLOCK debit_type_description -%]
[%- SWITCH debit_type.code -%]
[%- CASE 'ACCOUNT' -%]<span>Frais d'abonnement</span>
[%- CASE 'ACCOUNT_RENEW' -%]<span>Frais de renouvellement d'abonnement</span>
[%- CASE 'ARTICLE_REQUEST' -%]<span>Frais de demande d'article</span>
[%- CASE 'LOST' -%]<span>Document perdu</span>
[%- CASE 'MANUAL' -%]<span>Frais manuel</span>
[%- CASE 'NEW_CARD' -%]<span>Nouvelle carte</span>
[%- CASE 'OVERDUE' -%]<span>Amende</span>
[%- CASE 'PROCESSING' -%]<span>Frais de traitement pour exemplaire perdu</span>
[%- CASE 'RENT' -%]<span>Frais de location</span>
[%- CASE 'RENT_DAILY' -%]<span>Frais quotidien de location</span>
[%- CASE 'RENT_RENEW' -%]<span>Renouvellement d'une location</span>
[%- CASE 'RENT_DAILY_RENEW' -%]<span>Renouvellement d'une location quotidienne</span>
[%- CASE 'RESERVE' -%]<span>Frais de réservation</span>
[%- CASE 'RESERVE_EXPIRED' -%]<span>Réservation en attente depuis trop longtemps</span>
[%- CASE 'PAYOUT' -%]<span>Paiement de la bibliothèque à l'utilisateur</span>
[%- CASE 'VOID' -%]<span>Le crédit a été annulé</span>
[%- CASE -%]<span>[% debit_type.description | html %]</span>
[%- END -%]
[%- END -%]
[%- BLOCK credit_type_description -%]
[%- SWITCH credit_type.code -%]
[%- CASE 'CANCELLATION' -%]<span>Frais annulé</span>
[%- CASE 'CREDIT' -%]<span>Crédit</span>
[%- CASE 'DISCOUNT' -%]<span>Rabais</span>
[%- CASE 'FORGIVEN' -%]<span>Amnistié</span>
[%- CASE 'LOST_FOUND' -%]<span>Remboursement de frais d'exemplaire perdu</span>
[%- CASE 'OVERPAYMENT' -%]<span>Remboursement pour paiement en trop</span>
[%- CASE 'PAYMENT' -%]<span>Paiement</span>
[%- CASE 'PROCESSING_FOUND' -%]<span>Remboursement de frais d'administration pour document perdu</span>
[%- CASE 'PURCHASE' -%]<span>Achat</span>
[%- CASE 'REFUND' -%]<span>Remboursement</span>
[%- CASE 'WRITEOFF' -%]<span>Amnistie</span>
[%- CASE -%]<span>[% credit_type.description | html %]</span>
[%- END -%]
[%- END -%]
[%- BLOCK account_status_description -%]
[%- SWITCH account.status -%]
[%- CASE 'UNRETURNED' -%]<span> (En accumulation)</span>
[%- CASE 'RETURNED' -%]<span> (Retourné)</span>
[%- CASE 'REPLACED' -%]<span> (Remplacé)</span>
[%- CASE 'REFUNDED' -%]<span> (Remboursé)</span>
[%- CASE 'FORGIVEN' -%]<span> (Amnistié)</span>
[%- CASE 'VOID' -%]<span> (Annulé)</span>
[%- CASE 'LOST' -%]<span> (Perdu)</span>
[%- CASE 'CANCELLED' -%]<span> (Annulé)</span>
[%- CASE -%]
[%- END -%]
[%- END -%]

File diff suppressed because it is too large Load Diff