From a740e773c6bfeb2b42945f16047b1f5dfba67af4 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 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. Signed-off-by: Marc Véron Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- C4/Letters.pm | 4 +++- t/db_dependent/Letters/TemplateToolkit.t | 30 +++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index cd7b785c96..1d87a46771 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -782,6 +782,7 @@ sub GetPreparedLetter { content => $letter->{content}, tables => $tables, loops => $loops, + substitute => $substitute, } ); @@ -1455,6 +1456,7 @@ sub _process_tt { my $content = $params->{content}; my $tables = $params->{tables}; my $loops = $params->{loops}; + my $substitute = $params->{substitute} || {}; my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE}; my $template = Template->new( @@ -1469,7 +1471,7 @@ sub _process_tt { } ) or die Template->error(); - my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) } }; + my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute }; $content = qq|[% USE KohaDates %]$content|; diff --git a/t/db_dependent/Letters/TemplateToolkit.t b/t/db_dependent/Letters/TemplateToolkit.t index b83c2b6274..4fd000a85b 100644 --- a/t/db_dependent/Letters/TemplateToolkit.t +++ b/t/db_dependent/Letters/TemplateToolkit.t @@ -286,7 +286,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' } ); @@ -472,6 +472,34 @@ Thank you for visiting [% branch.branchname %]. is( $second_checkin_tt_letter->content, $second_checkin_letter->content, 'Verify second checkin letter' ); }; + + 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}, ); + }; }; subtest 'loops' => sub { -- 2.39.5