From 03e644cdea2baf564e3b09a934f301093150d6ff 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 Signed-off-by: Jonathan Druart Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer (cherry picked from commit 3f8b7785cd703f89de140108eb9347bf33a0c764) Signed-off-by: Fridolin Somers --- 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.' + ); +};