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

(-)a/t/db_dependent/Letters.t (-4 / +53 lines)
Lines 87-92 is_deeply( $mtts, ['email', 'phone', 'print', 'sms'], 'GetMessageTransportTypes Link Here
87
# EnqueueLetter
87
# EnqueueLetter
88
is( C4::Letters::EnqueueLetter(), undef, 'EnqueueLetter without argument returns undef' );
88
is( C4::Letters::EnqueueLetter(), undef, 'EnqueueLetter without argument returns undef' );
89
89
90
# used to trigger _send_message_by_sms in C4::Letter
90
my $my_message = {
91
my $my_message = {
91
    borrowernumber         => $borrowernumber,
92
    borrowernumber         => $borrowernumber,
92
    message_transport_type => 'sms',
93
    message_transport_type => 'sms',
Lines 111-123 $my_message->{message_transport_type} = 'sms'; Link Here
111
$message_id = C4::Letters::EnqueueLetter($my_message);
112
$message_id = C4::Letters::EnqueueLetter($my_message);
112
ok(defined $message_id && $message_id > 0, 'new message successfully queued');
113
ok(defined $message_id && $message_id > 0, 'new message successfully queued');
113
114
115
# This is will force C4::Context->preference() to read the DB.
116
C4::Context->disable_syspref_cache();
117
118
# used to trigger _send_message_by_email in C4::Letter
119
# first override.
120
$dbh->do("UPDATE systempreferences SET value='override\@example.com' WHERE variable='SendAllEmailsTo';");
121
my $message_id2 = C4::Letters::EnqueueLetter({
122
    borrowernumber         => $borrowernumber,
123
    message_transport_type => 'email',
124
    to_address             => 'to@example.com',
125
    from_address           => 'from@example.com',
126
    letter => {
127
        content      => 'a message',
128
        title        => 'message title',
129
        metadata     => 'metadata',
130
        code         => 'TEST_MESSAGE',
131
        content_type => 'text/plain',
132
    },
133
});
134
135
ok(defined $message_id2 && $message_id2 > 0, 'new message successfully queued');
136
114
137
115
# GetQueuedMessages
138
# GetQueuedMessages
116
my $messages = C4::Letters::GetQueuedMessages();
139
my $messages = C4::Letters::GetQueuedMessages();
117
is( @$messages, 1, 'GetQueuedMessages without argument returns all the entries' );
140
is( @$messages, 2, 'GetQueuedMessages without argument returns all the entries' );
118
141
119
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
142
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
120
is( @$messages, 1, 'one message stored for the borrower' );
143
is( @$messages, 2, 'two messages stored for the borrower' );
121
is( $messages->[0]->{message_id}, $message_id, 'EnqueueLetter returns the message id correctly' );
144
is( $messages->[0]->{message_id}, $message_id, 'EnqueueLetter returns the message id correctly' );
122
is( $messages->[0]->{borrowernumber}, $borrowernumber, 'EnqueueLetter stores the borrower number correctly' );
145
is( $messages->[0]->{borrowernumber}, $borrowernumber, 'EnqueueLetter stores the borrower number correctly' );
123
is( $messages->[0]->{subject}, $my_message->{letter}->{title}, 'EnqueueLetter stores the subject correctly' );
146
is( $messages->[0]->{subject}, $my_message->{letter}->{title}, 'EnqueueLetter stores the subject correctly' );
Lines 128-141 is( $messages->[0]->{status}, 'pending', 'EnqueueLetter stores the status pendin Link Here
128
151
129
# SendQueuedMessages
152
# SendQueuedMessages
130
my $messages_processed = C4::Letters::SendQueuedMessages();
153
my $messages_processed = C4::Letters::SendQueuedMessages();
131
is($messages_processed, 1, 'all queued messages processed');
154
is($messages_processed, 2, 'all queued messages processed');
155
156
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
157
is(scalar(@$messages), 2, 'two messages stored for the borrower');
158
159
# used to trigger _send_message_by_email in C4::Letter
160
# second no override.
161
$dbh->do("UPDATE systempreferences SET value='' WHERE variable='SendAllEmailsTo';");
162
my $message_id3 = C4::Letters::EnqueueLetter({
163
    borrowernumber         => $borrowernumber,
164
    message_transport_type => 'email',
165
    to_address             => 'to@example.com',
166
    from_address           => 'from@example.com',
167
    letter => {
168
        content      => 'a message',
169
        title        => 'message title',
170
        metadata     => 'metadata',
171
        code         => 'TEST_MESSAGE',
172
        content_type => 'text/plain',
173
    },
174
});
175
176
$messages_processed = C4::Letters::SendQueuedMessages();
177
is($messages_processed, 1, 'third queued message processed');
132
178
133
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
179
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
180
is(scalar(@$messages), 3, 'three messages stored for the borrower');
181
134
is(
182
is(
135
    $messages->[0]->{status},
183
    $messages->[0]->{status},
136
    'failed',
184
    'failed',
137
    'message marked failed if tried to send SMS message for borrower with no smsalertnumber set (bug 11208)'
185
    'message marked failed if tried to send SMS message for borrower with no smsalertnumber set (bug 11208)'
138
);
186
);
187
is ( $messages->[1]->{sentto_address},'override@example.com','Second message sent to override.');
188
is ( $messages->[2]->{sentto_address},'to@example.com','Third message sent to default.');
139
189
140
# ResendMessage
190
# ResendMessage
141
my $resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
191
my $resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
142
- 

Return to bug 8000