Lines 18-24
Link Here
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use DateTime::Duration; |
20 |
use DateTime::Duration; |
21 |
use Test::More tests => 106; |
21 |
use Test::More tests => 107; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
|
23 |
|
24 |
use t::lib::Mocks; |
24 |
use t::lib::Mocks; |
Lines 32-38
use Koha::DateUtils qw( dt_from_string output_pref );
Link Here
|
32 |
use Koha::Libraries; |
32 |
use Koha::Libraries; |
33 |
use Koha::Patrons; |
33 |
use Koha::Patrons; |
34 |
use Koha::Suggestions; |
34 |
use Koha::Suggestions; |
35 |
|
|
|
36 |
BEGIN { |
35 |
BEGIN { |
37 |
use_ok('C4::Suggestions'); |
36 |
use_ok('C4::Suggestions'); |
38 |
} |
37 |
} |
Lines 61-66
$dbh->do(q|DELETE FROM borrowers|);
Link Here
|
61 |
$dbh->do(q|DELETE FROM letter|); |
60 |
$dbh->do(q|DELETE FROM letter|); |
62 |
$dbh->do(q|DELETE FROM message_queue|); |
61 |
$dbh->do(q|DELETE FROM message_queue|); |
63 |
$dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'CHECKED', 'my content')|); |
62 |
$dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'CHECKED', 'my content')|); |
|
|
63 |
$dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'NEW_SUGGESTION', 'Content for new suggestion')|); |
64 |
|
64 |
|
65 |
# Add CPL if missing. |
65 |
# Add CPL if missing. |
66 |
if (not defined Koha::Libraries->find('CPL')) { |
66 |
if (not defined Koha::Libraries->find('CPL')) { |
Lines 95-100
my $my_suggestion = {
Link Here
|
95 |
publishercode => 'my publishercode', |
95 |
publishercode => 'my publishercode', |
96 |
suggestedby => $borrowernumber, |
96 |
suggestedby => $borrowernumber, |
97 |
biblionumber => $biblionumber1, |
97 |
biblionumber => $biblionumber1, |
|
|
98 |
branchcode => 'CPL', |
98 |
managedby => '', |
99 |
managedby => '', |
99 |
manageddate => '', |
100 |
manageddate => '', |
100 |
accepteddate => dt_from_string, |
101 |
accepteddate => dt_from_string, |
Lines 190-195
is( $suggestion->{note}, 'my note', 'ModSuggestion should not erase data if not
Link Here
|
190 |
|
191 |
|
191 |
my $messages = C4::Letters::GetQueuedMessages({ |
192 |
my $messages = C4::Letters::GetQueuedMessages({ |
192 |
borrowernumber => $borrowernumber, |
193 |
borrowernumber => $borrowernumber, |
|
|
194 |
letter_code => 'CHECKED', |
193 |
}); |
195 |
}); |
194 |
is( @$messages, 0, 'ModSuggestions does not send an email if the status is not updated' ); |
196 |
is( @$messages, 0, 'ModSuggestions does not send an email if the status is not updated' ); |
195 |
|
197 |
|
Lines 217-222
$suggestion = GetSuggestion($my_suggestionid);
Link Here
|
217 |
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' ); |
219 |
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' ); |
218 |
$messages = C4::Letters::GetQueuedMessages({ |
220 |
$messages = C4::Letters::GetQueuedMessages({ |
219 |
borrowernumber => $borrowernumber, |
221 |
borrowernumber => $borrowernumber, |
|
|
222 |
letter_code => 'CHECKED', |
220 |
}); |
223 |
}); |
221 |
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' ); |
224 |
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' ); |
222 |
is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is disabled the suggestion message_transport_type is always email'); |
225 |
is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is disabled the suggestion message_transport_type is always email'); |
Lines 227-232
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 1 );
Link Here
|
227 |
ModSuggestion($mod_suggestion3); |
230 |
ModSuggestion($mod_suggestion3); |
228 |
$messages = C4::Letters::GetQueuedMessages({ |
231 |
$messages = C4::Letters::GetQueuedMessages({ |
229 |
borrowernumber => $borrowernumber, |
232 |
borrowernumber => $borrowernumber, |
|
|
233 |
letter_code => 'CHECKED', |
230 |
}); |
234 |
}); |
231 |
is ($messages->[1]->{message_transport_type}, 'sms', 'When FallbackToSMSIfNoEmail syspref is enabled the suggestion message_transport_type is sms if the borrower has no email'); |
235 |
is ($messages->[1]->{message_transport_type}, 'sms', 'When FallbackToSMSIfNoEmail syspref is enabled the suggestion message_transport_type is sms if the borrower has no email'); |
232 |
|
236 |
|
Lines 242-247
my $mod_suggestion4 = {
Link Here
|
242 |
ModSuggestion($mod_suggestion4); |
246 |
ModSuggestion($mod_suggestion4); |
243 |
$messages = C4::Letters::GetQueuedMessages({ |
247 |
$messages = C4::Letters::GetQueuedMessages({ |
244 |
borrowernumber => $borrowernumber2, |
248 |
borrowernumber => $borrowernumber2, |
|
|
249 |
letter_code => 'CHECKED', |
245 |
}); |
250 |
}); |
246 |
is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is enabled the suggestion message_transport_type is email if the borrower has an email'); |
251 |
is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is enabled the suggestion message_transport_type is email if the borrower has an email'); |
247 |
|
252 |
|
Lines 462-465
subtest 'DelSuggestionsOlderThan' => sub {
Link Here
|
462 |
is( Koha::Suggestions->count, 2, '1 suggestions>1d deleted' ); |
467 |
is( Koha::Suggestions->count, 2, '1 suggestions>1d deleted' ); |
463 |
}; |
468 |
}; |
464 |
|
469 |
|
|
|
470 |
subtest 'EmailPurchaseSuggestions' => sub { |
471 |
plan tests => 5; |
472 |
|
473 |
$dbh->do(q|DELETE FROM message_queue|); |
474 |
|
475 |
Koha::Libraries->find('CPL')->update({ branchemail => 'branchemail@b.c' }); |
476 |
t::lib::Mocks::mock_preference( "KohaAdminEmailAddress", 'root@localhost'); |
477 |
t::lib::Mocks::mock_preference( "EmailAddressForSuggestions", 'a@b.c'); |
478 |
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "KohaAdminEmailAddress"); # EmailAddressForSuggestions or BranchEmailAddress or KohaAdminEmailAddress |
479 |
|
480 |
NewSuggestion($my_suggestion); |
481 |
my $newsuggestions_messages = C4::Letters::GetQueuedMessages({ |
482 |
borrowernumber => $borrowernumber, |
483 |
letter_code => 'NEW_SUGGESTION', |
484 |
}); |
485 |
|
486 |
is( @$newsuggestions_messages, 1, 'NewSuggestions sends an email' ); |
487 |
my $message1 = C4::Letters::GetMessage( $newsuggestions_messages->[0]->{message_id}); |
488 |
is ($message1->{to_address}, 'root@localhost', 'to_address is KohaAdminEmailAddress'); |
489 |
|
490 |
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "EmailAddressForSuggestions"); |
491 |
NewSuggestion($my_suggestion); |
492 |
$newsuggestions_messages = C4::Letters::GetQueuedMessages({ |
493 |
borrowernumber => $borrowernumber, |
494 |
letter_code => 'NEW_SUGGESTION', |
495 |
}); |
496 |
my $message2 = C4::Letters::GetMessage( $newsuggestions_messages->[1]->{message_id}); |
497 |
is ($message2->{to_address}, 'a@b.c', 'to_address is EmailAddressForSuggestions'); |
498 |
|
499 |
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "BranchEmailAddress"); |
500 |
NewSuggestion($my_suggestion); |
501 |
$newsuggestions_messages = C4::Letters::GetQueuedMessages({ |
502 |
borrowernumber => $borrowernumber, |
503 |
letter_code => 'NEW_SUGGESTION', |
504 |
}); |
505 |
my $message3 = C4::Letters::GetMessage( $newsuggestions_messages->[2]->{message_id}); |
506 |
is ($message3->{to_address}, 'branchemail@b.c', 'to_address is BranchEmailAddress'); |
507 |
|
508 |
Koha::Libraries->find('CPL')->update({ branchemail => undef }); |
509 |
NewSuggestion($my_suggestion); |
510 |
$newsuggestions_messages = C4::Letters::GetQueuedMessages({ |
511 |
borrowernumber => $borrowernumber, |
512 |
letter_code => 'NEW_SUGGESTION', |
513 |
}); |
514 |
my $message4 = C4::Letters::GetMessage( $newsuggestions_messages->[3]->{message_id}); |
515 |
isnt ($message4->{to_address}, 'branchemail@b.c', 'to_address is KohaAdminEmailAddress. Because branchemail is undef'); |
516 |
|
517 |
}; |
518 |
|
465 |
$schema->storage->txn_rollback; |
519 |
$schema->storage->txn_rollback; |
466 |
- |
|
|