Bug 17965: TT syntax for notices - Prove that DUEDGST is compatible

This notice template have the particular feature of using <<count>>.
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 <veron@veron.ch>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2017-01-16 16:58:23 +01:00
parent 48f847025d
commit a740e773c6
2 changed files with 32 additions and 2 deletions

View File

@ -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|;

View File

@ -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 <<count>> 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 {