From c25fe1e74aa6d6fd77bd7efd982d0e2d36660cb5 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Thu, 6 Mar 2014 16:59:44 -0500 Subject: [PATCH] Bug 8000 - Missing test to trigger code change This adds a test case which will trigger _send_message_by_email and thus provide a way to run the changes made. --- t/db_dependent/Letters.t | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index 356b075..d41434e 100644 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -18,7 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 61; +use Test::More tests => 63; use Test::MockModule; use Test::Warn; @@ -86,6 +86,7 @@ is_deeply( $mtts, ['email', 'phone', 'print', 'sms'], 'GetMessageTransportTypes # EnqueueLetter is( C4::Letters::EnqueueLetter(), undef, 'EnqueueLetter without argument returns undef' ); +# used to trigger _send_message_by_sms in C4::Letter my $my_message = { borrowernumber => $borrowernumber, message_transport_type => 'sms', @@ -110,13 +111,30 @@ $my_message->{message_transport_type} = 'sms'; $message_id = C4::Letters::EnqueueLetter($my_message); ok(defined $message_id && $message_id > 0, 'new message successfully queued'); +# used to trigger _send_message_by_email in C4::Letter +my $message_id2 = C4::Letters::EnqueueLetter({ + borrowernumber => $borrowernumber, + message_transport_type => 'email', + 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_id2 && $message_id2 > 0, 'new message successfully queued'); + # GetQueuedMessages my $messages = C4::Letters::GetQueuedMessages(); -is( @$messages, 1, 'GetQueuedMessages without argument returns all the entries' ); +is( @$messages, 2, 'GetQueuedMessages without argument returns all the entries' ); $messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber }); -is( @$messages, 1, 'one message stored for the borrower' ); +is( @$messages, 2, 'two messages stored for the borrower' ); is( $messages->[0]->{message_id}, $message_id, 'EnqueueLetter returns the message id correctly' ); is( $messages->[0]->{borrowernumber}, $borrowernumber, 'EnqueueLetter stores the borrower number correctly' ); is( $messages->[0]->{subject}, $my_message->{letter}->{title}, 'EnqueueLetter stores the subject correctly' ); @@ -127,9 +145,11 @@ is( $messages->[0]->{status}, 'pending', 'EnqueueLetter stores the status pendin # SendQueuedMessages my $messages_processed = C4::Letters::SendQueuedMessages(); -is($messages_processed, 1, 'all queued messages processed'); +is($messages_processed, 2, 'all queued messages processed'); $messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber }); +is(scalar(@$messages), 2, 'two messages stored for the borrower'); + is( $messages->[0]->{status}, 'failed', -- 2.1.4