From 9dc117ad2eae51a22e7c9e4e532de9dc8ada3b68 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Thu, 7 Mar 2024 09:07:49 +0000 Subject: [PATCH] Bug 36244: Unit test for tt syntax in parameters --- t/db_dependent/Letters.t | 47 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index ade28f89ad..8295c63baa 100755 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -18,7 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 99; +use Test::More tests => 100; use Test::MockModule; use Test::Warn; use Test::Exception; @@ -1410,3 +1410,48 @@ subtest 'Test message_id parameter for SendQueuedMessages' => sub { is( $message_1->{status}, 'failed', 'Message 1 status is unchanged' ); is( $message_2->{status}, 'sent', 'Valid from_address => status sent' ); }; + +subtest 'Template toolkit syntax in parameters' => sub { + + my $borrowernumber = Koha::Patron->new( + { + firstname => 'Robert', + surname => '[% USE Categories %][% Categories.all().search_related("borrowers").count() %]', + categorycode => $patron_category, + branchcode => $library->{branchcode}, + dateofbirth => $date, + smsalertnumber => undef, + } + )->store->borrowernumber; + + my $title = q|<> - <>|; + my $content = q{Dear <> <>}; + + $dbh->do( + q|INSERT INTO letter(branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES (?,'my module','tt test','my name',1,?,?,'email')|, + undef, $library->{branchcode}, $title, $content + ); + + my $tables = { + borrowers => $borrowernumber, + branches => $library->{branchcode}, + biblio => $biblionumber, + }; + my $substitute = { + status => 'overdue', + }; + my $prepared_letter = GetPreparedLetter( + module => 'my module', + branchcode => $library->{branchcode}, + letter_code => 'tt test', + tables => $tables, + substitute => $substitute, + repeat => [], + ); + + is( + $prepared_letter->{content}, + 'Dear Robert [% USE Categories %][% Categories.all().search_related("borrowers").count() %]', + 'Template toolkit syntax in parameter was not evaluated.' + ); +}; -- 2.39.2