Lines 51-59
subtest 'Test Koha::Patron::Message::Preferences' => sub {
Link Here
|
51 |
|
51 |
|
52 |
$schema->storage->txn_begin; |
52 |
$schema->storage->txn_begin; |
53 |
|
53 |
|
54 |
my $attribute = build_a_test_attribute(); |
54 |
my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' }); |
55 |
my $letter = build_a_test_letter(); |
55 |
my $letter = build_a_test_letter(); |
56 |
my $mtt = build_a_test_transport_type(); |
56 |
my $mtt = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' }); |
57 |
Koha::Patron::Message::Transport->new({ |
57 |
Koha::Patron::Message::Transport->new({ |
58 |
message_attribute_id => $attribute->message_attribute_id, |
58 |
message_attribute_id => $attribute->message_attribute_id, |
59 |
message_transport_type => $mtt->message_transport_type, |
59 |
message_transport_type => $mtt->message_transport_type, |
Lines 65-71
subtest 'Test Koha::Patron::Message::Preferences' => sub {
Link Here
|
65 |
subtest 'Test for a patron' => sub { |
65 |
subtest 'Test for a patron' => sub { |
66 |
plan tests => 3; |
66 |
plan tests => 3; |
67 |
|
67 |
|
68 |
my $patron = build_a_test_patron(); |
68 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
69 |
Koha::Patron::Message::Preference->new({ |
69 |
Koha::Patron::Message::Preference->new({ |
70 |
borrowernumber => $patron->borrowernumber, |
70 |
borrowernumber => $patron->borrowernumber, |
71 |
message_attribute_id => $attribute->message_attribute_id, |
71 |
message_attribute_id => $attribute->message_attribute_id, |
Lines 99-105
subtest 'Test Koha::Patron::Message::Preferences' => sub {
Link Here
|
99 |
}; |
99 |
}; |
100 |
|
100 |
|
101 |
subtest 'Test for a category' => sub { |
101 |
subtest 'Test for a category' => sub { |
102 |
my $category = build_a_test_category(); |
102 |
my $category = $builder->build_object({ class => 'Koha::Patron::Categories' }); |
103 |
Koha::Patron::Message::Preference->new({ |
103 |
Koha::Patron::Message::Preference->new({ |
104 |
categorycode => $category->categorycode, |
104 |
categorycode => $category->categorycode, |
105 |
message_attribute_id => $attribute->message_attribute_id, |
105 |
message_attribute_id => $attribute->message_attribute_id, |
Lines 167-173
subtest 'Add preferences from defaults' => sub {
Link Here
|
167 |
|
167 |
|
168 |
$schema->storage->txn_begin; |
168 |
$schema->storage->txn_begin; |
169 |
|
169 |
|
170 |
my $patron = build_a_test_patron(); |
170 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
171 |
my ($default, $mtt1, $mtt2) = build_a_test_category_preference({ |
171 |
my ($default, $mtt1, $mtt2) = build_a_test_category_preference({ |
172 |
patron => $patron, |
172 |
patron => $patron, |
173 |
}); |
173 |
}); |
Lines 198-204
subtest 'Test Koha::Patron::Message::Preference->message_transport_types' => sub
Link Here
|
198 |
|
198 |
|
199 |
$schema->storage->txn_begin; |
199 |
$schema->storage->txn_begin; |
200 |
|
200 |
|
201 |
my $patron = build_a_test_patron(); |
201 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
202 |
my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({ |
202 |
my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({ |
203 |
patron => $patron |
203 |
patron => $patron |
204 |
}); |
204 |
}); |
Lines 261-267
HERE
Link Here
|
261 |
my $transports = $pref->message_transport_types; |
261 |
my $transports = $pref->message_transport_types; |
262 |
is($appender, undef, 'Nothing in buffer yet'); |
262 |
is($appender, undef, 'Nothing in buffer yet'); |
263 |
|
263 |
|
264 |
my $mtt_new = build_a_test_transport_type(); |
264 |
my $mtt_new = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' }); |
265 |
Koha::Patron::Message::Transport::Preference->new({ |
265 |
Koha::Patron::Message::Transport::Preference->new({ |
266 |
borrower_message_preference_id => |
266 |
borrower_message_preference_id => |
267 |
$pref->borrower_message_preference_id, |
267 |
$pref->borrower_message_preference_id, |
Lines 286-292
HERE
Link Here
|
286 |
|
286 |
|
287 |
$schema->storage->txn_begin; |
287 |
$schema->storage->txn_begin; |
288 |
|
288 |
|
289 |
my $patron = build_a_test_patron(); |
289 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
290 |
my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({ |
290 |
my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({ |
291 |
patron => $patron |
291 |
patron => $patron |
292 |
}); |
292 |
}); |
Lines 386-395
HERE
Link Here
|
386 |
|
386 |
|
387 |
$schema->storage->txn_begin; |
387 |
$schema->storage->txn_begin; |
388 |
|
388 |
|
389 |
my $patron = build_a_test_patron(); |
389 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
390 |
my $letter = build_a_test_letter(); |
390 |
my $letter = build_a_test_letter(); |
391 |
my $attribute = build_a_test_attribute(); |
391 |
my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' }); |
392 |
my $mtt = build_a_test_transport_type(); |
392 |
my $mtt = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' }); |
393 |
Koha::Patron::Message::Transport->new({ |
393 |
Koha::Patron::Message::Transport->new({ |
394 |
message_attribute_id => $attribute->message_attribute_id, |
394 |
message_attribute_id => $attribute->message_attribute_id, |
395 |
message_transport_type => $mtt->message_transport_type, |
395 |
message_transport_type => $mtt->message_transport_type, |
Lines 421-428
subtest 'Test Koha::Patron::Message::Preference->message_name' => sub {
Link Here
|
421 |
|
421 |
|
422 |
$schema->storage->txn_begin; |
422 |
$schema->storage->txn_begin; |
423 |
|
423 |
|
424 |
my $patron = build_a_test_patron(); |
424 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
425 |
my $attribute = build_a_test_attribute(); |
425 |
my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' }); |
426 |
my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({ |
426 |
my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({ |
427 |
patron => $patron, |
427 |
patron => $patron, |
428 |
attr => $attribute, |
428 |
attr => $attribute, |
Lines 453-459
subtest 'Test adding a new preference with invalid parameters' => sub {
Link Here
|
453 |
|
453 |
|
454 |
$schema->storage->txn_begin; |
454 |
$schema->storage->txn_begin; |
455 |
|
455 |
|
456 |
my $patron = build_a_test_patron(); |
456 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
457 |
eval { Koha::Patron::Message::Preference->new({ |
457 |
eval { Koha::Patron::Message::Preference->new({ |
458 |
borrowernumber => $patron->borrowernumber, |
458 |
borrowernumber => $patron->borrowernumber, |
459 |
categorycode => $patron->categorycode, |
459 |
categorycode => $patron->categorycode, |
Lines 489-495
subtest 'Test adding a new preference with invalid parameters' => sub {
Link Here
|
489 |
.' was the categorycode.'); |
489 |
.' was the categorycode.'); |
490 |
|
490 |
|
491 |
my $attribute = build_a_test_attribute({ takes_days => 0 }); |
491 |
my $attribute = build_a_test_attribute({ takes_days => 0 }); |
492 |
my $patron = build_a_test_patron(); |
492 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
493 |
eval { Koha::Patron::Message::Preference->new({ |
493 |
eval { Koha::Patron::Message::Preference->new({ |
494 |
borrowernumber => $patron->borrowernumber, |
494 |
borrowernumber => $patron->borrowernumber, |
495 |
message_attribute_id => $attribute->message_attribute_id, |
495 |
message_attribute_id => $attribute->message_attribute_id, |
Lines 523-529
subtest 'Test adding a new preference with invalid parameters' => sub {
Link Here
|
523 |
is ($@->parameter, 'message_transport_types', 'The previous exception ' |
523 |
is ($@->parameter, 'message_transport_types', 'The previous exception ' |
524 |
.'tells us it was the message_transport_types.'); |
524 |
.'tells us it was the message_transport_types.'); |
525 |
|
525 |
|
526 |
my $mtt_new = build_a_test_transport_type(); |
526 |
my $mtt_new = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' }); |
527 |
eval { |
527 |
eval { |
528 |
Koha::Patron::Message::Preference->new({ |
528 |
Koha::Patron::Message::Preference->new({ |
529 |
borrowernumber => $patron->borrowernumber, |
529 |
borrowernumber => $patron->borrowernumber, |
Lines 591-599
subtest 'Test adding a new preference with invalid parameters' => sub {
Link Here
|
591 |
|
591 |
|
592 |
$schema->storage->txn_begin; |
592 |
$schema->storage->txn_begin; |
593 |
|
593 |
|
594 |
my $attribute = build_a_test_attribute(); |
594 |
my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' }); |
595 |
my $letter = build_a_test_letter(); |
595 |
my $letter = build_a_test_letter(); |
596 |
my $mtt = build_a_test_transport_type(); |
596 |
my $mtt = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' }); |
597 |
Koha::Patron::Message::Transport->new({ |
597 |
Koha::Patron::Message::Transport->new({ |
598 |
message_attribute_id => $attribute->message_attribute_id, |
598 |
message_attribute_id => $attribute->message_attribute_id, |
599 |
message_transport_type => $mtt->message_transport_type, |
599 |
message_transport_type => $mtt->message_transport_type, |
Lines 601-607
subtest 'Test adding a new preference with invalid parameters' => sub {
Link Here
|
601 |
letter_module => $letter->module, |
601 |
letter_module => $letter->module, |
602 |
letter_code => $letter->code, |
602 |
letter_code => $letter->code, |
603 |
})->store; |
603 |
})->store; |
604 |
my $patron = build_a_test_patron(); |
604 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
605 |
my $preference = Koha::Patron::Message::Preference->new({ |
605 |
my $preference = Koha::Patron::Message::Preference->new({ |
606 |
borrowernumber => $patron->borrowernumber, |
606 |
borrowernumber => $patron->borrowernumber, |
607 |
message_attribute_id => $attribute->message_attribute_id, |
607 |
message_attribute_id => $attribute->message_attribute_id, |
Lines 640-652
sub build_a_test_attribute {
Link Here
|
640 |
); |
640 |
); |
641 |
} |
641 |
} |
642 |
|
642 |
|
643 |
sub build_a_test_category { |
|
|
644 |
my $categorycode = $builder->build({ |
645 |
source => 'Category' })->{categorycode}; |
646 |
|
647 |
return Koha::Patron::Categories->find($categorycode); |
648 |
} |
649 |
|
650 |
sub build_a_test_letter { |
643 |
sub build_a_test_letter { |
651 |
my ($params) = @_; |
644 |
my ($params) = @_; |
652 |
|
645 |
|
Lines 669-694
sub build_a_test_letter {
Link Here
|
669 |
}); |
662 |
}); |
670 |
} |
663 |
} |
671 |
|
664 |
|
672 |
sub build_a_test_patron { |
|
|
673 |
my $categorycode = $builder->build({ |
674 |
source => 'Category' })->{categorycode}; |
675 |
my $branchcode = $builder->build({ |
676 |
source => 'Branch' })->{branchcode}; |
677 |
my $borrowernumber = $builder->build({ |
678 |
source => 'Borrower' })->{borrowernumber}; |
679 |
|
680 |
return Koha::Patrons->find($borrowernumber); |
681 |
} |
682 |
|
683 |
sub build_a_test_transport_type { |
684 |
my $mtt = $builder->build({ |
685 |
source => 'MessageTransportType' }); |
686 |
|
687 |
return Koha::Patron::Message::Transport::Types->find( |
688 |
$mtt->{message_transport_type} |
689 |
); |
690 |
} |
691 |
|
692 |
sub build_a_test_category_preference { |
665 |
sub build_a_test_category_preference { |
693 |
my ($params) = @_; |
666 |
my ($params) = @_; |
694 |
|
667 |
|
Lines 698-705
sub build_a_test_category_preference {
Link Here
|
698 |
: build_a_test_attribute($params->{days_in_advance}); |
671 |
: build_a_test_attribute($params->{days_in_advance}); |
699 |
|
672 |
|
700 |
my $letter = $params->{letter} ? $params->{letter} : build_a_test_letter(); |
673 |
my $letter = $params->{letter} ? $params->{letter} : build_a_test_letter(); |
701 |
my $mtt1 = $params->{mtt1} ? $params->{mtt1} : build_a_test_transport_type(); |
674 |
my $mtt1 = $params->{mtt1} ? $params->{mtt1} : $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' }); |
702 |
my $mtt2 = $params->{mtt2} ? $params->{mtt2} : build_a_test_transport_type(); |
675 |
my $mtt2 = $params->{mtt2} ? $params->{mtt2} : $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' }); |
703 |
|
676 |
|
704 |
Koha::Patron::Message::Transport->new({ |
677 |
Koha::Patron::Message::Transport->new({ |
705 |
message_attribute_id => $attr->message_attribute_id, |
678 |
message_attribute_id => $attr->message_attribute_id, |