Lines 467-523
subtest 'DelSuggestionsOlderThan' => sub {
Link Here
|
467 |
}; |
467 |
}; |
468 |
|
468 |
|
469 |
subtest 'EmailPurchaseSuggestions' => sub { |
469 |
subtest 'EmailPurchaseSuggestions' => sub { |
470 |
plan tests => 6; |
470 |
plan tests => 11; |
471 |
|
471 |
|
472 |
$dbh->do(q|DELETE FROM message_queue|); |
472 |
$dbh->do(q|DELETE FROM message_queue|); |
473 |
|
473 |
|
474 |
Koha::Libraries->find('CPL')->update({ branchemail => 'branchemail@b.c' }); |
474 |
t::lib::Mocks::mock_preference( "KohaAdminEmailAddress", |
475 |
t::lib::Mocks::mock_preference( "KohaAdminEmailAddress", 'root@localhost'); |
475 |
'noreply@hosting.com' ); |
476 |
t::lib::Mocks::mock_preference( "EmailAddressForSuggestions", 'a@b.c'); |
|
|
477 |
|
476 |
|
478 |
# EmailAddressForSuggestions or BranchEmailAddress or KohaAdminEmailAddress or 0 |
477 |
# EmailPurchaseSuggestions set to disabled |
479 |
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "0"); |
478 |
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "0" ); |
480 |
NewSuggestion($my_suggestion); |
479 |
NewSuggestion($my_suggestion); |
481 |
my $newsuggestions_messages = C4::Letters::GetQueuedMessages({ |
480 |
my $newsuggestions_messages = C4::Letters::GetQueuedMessages( |
|
|
481 |
{ |
482 |
borrowernumber => $borrowernumber |
482 |
borrowernumber => $borrowernumber |
483 |
}); |
483 |
} |
484 |
|
484 |
); |
485 |
is( @$newsuggestions_messages, 0, 'NewSuggestions does not send an email when disabled' ); |
485 |
is( @$newsuggestions_messages, 0, |
|
|
486 |
'NewSuggestions does not send an email when disabled' ); |
487 |
|
488 |
# EmailPurchaseSuggestions set to BranchEmailAddress |
489 |
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", |
490 |
"BranchEmailAddress" ); |
491 |
NewSuggestion($my_suggestion); |
486 |
|
492 |
|
487 |
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "KohaAdminEmailAddress"); |
493 |
t::lib::Mocks::mock_preference( "ReplytoDefault", 'library@b.c' ); |
488 |
NewSuggestion($my_suggestion); |
494 |
NewSuggestion($my_suggestion); |
489 |
my $newsuggestions_messages = C4::Letters::GetQueuedMessages({ |
|
|
490 |
borrowernumber => $borrowernumber |
491 |
}); |
492 |
|
495 |
|
493 |
is( @$newsuggestions_messages, 1, 'NewSuggestions sends an email' ); |
496 |
Koha::Libraries->find('CPL')->update( { branchemail => 'branchemail@hosting.com' } ); |
494 |
my $message1 = C4::Letters::GetMessage( $newsuggestions_messages->[0]->{message_id}); |
497 |
NewSuggestion($my_suggestion); |
495 |
is ($message1->{to_address}, 'root@localhost', 'to_address is KohaAdminEmailAddress'); |
|
|
496 |
|
498 |
|
497 |
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "EmailAddressForSuggestions"); |
499 |
Koha::Libraries->find('CPL')->update( { branchreplyto => 'branchemail@b.c' } ); |
498 |
NewSuggestion($my_suggestion); |
500 |
NewSuggestion($my_suggestion); |
499 |
$newsuggestions_messages = C4::Letters::GetQueuedMessages({ |
501 |
|
|
|
502 |
$newsuggestions_messages = C4::Letters::GetQueuedMessages( |
503 |
{ |
500 |
borrowernumber => $borrowernumber |
504 |
borrowernumber => $borrowernumber |
501 |
}); |
505 |
} |
502 |
my $message2 = C4::Letters::GetMessage( $newsuggestions_messages->[1]->{message_id}); |
506 |
); |
503 |
is ($message2->{to_address}, 'a@b.c', 'to_address is EmailAddressForSuggestions'); |
507 |
isnt( @$newsuggestions_messages, 0, 'NewSuggestions sends an email' ); |
|
|
508 |
my $message1 = |
509 |
C4::Letters::GetMessage( $newsuggestions_messages->[0]->{message_id} ); |
510 |
is( $message1->{to_address}, 'noreply@hosting.com', |
511 |
'BranchEmailAddress falls back to KohaAdminEmailAddress if branchreplyto, branchemail and ReplytoDefault are not set' |
512 |
); |
513 |
my $message2 = |
514 |
C4::Letters::GetMessage( $newsuggestions_messages->[1]->{message_id} ); |
515 |
is( $message2->{to_address}, 'library@b.c', |
516 |
'BranchEmailAddress falls back to ReplytoDefault if neither branchreplyto or branchemail are set' |
517 |
); |
518 |
my $message3 = |
519 |
C4::Letters::GetMessage( $newsuggestions_messages->[2]->{message_id} ); |
520 |
is( $message3->{to_address}, 'branchemail@hosting.com', |
521 |
'BranchEmailAddress uses branchemail if branch_replto is not set' |
522 |
); |
523 |
my $message4 = |
524 |
C4::Letters::GetMessage( $newsuggestions_messages->[3]->{message_id} ); |
525 |
is( $message4->{to_address}, 'branchemail@b.c', |
526 |
'BranchEmailAddress uses branchreplyto in preference to branchemail when set' |
527 |
); |
528 |
|
529 |
# EmailPurchaseSuggestions set to KohaAdminEmailAddress |
530 |
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", |
531 |
"KohaAdminEmailAddress" ); |
532 |
|
533 |
t::lib::Mocks::mock_preference( "ReplytoDefault", undef ); |
534 |
NewSuggestion($my_suggestion); |
504 |
|
535 |
|
505 |
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "BranchEmailAddress"); |
536 |
t::lib::Mocks::mock_preference( "ReplytoDefault", 'library@b.c' ); |
506 |
NewSuggestion($my_suggestion); |
537 |
NewSuggestion($my_suggestion); |
507 |
$newsuggestions_messages = C4::Letters::GetQueuedMessages({ |
538 |
|
|
|
539 |
$newsuggestions_messages = C4::Letters::GetQueuedMessages( |
540 |
{ |
508 |
borrowernumber => $borrowernumber |
541 |
borrowernumber => $borrowernumber |
509 |
}); |
542 |
} |
510 |
my $message3 = C4::Letters::GetMessage( $newsuggestions_messages->[2]->{message_id}); |
543 |
); |
511 |
is ($message3->{to_address}, 'branchemail@b.c', 'to_address is BranchEmailAddress'); |
544 |
my $message5 = |
|
|
545 |
C4::Letters::GetMessage( $newsuggestions_messages->[4]->{message_id} ); |
546 |
is( $message5->{to_address}, |
547 |
'noreply@hosting.com', 'KohaAdminEmailAddress uses KohaAdminEmailAddress when ReplytoDefault is not set' ); |
548 |
my $message6 = |
549 |
C4::Letters::GetMessage( $newsuggestions_messages->[5]->{message_id} ); |
550 |
is( $message6->{to_address}, |
551 |
'library@b.c', 'KohaAdminEmailAddress uses ReplytoDefualt when ReplytoDefault is set' ); |
552 |
|
553 |
# EmailPurchaseSuggestions set to EmailAddressForSuggestions |
554 |
t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", |
555 |
"EmailAddressForSuggestions" ); |
556 |
|
557 |
t::lib::Mocks::mock_preference( "ReplytoDefault", undef ); |
558 |
NewSuggestion($my_suggestion); |
512 |
|
559 |
|
513 |
Koha::Libraries->find('CPL')->update({ branchemail => undef }); |
560 |
t::lib::Mocks::mock_preference( "ReplytoDefault", 'library@b.c' ); |
514 |
NewSuggestion($my_suggestion); |
561 |
NewSuggestion($my_suggestion); |
515 |
$newsuggestions_messages = C4::Letters::GetQueuedMessages({ |
|
|
516 |
borrowernumber => $borrowernumber |
517 |
}); |
518 |
my $message4 = C4::Letters::GetMessage( $newsuggestions_messages->[3]->{message_id}); |
519 |
isnt ($message4->{to_address}, 'branchemail@b.c', 'to_address is KohaAdminEmailAddress. Because branchemail is undef'); |
520 |
|
562 |
|
|
|
563 |
t::lib::Mocks::mock_preference( "EmailAddressForSuggestions", |
564 |
'suggestions@b.c' ); |
565 |
NewSuggestion($my_suggestion); |
566 |
|
567 |
$newsuggestions_messages = C4::Letters::GetQueuedMessages( |
568 |
{ |
569 |
borrowernumber => $borrowernumber |
570 |
} |
571 |
); |
572 |
my $message7 = |
573 |
C4::Letters::GetMessage( $newsuggestions_messages->[6]->{message_id} ); |
574 |
is( $message7->{to_address}, |
575 |
'noreply@hosting.com', 'EmailAddressForSuggestions uses KohaAdminEmailAddress when neither EmailAddressForSuggestions or ReplytoDefault are set' ); |
576 |
|
577 |
my $message8 = |
578 |
C4::Letters::GetMessage( $newsuggestions_messages->[7]->{message_id} ); |
579 |
is( $message8->{to_address}, |
580 |
'library@b.c', 'EmailAddressForSuggestions uses ReplytoDefault when EmailAddressForSuggestions is not set' ); |
581 |
|
582 |
my $message9 = |
583 |
C4::Letters::GetMessage( $newsuggestions_messages->[8]->{message_id} ); |
584 |
is( $message9->{to_address}, |
585 |
'suggestions@b.c', 'EmailAddressForSuggestions uses EmailAddressForSuggestions when set' ); |
521 |
}; |
586 |
}; |
522 |
|
587 |
|
523 |
$schema->storage->txn_rollback; |
588 |
$schema->storage->txn_rollback; |
524 |
- |
|
|