Koha/t/db_dependent/Letters.t
Jonathan Druart 8214541114 Bug 9016: Create a message for each transport type.
This patch adds:
- a new jquery plugin : insertatcaret.
- the ability to define a notice template for each transport type.
- a new routine C4::Letters::GetMessageTransportTypes.

Test plan:
- Go on tools/letter.pl and check that all existing notices are still
  there.
- Modify one. A new empty message is present for sms, print, etc. The
  email message is filled with the existant value.
- Add a message for sms for example (don't forget the subject) and save.
- edit again and verify the sms message has been saved.

Signed-off-by: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
2014-05-02 20:29:16 +00:00

80 lines
2.4 KiB
Perl

#!/usr/bin/perl
# This file is part of Koha.
#
# Copyright (C) 2013 Equinox Software, Inc.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 5;
use C4::Context;
use C4::Letters;
use C4::Members;
my $dbh = C4::Context->dbh;
# Start transaction
$dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
$dbh->do(q|DELETE FROM letter|);
$dbh->do(q|DELETE FROM message_queue|);
$dbh->do(q|DELETE FROM message_transport_types|);
my $borrowernumber = AddMember(
firstname => 'Jane',
surname => 'Smith',
categorycode => 'PT',
branchcode => 'CPL',
);
$dbh->do(q|
INSERT INTO message_transport_types( message_transport_type ) VALUES ('email'), ('phone'), ('print'), ('sms')
|);
my $mtts = C4::Letters::GetMessageTransportTypes();
is_deeply( $mtts, ['email', 'phone', 'print', 'sms'], 'GetMessageTransportTypes returns all values' );
my $message_id = C4::Letters::EnqueueLetter({
borrowernumber => $borrowernumber,
message_transport_type => 'sms',
to_address => 'to@example.com',
from_address => 'from@example.com',
letter => {
content => 'a message',
title => 'message title',
metadata => 'metadata',
code => 'TEST_MESSAGE',
content_type => 'text/plain',
},
});
ok(defined $message_id && $message_id > 0, 'new message successfully queued');
my $messages_processed = C4::Letters::SendQueuedMessages();
is($messages_processed, 1, 'all queued messages processed');
my $messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
is(scalar(@$messages), 1, 'one message stored for the borrower');
is(
$messages->[0]->{status},
'failed',
'message marked failed if tried to send SMS message for borrower with no smsalertnumber set (bug 11208)'
);
$dbh->rollback;