From 1e120924c2bfd11c4e0bf4a8479897d6cc2cf921 Mon Sep 17 00:00:00 2001 From: Katrin Fischer Date: Wed, 19 Oct 2016 23:26:22 +0200 Subject: [PATCH] Bug 5260: QA follow-up: Fix error when no notice template is defined When no notice template ACQORDER was defined, you'r receive a false positive "email sent" message. Now it will display a specific error message instead. Also includes 2 unit tests to test for the warn and new error code. Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall --- C4/Letters.pm | 2 +- acqui/basket.pl | 6 ++---- koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt | 2 ++ t/db_dependent/Letters.t | 9 ++++++++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index ef3433aad3..a981e8a4b9 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -566,7 +566,7 @@ sub SendAlerts { }, repeat => $dataorders, want_librarian => 1, - ) or return; + ) or return { error => "no_letter" }; # Remove the order tag $letter->{content} =~ s/(.*?)<\/order>/$1/gxms; diff --git a/acqui/basket.pl b/acqui/basket.pl index b8caba578c..054d743e88 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -178,10 +178,8 @@ if ( $op eq 'delete_confirm' ) { }; if ( $@ ) { $redirect_url .= '&email_error='.$@; - } elsif ( ref $err and exists $err->{error} and $err->{error} eq "no_email" ) { - $redirect_url .= '&email_error=no_email'; - } elsif ( ref $err and exists $err->{error} and $err->{error} eq "no_basketno" ) { - $redirect_url .= '&email_error=no_basketno'; + } elsif ( ref $err and exists $err->{error} ) { + $redirect_url .= '&email_error=' . $err->{error}; } else { $redirect_url .= '&email_ok=1'; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt index f94fbf4f9f..8a114fdb07 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt @@ -301,6 +301,8 @@ This vendor has no contact selected for sending orders to or is missing an e-mail address. [% ELSIF ( email_error == "no_basketno" ) %] No basket given. + [% ELSIF ( email_error == "no_letter" ) %] + There is no notice template with code ACQORDER defined. [% ELSE %] ERROR! - [% email_error %] [% END %] diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index d283c01c82..3f20306795 100644 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -18,7 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 78; +use Test::More tests => 80; use Test::MockModule; use Test::Warn; @@ -431,6 +431,13 @@ warning_is { is($err, 1, "Successfully sent order."); is($mail{'To'}, 'testemail@mydomain.com', "mailto correct in sent order"); is($mail{'Message'}, 'my vendor|John Smith|Ordernumber ' . $ordernumber . ' (Silence in the library) (1 ordered)', 'Order notice text constructed successfully'); + +$dbh->do(q{DELETE FROM letter WHERE code = 'TESTACQORDER';}); +warning_like { + $err = SendAlerts( 'orderacquisition', $basketno , 'TESTACQORDER' ) } + qr/No orderacquisition TESTACQORDER letter transported by email/, + "GetPreparedLetter warns about missing notice template"; +is($err->{'error'}, 'no_letter', "No TESTACQORDER letter was defined."); } -- 2.39.5