Bug 9088: if there is only one active order, pre-select it when creating new orderings
[koha.git] / t / db_dependent / Letters.t
blob9f5c9ace19442c5dc4ad42ef6ed721a80963a6f7
1 #!/usr/bin/perl
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>.
20 use Modern::Perl;
22 use Test::More tests => 5;
24 use C4::Context;
25 use C4::Letters;
26 use C4::Members;
28 my $dbh = C4::Context->dbh;
30 # Start transaction
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(
39 firstname => 'Jane',
40 surname => 'Smith',
41 categorycode => 'PT',
42 branchcode => 'CPL',
45 $dbh->do(q|
46 INSERT INTO message_transport_types( message_transport_type ) VALUES ('email'), ('phone'), ('print'), ('sms')
47 |);
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',
57 letter => {
58 content => 'a message',
59 title => 'message title',
60 metadata => 'metadata',
61 code => 'TEST_MESSAGE',
62 content_type => 'text/plain',
64 });
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');
74 is(
75 $messages->[0]->{status},
76 'failed',
77 'message marked failed if tried to send SMS message for borrower with no smsalertnumber set (bug 11208)'
80 $dbh->rollback;