From b753678c3dff4e0fd2fde008b3c43f0796fcfb05 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Mon, 30 Dec 2013 16:45:45 +0000 Subject: [PATCH] Bug 11208: regression test for failing SMS messages This patch adds a regression test for verifying that queued SMS messages meant for patrons who have no SMS alert number set are marked as failed after the first attempt to send them. To test: [1] Run prove -v t/db_dependent/Letters.t. The fourth test should. [2] Apply the main patch and run t/db_dependent/Letters.t again. This time, all tests should pass. Signed-off-by: Galen Charlton --- t/db_dependent/Letters.t | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 t/db_dependent/Letters.t diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t new file mode 100644 index 0000000000..77383594b0 --- /dev/null +++ b/t/db_dependent/Letters.t @@ -0,0 +1,71 @@ +#!/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 . + +use Modern::Perl; + +use Test::More tests => 4; + +use C4::Context; +use C4::Letters; +use C4::Members; + +my $dbh = C4::Context->dbh; + +# Start transaction +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; + +$dbh->do('DELETE FROM message_queue'); + +my $borrowernumber = AddMember( + firstname => 'Jane', + surname => 'Smith', + categorycode => 'PT', + branchcode => 'CPL', +); + +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; -- 2.39.5