3 # This file is part of Koha.
5 # Copyright (C) 2013 Equinox Software, Inc.
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.
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.
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>.
22 use Test
::More tests
=> 5;
28 my $dbh = C4
::Context
->dbh;
31 $dbh->{AutoCommit
} = 0;
32 $dbh->{RaiseError
} = 1;
34 $dbh->do(q
|DELETE FROM letter
|);
35 $dbh->do(q
|DELETE FROM message_queue
|);
36 $dbh->do(q
|DELETE FROM message_transport_types
|);
38 my $borrowernumber = AddMember
(
46 INSERT INTO message_transport_types
( message_transport_type
) VALUES
('email'), ('phone'), ('print'), ('sms')
49 my $mtts = C4
::Letters
::GetMessageTransportTypes
();
50 is_deeply
( $mtts, ['email', 'phone', 'print', 'sms'], 'GetMessageTransportTypes returns all values' );
52 my $message_id = C4
::Letters
::EnqueueLetter
({
53 borrowernumber
=> $borrowernumber,
54 message_transport_type
=> 'sms',
55 to_address
=> 'to@example.com',
56 from_address
=> 'from@example.com',
58 content
=> 'a message',
59 title
=> 'message title',
60 metadata
=> 'metadata',
61 code
=> 'TEST_MESSAGE',
62 content_type
=> 'text/plain',
66 ok
(defined $message_id && $message_id > 0, 'new message successfully queued');
68 my $messages_processed = C4
::Letters
::SendQueuedMessages
();
69 is
($messages_processed, 1, 'all queued messages processed');
71 my $messages = C4
::Letters
::GetQueuedMessages
({ borrowernumber
=> $borrowernumber });
72 is
(scalar(@
$messages), 1, 'one message stored for the borrower');
75 $messages->[0]->{status
},
77 'message marked failed if tried to send SMS message for borrower with no smsalertnumber set (bug 11208)'