Bug 10012: DBRev 3.15.00.024
[koha.git] / t / db_dependent / Letters.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright (C) 2013 Equinox Software, Inc.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use Test::More tests => 4;
23
24 use C4::Context;
25 use C4::Letters;
26 use C4::Members;
27
28 my $dbh = C4::Context->dbh;
29
30 # Start transaction
31 $dbh->{AutoCommit} = 0;
32 $dbh->{RaiseError} = 1;
33
34 $dbh->do('DELETE FROM message_queue');
35
36 my $borrowernumber = AddMember(
37     firstname    => 'Jane',
38     surname      => 'Smith',
39     categorycode => 'PT',
40     branchcode   => 'CPL',
41 );
42
43 my $message_id = C4::Letters::EnqueueLetter({
44     borrowernumber         => $borrowernumber,
45     message_transport_type => 'sms',
46     to_address             => 'to@example.com',
47     from_address           => 'from@example.com',
48     letter => {
49         content      => 'a message',
50         title        => 'message title',
51         metadata     => 'metadata',
52         code         => 'TEST_MESSAGE',
53         content_type => 'text/plain',
54     },
55 });
56
57 ok(defined $message_id && $message_id > 0, 'new message successfully queued');
58
59 my $messages_processed = C4::Letters::SendQueuedMessages();
60 is($messages_processed, 1, 'all queued messages processed');
61
62 my $messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
63 is(scalar(@$messages), 1, 'one message stored for the borrower');
64
65 is(
66     $messages->[0]->{status},
67     'failed',
68     'message marked failed if tried to send SMS message for borrower with no smsalertnumber set (bug 11208)'
69 );
70
71 $dbh->rollback;