Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 4; |
22 |
use Test::More tests => 5; |
23 |
|
23 |
|
24 |
use t::lib::Mocks; |
24 |
use t::lib::Mocks; |
25 |
use t::lib::TestBuilder; |
25 |
use t::lib::TestBuilder; |
Lines 148-153
subtest 'Test Koha::Patron::Message::Preferences->get_options' => sub {
Link Here
|
148 |
}; |
148 |
}; |
149 |
}; |
149 |
}; |
150 |
|
150 |
|
|
|
151 |
subtest 'Add preferences from defaults' => sub { |
152 |
plan tests => 3; |
153 |
|
154 |
$schema->storage->txn_begin; |
155 |
|
156 |
my $patron = build_a_test_patron(); |
157 |
my ($default, $mtt1, $mtt2) = build_a_test_category_preference({ |
158 |
patron => $patron, |
159 |
}); |
160 |
ok(Koha::Patron::Message::Preference->new_from_default({ |
161 |
borrowernumber => $patron->borrowernumber, |
162 |
categorycode => $patron->categorycode, |
163 |
message_attribute_id => $default->message_attribute_id, |
164 |
})->store, 'Added a default preference to patron.'); |
165 |
ok(my $pref = Koha::Patron::Message::Preferences->find({ |
166 |
borrowernumber => $patron->borrowernumber, |
167 |
message_attribute_id => $default->message_attribute_id, |
168 |
}), 'Found the default preference from patron.'); |
169 |
is(Koha::Patron::Message::Transport::Preferences->search({ |
170 |
borrower_message_preference_id => $pref->borrower_message_preference_id |
171 |
})->count, 2, 'Found the two transport types that we set earlier'); |
172 |
|
173 |
$schema->storage->txn_rollback; |
174 |
}; |
175 |
|
151 |
subtest 'Test adding a new preference with invalid parameters' => sub { |
176 |
subtest 'Test adding a new preference with invalid parameters' => sub { |
152 |
plan tests => 4; |
177 |
plan tests => 4; |
153 |
|
178 |
|
Lines 280-285
sub build_a_test_category {
Link Here
|
280 |
return Koha::Patron::Categories->find($categorycode); |
305 |
return Koha::Patron::Categories->find($categorycode); |
281 |
} |
306 |
} |
282 |
|
307 |
|
|
|
308 |
sub build_a_test_letter { |
309 |
my ($params) = @_; |
310 |
|
311 |
my $mtt = $params->{mtt} ? $params->{mtt} : 'email'; |
312 |
my $branchcode = $builder->build({ |
313 |
source => 'Branch' })->{branchcode}; |
314 |
my $letter = $builder->build({ |
315 |
source => 'Letter', |
316 |
value => { |
317 |
branchcode => '', |
318 |
is_html => 0, |
319 |
message_transport_type => $mtt |
320 |
} |
321 |
}); |
322 |
|
323 |
return Koha::Notice::Templates->find({ |
324 |
module => $letter->{module}, |
325 |
code => $letter->{code}, |
326 |
branchcode => $letter->{branchcode}, |
327 |
}); |
328 |
} |
329 |
|
283 |
sub build_a_test_patron { |
330 |
sub build_a_test_patron { |
284 |
my $categorycode = $builder->build({ |
331 |
my $categorycode = $builder->build({ |
285 |
source => 'Category' })->{categorycode}; |
332 |
source => 'Category' })->{categorycode}; |
Lines 291-294
sub build_a_test_patron {
Link Here
|
291 |
return Koha::Patrons->find($borrowernumber); |
338 |
return Koha::Patrons->find($borrowernumber); |
292 |
} |
339 |
} |
293 |
|
340 |
|
|
|
341 |
sub build_a_test_transport_type { |
342 |
my $mtt = $builder->build({ |
343 |
source => 'MessageTransportType' }); |
344 |
|
345 |
return Koha::Patron::Message::Transport::Types->find( |
346 |
$mtt->{message_transport_type} |
347 |
); |
348 |
} |
349 |
|
350 |
sub build_a_test_category_preference { |
351 |
my ($params) = @_; |
352 |
|
353 |
my $patron = $params->{patron}; |
354 |
my $attr = $params->{attr} |
355 |
? $params->{attr} |
356 |
: build_a_test_attribute($params->{days_in_advance}); |
357 |
|
358 |
my $letter = $params->{letter} ? $params->{letter} : build_a_test_letter(); |
359 |
my $mtt1 = $params->{mtt1} ? $params->{mtt1} : build_a_test_transport_type(); |
360 |
my $mtt2 = $params->{mtt2} ? $params->{mtt2} : build_a_test_transport_type(); |
361 |
|
362 |
Koha::Patron::Message::Transport->new({ |
363 |
message_attribute_id => $attr->message_attribute_id, |
364 |
message_transport_type => $mtt1->message_transport_type, |
365 |
is_digest => $params->{digest} ? 1 : 0, |
366 |
letter_module => $letter->module, |
367 |
letter_code => $letter->code, |
368 |
})->store; |
369 |
|
370 |
Koha::Patron::Message::Transport->new({ |
371 |
message_attribute_id => $attr->message_attribute_id, |
372 |
message_transport_type => $mtt2->message_transport_type, |
373 |
is_digest => $params->{digest} ? 1 : 0, |
374 |
letter_module => $letter->module, |
375 |
letter_code => $letter->code, |
376 |
})->store; |
377 |
|
378 |
my $default = Koha::Patron::Message::Preference->new({ |
379 |
categorycode => $patron->categorycode, |
380 |
message_attribute_id => $attr->message_attribute_id, |
381 |
wants_digest => $params->{digest} ? 1 : 0, |
382 |
days_in_advance => $params->{days_in_advance} |
383 |
? $params->{days_in_advance} : 0, |
384 |
})->store; |
385 |
|
386 |
Koha::Patron::Message::Transport::Preference->new({ |
387 |
borrower_message_preference_id => $default->borrower_message_preference_id, |
388 |
message_transport_type => $mtt1->message_transport_type, |
389 |
})->store; |
390 |
Koha::Patron::Message::Transport::Preference->new({ |
391 |
borrower_message_preference_id => $default->borrower_message_preference_id, |
392 |
message_transport_type => $mtt2->message_transport_type, |
393 |
})->store; |
394 |
|
395 |
return ($default, $mtt1, $mtt2); |
396 |
} |
397 |
|
294 |
1; |
398 |
1; |
295 |
- |
|
|