diff --git a/C4/Letters.pm b/C4/Letters.pm index f6802cef43..cf64147256 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1498,6 +1498,12 @@ sub _get_tt_params { plural => 'news', pk => 'idnew', }, + aqorders => { + module => 'Koha::Tmp::Orders', # Should Koha::Acquisition::Orders when will be based on Koha::Objects + singular => 'order', + plural => 'orders', + pk => 'ordernumber', + }, reserves => { module => 'Koha::Holds', singular => 'hold', diff --git a/t/db_dependent/Letters/TemplateToolkit.t b/t/db_dependent/Letters/TemplateToolkit.t index bdcfb96ff0..9bf8033213 100644 --- a/t/db_dependent/Letters/TemplateToolkit.t +++ b/t/db_dependent/Letters/TemplateToolkit.t @@ -18,7 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 15; +use Test::More tests => 16; use Test::Warn; use MARC::Record; @@ -39,6 +39,7 @@ use Koha::Serial; use Koha::Subscription; use Koha::Suggestion; use Koha::Checkout; +use Koha::Notice::Templates; use Koha::Patron::Modification; my $schema = Koha::Database->schema; @@ -279,3 +280,88 @@ $prepared_letter = GetPreparedLetter( ) ); is( $prepared_letter->{content}, $modification->id(), 'Patron modification object used correctly' ); + +subtest 'regression tests' => sub { + plan tests => 1; + + my $library = $builder->build( { source => 'Branch' } ); + my $patron = $builder->build( { source => 'Borrower' } ); + my $biblio = Koha::Biblio->new({title => 'Test Biblio'})->store->unblessed; + my $biblioitem = Koha::Biblioitem->new({biblionumber => $biblio->{biblionumber}})->store()->unblessed; + my $item1 = Koha::Item->new( + { + biblionumber => $biblio->{biblionumber}, + biblioitemnumber => $biblioitem->{biblioitemnumber}, + } + )->store->unblessed; + my $item2 = Koha::Item->new( + { + biblionumber => $biblio->{biblionumber}, + biblioitemnumber => $biblioitem->{biblioitemnumber}, + } + )->store->unblessed; + + subtest 'ACQ_NOTIF_ON_RECEIV ' => sub { + plan tests => 1; + my $code = 'ACQ_NOTIF_ON_RECEIV'; + my $branchcode = $library->{branchcode}; + my $order = $builder->build({ source => 'Aqorder' }); + + my $template = q| + Dear <> <>, + The order <> (<>) has been received. + Your library. + |; + my $params = { code => $code, branchcode => $branchcode, tables => { branches => $library, borrowers => $patron, biblio => $biblio, aqorders => $order } }; + my $letter = process_letter( { template => $template, %$params }); + my $tt_template = q| + Dear [% borrower.firstname %] [% borrower.surname %], + The order [% order.ordernumber %] ([% biblio.title %]) has been received. + Your library. + |; + my $tt_letter = process_letter( { template => $tt_template, %$params }); + + is( $tt_letter->{content}, $letter->{content}, ); + }; +}; + +sub reset_template { + my ( $params ) = @_; + my $template = $params->{template}; + my $code = $params->{code}; + my $module = $params->{module} || 'test_module'; + + Koha::Notice::Templates->search( { code => $code } )->delete; + Koha::Notice::Template->new( + { + module => $module, + code => $code, + branchcode => '', + name => $code, + title => $code, + message_transport_type => 'email', + content => $template + } + )->store; +} + +sub process_letter { + my ($params) = @_; + my $template = $params->{template}; + my $tables = $params->{tables}; + my $substitute = $params->{substitute}; + my $code = $params->{code}; + my $module = $params->{module} || 'test_module'; + my $branchcode = $params->{branchcode}; + + reset_template( $params ); + + my $letter = C4::Letters::GetPreparedLetter( + module => $module, + letter_code => $code, + branchcode => '', + tables => $tables, + substitute => $substitute, + ); + return $letter; +}