View | Details | Raw Unified | Return to bug 8000
Collapse All | Expand All

(-)a/t/db_dependent/Letters.t (-5 / +24 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 58;
21
use Test::More tests => 60;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 82-87 is_deeply( $mtts, ['email', 'phone', 'print', 'sms'], 'GetMessageTransportTypes Link Here
82
# EnqueueLetter
82
# EnqueueLetter
83
is( C4::Letters::EnqueueLetter(), undef, 'EnqueueLetter without argument returns undef' );
83
is( C4::Letters::EnqueueLetter(), undef, 'EnqueueLetter without argument returns undef' );
84
84
85
# used to trigger _send_message_by_sms in C4::Letter
85
my $my_message = {
86
my $my_message = {
86
    borrowernumber         => $borrowernumber,
87
    borrowernumber         => $borrowernumber,
87
    message_transport_type => 'sms',
88
    message_transport_type => 'sms',
Lines 106-118 $my_message->{message_transport_type} = 'sms'; Link Here
106
$message_id = C4::Letters::EnqueueLetter($my_message);
107
$message_id = C4::Letters::EnqueueLetter($my_message);
107
ok(defined $message_id && $message_id > 0, 'new message successfully queued');
108
ok(defined $message_id && $message_id > 0, 'new message successfully queued');
108
109
110
# used to trigger _send_message_by_email in C4::Letter
111
my $message_id2 = C4::Letters::EnqueueLetter({
112
    borrowernumber         => $borrowernumber,
113
    message_transport_type => 'email',
114
    to_address             => 'to@example.com',
115
    from_address           => 'from@example.com',
116
    letter => {
117
        content      => 'a message',
118
        title        => 'message title',
119
        metadata     => 'metadata',
120
        code         => 'TEST_MESSAGE',
121
        content_type => 'text/plain',
122
    },
123
});
124
125
ok(defined $message_id2 && $message_id2 > 0, 'new message successfully queued');
126
109
127
110
# GetQueuedMessages
128
# GetQueuedMessages
111
my $messages = C4::Letters::GetQueuedMessages();
129
my $messages = C4::Letters::GetQueuedMessages();
112
is( @$messages, 1, 'GetQueuedMessages without argument returns all the entries' );
130
is( @$messages, 2, 'GetQueuedMessages without argument returns all the entries' );
113
131
114
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
132
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
115
is( @$messages, 1, 'one message stored for the borrower' );
133
is( @$messages, 2, 'two messages stored for the borrower' );
116
is( $messages->[0]->{message_id}, $message_id, 'EnqueueLetter returns the message id correctly' );
134
is( $messages->[0]->{message_id}, $message_id, 'EnqueueLetter returns the message id correctly' );
117
is( $messages->[0]->{borrowernumber}, $borrowernumber, 'EnqueueLetter stores the borrower number correctly' );
135
is( $messages->[0]->{borrowernumber}, $borrowernumber, 'EnqueueLetter stores the borrower number correctly' );
118
is( $messages->[0]->{subject}, $my_message->{letter}->{title}, 'EnqueueLetter stores the subject correctly' );
136
is( $messages->[0]->{subject}, $my_message->{letter}->{title}, 'EnqueueLetter stores the subject correctly' );
Lines 123-131 is( $messages->[0]->{status}, 'pending', 'EnqueueLetter stores the status pendin Link Here
123
141
124
# SendQueuedMessages
142
# SendQueuedMessages
125
my $messages_processed = C4::Letters::SendQueuedMessages();
143
my $messages_processed = C4::Letters::SendQueuedMessages();
126
is($messages_processed, 1, 'all queued messages processed');
144
is($messages_processed, 2, 'all queued messages processed');
127
145
128
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
146
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
147
is(scalar(@$messages), 2, 'two messages stored for the borrower');
148
129
is(
149
is(
130
    $messages->[0]->{status},
150
    $messages->[0]->{status},
131
    'failed',
151
    'failed',
132
- 

Return to bug 8000