From 6916f993b5c60d1dafb9eca5e95e4737e8e3b7fd Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 16 Jan 2017 16:58:23 +0100 Subject: [PATCH] Bug 17965: TT syntax for notices - Prove that DUEDGST is compatible This notice template have the particular feature of using <>. This value is substitued during the process of the notice template. For the TT syntax, all what we need is to send the values to substitute to the template. Note that items.content can also be used in these template, you can have a look at bug 17967 to see a better alternative to this marker. Test plan: Generate DUEDGST and DUE notice messages. You should be able to generate the same messages with the TT syntax. --- C4/Letters.pm | 3 +++ t/db_dependent/Letters/TemplateToolkit.t | 31 ++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index e2b6992..bbd1ade 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -770,6 +770,7 @@ sub GetPreparedLetter { { content => $letter->{content}, tables => $tables, + substitute => $substitute, } ); @@ -1440,6 +1441,7 @@ sub _process_tt { my $content = $params->{content}; my $tables = $params->{tables}; + my $substitute = $params->{substitute} || {}; my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE}; my $template = Template->new( @@ -1455,6 +1457,7 @@ sub _process_tt { ) or die Template->error(); my $tt_params = _get_tt_params( $tables ); + $tt_params = { %$tt_params, %$substitute }; $content = qq|[% USE KohaDates %]$content|; diff --git a/t/db_dependent/Letters/TemplateToolkit.t b/t/db_dependent/Letters/TemplateToolkit.t index c8f2e0d..32f0845 100644 --- a/t/db_dependent/Letters/TemplateToolkit.t +++ b/t/db_dependent/Letters/TemplateToolkit.t @@ -285,7 +285,7 @@ $prepared_letter = GetPreparedLetter( is( $prepared_letter->{content}, $modification->id(), 'Patron modification object used correctly' ); subtest 'regression tests' => sub { - plan tests => 3; + plan tests => 4; my $library = $builder->build( { source => 'Branch' } ); my $patron = $builder->build( { source => 'Borrower' } ); @@ -470,6 +470,35 @@ Thank you for visiting [% branch.branchname %]. is( $second_checkin_tt_letter->content, $second_checkin_letter->content, ); }; + + subtest 'DUEDGST|count' => sub { + plan tests => 1; + + my $code = 'DUEDGST'; + + my $dbh = C4::Context->dbh; + # Enable notification for DUEDGST - Things are hardcoded here but should work with default data + $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 1 ); + my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef); + $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' ); + + my $params = { + code => $code, + substitute => { count => 42 }, + }; + + my $template = q| +You have <> items due + |; + my $letter = process_letter( { template => $template, %$params }); + + my $tt_template = q| +You have [% count %] items due + |; + my $tt_letter = process_letter( { template => $tt_template, %$params }); + is( $tt_letter->{content}, $letter->{content}, ); + }; + }; sub reset_template { -- 2.1.4