From 95e6f6a612013bedbb26054295b3336008466aed Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 16 Jan 2017 14:46:12 +0100 Subject: [PATCH] Bug 17963: TT syntax for notices - Prove that AR_* are compatible Nothing new here since bug 17962, the AR_* notice messages are quite simple. They send the article_request, patron, biblio, biblioitem, item and library linked to the article request. All the fields from these 6 tables should still be accessible using the TT syntax. Test plan: Define TT notice templates for AR_PENDING, AR_PROCESSING, AR_COMPLETED or AR_CANCELED. You should manage to create a template to generate the same result as the historical syntax. Signed-off-by: Kyle M Hall Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall --- C4/Letters.pm | 6 +++ Koha/ArticleRequest.pm | 2 +- t/db_dependent/Letters/TemplateToolkit.t | 55 +++++++++++++++++++++++- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index cf64147256..9308e4f41e 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1468,6 +1468,12 @@ sub _get_tt_params { my $params; my $config = { + article_requests => { + module => 'Koha::ArticleRequests', + singular => 'article_request', + plural => 'article_requests', + pk => 'id', + }, biblio => { module => 'Koha::Biblios', singular => 'biblio', diff --git a/Koha/ArticleRequest.pm b/Koha/ArticleRequest.pm index 75318fdf4c..6b4daf4ead 100644 --- a/Koha/ArticleRequest.pm +++ b/Koha/ArticleRequest.pm @@ -106,7 +106,7 @@ sub notify { if ( my $letter = C4::Letters::GetPreparedLetter( module => 'circulation', - letter_code => "AR_$status", + letter_code => "AR_$status", # AR_PENDING, AR_PROCESSING, AR_COMPLETED, AR_CANCELED message_transport_type => 'email', tables => { article_requests => $self->id, diff --git a/t/db_dependent/Letters/TemplateToolkit.t b/t/db_dependent/Letters/TemplateToolkit.t index 9bf8033213..38b50480f2 100644 --- a/t/db_dependent/Letters/TemplateToolkit.t +++ b/t/db_dependent/Letters/TemplateToolkit.t @@ -30,6 +30,7 @@ use C4::Members; use C4::Biblio; use Koha::Database; use Koha::DateUtils; +use Koha::ArticleRequests; use Koha::Biblio; use Koha::Biblioitem; use Koha::Item; @@ -39,6 +40,7 @@ use Koha::Serial; use Koha::Subscription; use Koha::Suggestion; use Koha::Checkout; +use Koha::Notice::Messages; use Koha::Notice::Templates; use Koha::Patron::Modification; @@ -282,7 +284,7 @@ $prepared_letter = GetPreparedLetter( is( $prepared_letter->{content}, $modification->id(), 'Patron modification object used correctly' ); subtest 'regression tests' => sub { - plan tests => 1; + plan tests => 2; my $library = $builder->build( { source => 'Branch' } ); my $patron = $builder->build( { source => 'Borrower' } ); @@ -323,6 +325,57 @@ subtest 'regression tests' => sub { is( $tt_letter->{content}, $letter->{content}, ); }; + + subtest 'AR_*' => sub { + plan tests => 2; + my $code = 'AR_CANCELED'; + my $branchcode = $library->{branchcode}; + + my $template = q| + <> <> (<>) + + Your request for an article from <> (<>) has been canceled for the following reason: + + <> + + Article requested: + Title: <> + Author: <> + Volume: <> + Issue: <> + Date: <> + Pages: <> + Chapters: <> + Notes: <> + |; + reset_template( { template => $template, code => $code, module => 'circulation' } ); + my $article_request = $builder->build({ source => 'ArticleRequest' }); + Koha::ArticleRequests->find( $article_request->{id} )->cancel; + my $letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next; + + my $tt_template = q| + [% borrower.firstname %] [% borrower.surname %] ([% borrower.cardnumber %]) + + Your request for an article from [% biblio.title %] ([% item.barcode %]) has been canceled for the following reason: + + [% article_request.notes %] + + Article requested: + Title: [% article_request.title %] + Author: [% article_request.author %] + Volume: [% article_request.volume %] + Issue: [% article_request.issue %] + Date: [% article_request.date %] + Pages: [% article_request.pages %] + Chapters: [% article_request.chapters %] + Notes: [% article_request.patron_notes %] + |; + reset_template( { template => $tt_template, code => $code, module => 'circulation' } ); + Koha::ArticleRequests->find( $article_request->{id} )->cancel; + my $tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next; + is( $tt_letter->content, $letter->content, 'Compare AR_* notices' ); + isnt( $tt_letter->message_id, $letter->message_id, 'Comparing AR_* notices should compare 2 different messages' ); + }; }; sub reset_template { -- 2.39.5