Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 16; |
22 |
use Test::More tests => 17; |
23 |
|
23 |
|
24 |
use t::lib::Mocks; |
24 |
use t::lib::Mocks; |
25 |
use t::lib::TestBuilder; |
25 |
use t::lib::TestBuilder; |
Lines 111-117
subtest 'Add a test messaging attribute' => sub {
Link Here
|
111 |
}; |
111 |
}; |
112 |
|
112 |
|
113 |
subtest 'Add a test messaging transport' => sub { |
113 |
subtest 'Add a test messaging transport' => sub { |
114 |
plan tests => 2; |
114 |
plan tests => 4; |
115 |
|
115 |
|
116 |
ok(Koha::Patron::Message::Transport->new({ |
116 |
ok(Koha::Patron::Message::Transport->new({ |
117 |
message_attribute_id => $attribute->message_attribute_id, |
117 |
message_attribute_id => $attribute->message_attribute_id, |
Lines 119-125
subtest 'Add a test messaging transport' => sub {
Link Here
|
119 |
is_digest => 0, |
119 |
is_digest => 0, |
120 |
letter_module => "circulation", |
120 |
letter_module => "circulation", |
121 |
letter_code => "CHECKIN", |
121 |
letter_code => "CHECKIN", |
122 |
})->store, "Added a new messaging transport type."); |
122 |
})->store, "Added a new messaging transport type test."); |
|
|
123 |
ok(Koha::Patron::Message::Transport->new({ |
124 |
message_attribute_id => $attribute->message_attribute_id, |
125 |
message_transport_type => 'sms', |
126 |
is_digest => 0, |
127 |
letter_module => "circulation", |
128 |
letter_code => "CHECKIN", |
129 |
})->store, "Added a new messaging transport type sms."); |
130 |
ok(Koha::Patron::Message::Transport->new({ |
131 |
message_attribute_id => $attribute->message_attribute_id, |
132 |
message_transport_type => 'email', |
133 |
is_digest => 0, |
134 |
letter_module => "circulation", |
135 |
letter_code => "CHECKIN", |
136 |
})->store, "Added a new messaging transport type email."); |
123 |
is(Koha::Patron::Message::Transports->find({ |
137 |
is(Koha::Patron::Message::Transports->find({ |
124 |
message_transport_type => "test" })->message_attribute_id, |
138 |
message_transport_type => "test" })->message_attribute_id, |
125 |
$attribute->message_attribute_id , "Found test messaging transport from database."); |
139 |
$attribute->message_attribute_id , "Found test messaging transport from database."); |
Lines 182-188
subtest 'Add a messaging preference to patron' => sub {
Link Here
|
182 |
}; |
196 |
}; |
183 |
|
197 |
|
184 |
subtest 'Attempt to add a messaging preference with invalid parameters' => sub { |
198 |
subtest 'Attempt to add a messaging preference with invalid parameters' => sub { |
185 |
plan tests => 6; |
199 |
plan tests => 11; |
186 |
|
200 |
|
187 |
eval { Koha::Patron::Message::Preference->new->store }; |
201 |
eval { Koha::Patron::Message::Preference->new->store }; |
188 |
is (ref $@, "Koha::Exceptions::MissingParameter", |
202 |
is (ref $@, "Koha::Exceptions::MissingParameter", |
Lines 211-216
subtest 'Add a messaging preference to patron' => sub {
Link Here
|
211 |
." => Koha::Exceptions::BadParameter"); |
225 |
." => Koha::Exceptions::BadParameter"); |
212 |
is ($@->parameter, "categorycode", "The previous exception tells us it" |
226 |
is ($@->parameter, "categorycode", "The previous exception tells us it" |
213 |
." was the categorycode."); |
227 |
." was the categorycode."); |
|
|
228 |
eval { Koha::Patron::Message::Preference->new({ |
229 |
borrowernumber => $patron->{'borrowernumber'}, |
230 |
message_transport_types => ['nonexistent'] |
231 |
})->store }; |
232 |
is (ref $@, "Koha::Exceptions::BadParameter", |
233 |
"Adding a message preference with invalid message_transport_type" |
234 |
." => Koha::Exceptions::BadParameter"); |
235 |
is ($@->parameter, "message_transport_type", "The previous exception tells us it" |
236 |
." was the message_transport_type."); |
237 |
eval { |
238 |
Koha::Patron::Message::Preference->new({ |
239 |
borrowernumber => $patron->{'borrowernumber'}, |
240 |
message_attribute_id => $attribute->message_attribute_id, |
241 |
message_transport_types => ['sms'], |
242 |
wants_digest => 1, |
243 |
})->store }; |
244 |
is (ref $@, "Koha::Exceptions::BadParameter", |
245 |
"Adding a message preference with invalid message_transport_type" |
246 |
." => Koha::Exceptions::BadParameter"); |
247 |
is ($@->parameter, "message_transport_type", "The previous exception tells us it" |
248 |
." was the message_transport_type."); |
249 |
like ($@->error, qr/^Message transport option/, "Exception s because of given" |
250 |
." message_transport_type is not a valid option."); |
214 |
}; |
251 |
}; |
215 |
}; |
252 |
}; |
216 |
|
253 |
|
Lines 227-232
subtest 'Add a messaging transport preference to patron' => sub {
Link Here
|
227 |
"Found test messaging transport preference from database."); |
264 |
"Found test messaging transport preference from database."); |
228 |
}; |
265 |
}; |
229 |
|
266 |
|
|
|
267 |
subtest 'Test Koha::Patron::Message::Preference->message_transport_types' => sub { |
268 |
plan tests => 3; |
269 |
|
270 |
subtest 'Get' => sub { |
271 |
plan tests => 5; |
272 |
|
273 |
Koha::Patron::Message::Transport::Preferences->search({ |
274 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
275 |
})->delete; |
276 |
Koha::Patron::Message::Transport::Preference->new({ |
277 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
278 |
message_transport_type => 'sms', |
279 |
})->store; |
280 |
Koha::Patron::Message::Transport::Preference->new({ |
281 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
282 |
message_transport_type => 'email', |
283 |
})->store; |
284 |
my $stored_transports = Koha::Patron::Message::Transport::Preferences->search({ |
285 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
286 |
}); |
287 |
|
288 |
ok(Koha::Patron::Message::Preference->can('message_transport_types'), "Method available-"); |
289 |
my $transports = $preference->message_transport_types; |
290 |
is(keys $transports, $stored_transports->count, "->message_transport_types gets correct amount of transport types."); |
291 |
is($transports->{$stored_transports->next->message_transport_type}, "CHECKIN", "Found correct message transport type and letter code."); |
292 |
is($transports->{$stored_transports->next->message_transport_type}, "CHECKIN", "Found correct message transport type and letter code."); |
293 |
ok(!$preference->message_transport_types->{'nonexistent'}, "Didn't find nonexistent transport type."); |
294 |
}; |
295 |
|
296 |
subtest 'Set' => sub { |
297 |
plan tests => 9; |
298 |
|
299 |
# 1/3, use message_transport_types(list) |
300 |
Koha::Patron::Message::Transport::Preferences->search({ |
301 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
302 |
})->delete; |
303 |
ok($preference->message_transport_types('sms', 'email')->store, "1/3 Set returned true."); |
304 |
my $stored_transports = Koha::Patron::Message::Transport::Preferences->search({ |
305 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
306 |
}); |
307 |
is($stored_transports->next->message_transport_type, 'email', "First type is email."); |
308 |
is($stored_transports->next->message_transport_type, 'sms', "Second type is sms."); |
309 |
|
310 |
# 2/3, use message_transport_types(ARRAYREF) |
311 |
Koha::Patron::Message::Transport::Preferences->search({ |
312 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
313 |
})->delete; |
314 |
ok($preference->message_transport_types(['sms', 'email'])->store, "2/3 Set returned true."); |
315 |
$stored_transports = Koha::Patron::Message::Transport::Preferences->search({ |
316 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
317 |
}); |
318 |
is($stored_transports->next->message_transport_type, 'email', "First type is email."); |
319 |
is($stored_transports->next->message_transport_type, 'sms', "Second type is sms."); |
320 |
|
321 |
# 3/3, use set({ message_transport_types => ARRAYREF }) |
322 |
Koha::Patron::Message::Transport::Preferences->search({ |
323 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
324 |
})->delete; |
325 |
ok($preference->set({ message_transport_types => ['sms', 'email']})->store, "3/3 Set returned true."); |
326 |
$stored_transports = Koha::Patron::Message::Transport::Preferences->search({ |
327 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
328 |
}); |
329 |
is($stored_transports->next->message_transport_type, 'email', "First type is email."); |
330 |
is($stored_transports->next->message_transport_type, 'sms', "Second type is sms."); |
331 |
}; |
332 |
|
333 |
subtest 'New' => sub { |
334 |
plan tests => 3; |
335 |
|
336 |
$preference->delete; |
337 |
ok($preference = Koha::Patron::Message::Preference->new({ |
338 |
borrowernumber => $patron->{'borrowernumber'}, |
339 |
message_attribute_id => $attribute->message_attribute_id, |
340 |
wants_digest => 0, |
341 |
days_in_advance => 1, |
342 |
message_transport_types => $transport_type->message_transport_type, |
343 |
})->store, "Added a new messaging preference and transport types to patron."); |
344 |
ok($preference->message_transport_types->{$transport_type->message_transport_type}, |
345 |
"The transport type is stored in the object."); |
346 |
my $stored_transports = Koha::Patron::Message::Transport::Preferences->search({ |
347 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
348 |
}); |
349 |
is($stored_transports->next->message_transport_type, $transport_type->message_transport_type, |
350 |
"The transport type is stored in the database."); |
351 |
}; |
352 |
}; |
353 |
|
230 |
$schema->storage->txn_rollback; |
354 |
$schema->storage->txn_rollback; |
231 |
|
355 |
|
232 |
1; |
356 |
1; |
233 |
- |
|
|