From 4bd91e967634eed281a0d63497441f7d6acff466 Mon Sep 17 00:00:00 2001
From: Katrin Fischer <Katrin.Fischer.83@web.de>
Date: Mon, 25 May 2015 17:01:46 +0200
Subject: [PATCH] [Signed-off] Bug 13972: Follow-up - Add unit tests for
 changed parts of SendAlerts
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

To test:
- prove t/db_dependent/Letters.t

Signed-off-by: Marc Véron <veron@veron.ch>
---
 t/db_dependent/Letters.t |   43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t
index 8599c3f..69eeb72 100644
--- a/t/db_dependent/Letters.t
+++ b/t/db_dependent/Letters.t
@@ -18,7 +18,7 @@
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
-use Test::More tests => 58;
+use Test::More tests => 62;
 use Test::MockModule;
 use Test::Warn;
 
@@ -336,6 +336,7 @@ $bookseller->contacts->[0]->email('testemail@mydomain.com');
 C4::Bookseller::ModBookseller($bookseller);
 $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
 
+{
 warning_is {
     $err = SendAlerts( 'claimacquisition', [ $ordernumber ], 'TESTACQCLAIM' ) }
     "Fake sendmail",
@@ -344,5 +345,45 @@ warning_is {
 is($err, 1, "Successfully sent claim");
 is($mail{'To'}, 'testemail@mydomain.com', "mailto correct in sent claim");
 is($mail{'Message'}, 'my vendor|John Smith|Ordernumber ' . $ordernumber . ' (Silence in the library) (1 ordered)', 'Claim notice text constructed successfully');
+}
+
+{
+use C4::Serials;
+
+my $notes = 'notes';
+my $internalnotes = 'intnotes';
+my $subscriptionid = NewSubscription(
+     undef,      "",     undef, undef, undef, $biblionumber,
+    '2013-01-01', 1, undef, undef,  undef,
+    undef,      undef,  undef, undef, undef, undef,
+    1,          $notes,undef, '2013-01-01', undef, 1,
+    undef,       undef,  0,    $internalnotes,  0,
+    undef, undef, 0,          undef,         '2013-12-31', 0
+);
+$dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('serial','RLIST','Serial issue notification','Serial issue notification','<<biblio.title>>,<<subscription.subscriptionid>>,<<serial.serialseq>>');});
+my ($serials_count, @serials) = GetSerials($subscriptionid);
+my $serial = $serials[0];
+
+my $borrowernumber = AddMember(
+    firstname    => 'John',
+    surname      => 'Smith',
+    categorycode => 'PT',
+    branchcode   => 'CPL',
+    dateofbirth  => $date,
+    email        => 'john.smith@test.de',
+);
+my $alert_id = C4::Letters::addalert($borrowernumber, 'issue', $subscriptionid);
+
+
+my $err2;
+warning_is {
+$err2 = SendAlerts( 'issue', $serial->{serialid}, 'RLIST' ) }
+    "Fake sendmail",
+    "SendAlerts is using the mocked sendmail routine";
+is($err2, "", "Successfully sent serial notification");
+is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notification");
+is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
+}
+
 
 $schema->storage->txn_rollback();
-- 
1.7.10.4