|
Lines 18-27
Link Here
|
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
use Test::More tests => 77; |
21 |
use Test::More tests => 83; |
| 22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
| 23 |
use Test::Warn; |
23 |
use Test::Warn; |
| 24 |
|
24 |
|
|
|
25 |
use Email::Sender::Failure; |
| 26 |
|
| 25 |
use MARC::Record; |
27 |
use MARC::Record; |
| 26 |
|
28 |
|
| 27 |
use utf8; |
29 |
use utf8; |
|
Lines 461-471
t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'library@domain.com' );
Link Here
|
| 461 |
warning_like { |
463 |
warning_like { |
| 462 |
$err = SendAlerts( 'orderacquisition', $basketno , 'TESTACQORDER' ) } |
464 |
$err = SendAlerts( 'orderacquisition', $basketno , 'TESTACQORDER' ) } |
| 463 |
qr|Fake send_or_die|, |
465 |
qr|Fake send_or_die|, |
| 464 |
"SendAlerts is using the mocked sendmail routine (orderacquisition)"; |
466 |
"SendAlerts is using the mocked send_or_die routine (orderacquisition)"; |
| 465 |
is($err, 1, "Successfully sent order."); |
467 |
is($err, 1, "Successfully sent order."); |
| 466 |
is($email_object->email->header('To'), 'testemail@mydomain.com', "mailto correct in sent order"); |
468 |
is($email_object->email->header('To'), 'testemail@mydomain.com', "mailto correct in sent order"); |
| 467 |
is($email_object->email->body, 'my vendor|John Smith|Ordernumber ' . $ordernumber . ' (Silence in the library) (1 ordered)', 'Order notice text constructed successfully'); |
469 |
is($email_object->email->body, 'my vendor|John Smith|Ordernumber ' . $ordernumber . ' (Silence in the library) (1 ordered)', 'Order notice text constructed successfully'); |
| 468 |
|
470 |
|
|
|
471 |
my $mocked_koha_email = Test::MockModule->new('Koha::Email'); |
| 472 |
$mocked_koha_email->mock( 'send_or_die', sub { |
| 473 |
Email::Sender::Failure->throw('something went wrong'); |
| 474 |
}); |
| 475 |
|
| 476 |
warning_like { |
| 477 |
$err = SendAlerts( 'orderacquisition', $basketno , 'TESTACQORDER' ); } |
| 478 |
qr{something went wrong}, |
| 479 |
'Warning is printed'; |
| 480 |
|
| 481 |
is($err->{error}, 'something went wrong', "Send exception, error message returned"); |
| 482 |
|
| 469 |
$dbh->do(q{DELETE FROM letter WHERE code = 'TESTACQORDER';}); |
483 |
$dbh->do(q{DELETE FROM letter WHERE code = 'TESTACQORDER';}); |
| 470 |
warning_like { |
484 |
warning_like { |
| 471 |
$err = SendAlerts( 'orderacquisition', $basketno , 'TESTACQORDER' ) } |
485 |
$err = SendAlerts( 'orderacquisition', $basketno , 'TESTACQORDER' ) } |
|
Lines 478-488
is($err->{'error'}, 'no_letter', "No TESTACQORDER letter was defined.");
Link Here
|
| 478 |
warning_like { |
492 |
warning_like { |
| 479 |
$err = SendAlerts( 'claimacquisition', [ $ordernumber ], 'TESTACQCLAIM' ) } |
493 |
$err = SendAlerts( 'claimacquisition', [ $ordernumber ], 'TESTACQCLAIM' ) } |
| 480 |
qr|Fake send_or_die|, |
494 |
qr|Fake send_or_die|, |
| 481 |
"SendAlerts is using the mocked sendmail routine"; |
495 |
"SendAlerts is using the mocked send_or_die routine"; |
| 482 |
|
496 |
|
| 483 |
is($err, 1, "Successfully sent claim"); |
497 |
is($err, 1, "Successfully sent claim"); |
| 484 |
is($email_object->email->header('To'), 'testemail@mydomain.com', "mailto correct in sent claim"); |
498 |
is($email_object->email->header('To'), 'testemail@mydomain.com', "mailto correct in sent claim"); |
| 485 |
is($email_object->email->body, 'my vendor|John Smith|Ordernumber ' . $ordernumber . ' (Silence in the library) (1 ordered)', 'Claim notice text constructed successfully'); |
499 |
is($email_object->email->body, 'my vendor|John Smith|Ordernumber ' . $ordernumber . ' (Silence in the library) (1 ordered)', 'Claim notice text constructed successfully'); |
|
|
500 |
|
| 501 |
my $mocked_koha_email = Test::MockModule->new('Koha::Email'); |
| 502 |
$mocked_koha_email->mock( 'send_or_die', sub { |
| 503 |
Email::Sender::Failure->throw('something went wrong'); |
| 504 |
}); |
| 505 |
|
| 506 |
warning_like { |
| 507 |
$err = SendAlerts( 'claimacquisition', [ $ordernumber ] , 'TESTACQCLAIM' ); } |
| 508 |
qr{something went wrong}, |
| 509 |
'Warning is printed'; |
| 510 |
|
| 511 |
is($err->{error}, 'something went wrong', "Send exception, error message returned"); |
| 486 |
} |
512 |
} |
| 487 |
|
513 |
|
| 488 |
{ |
514 |
{ |
|
Lines 520-526
my $err2;
Link Here
|
| 520 |
warning_like { |
546 |
warning_like { |
| 521 |
$err2 = SendAlerts( 'issue', $serial->{serialid}, 'RLIST' ) } |
547 |
$err2 = SendAlerts( 'issue', $serial->{serialid}, 'RLIST' ) } |
| 522 |
qr|Fake send_or_die|, |
548 |
qr|Fake send_or_die|, |
| 523 |
"SendAlerts is using the mocked sendmail routine"; |
549 |
"SendAlerts is using the mocked send_or_die routine"; |
| 524 |
|
550 |
|
| 525 |
is($err2, 1, "Successfully sent serial notification"); |
551 |
is($err2, 1, "Successfully sent serial notification"); |
| 526 |
is($email_object->email->header('To'), 'john.smith@test.de', "mailto correct in sent serial notification"); |
552 |
is($email_object->email->header('To'), 'john.smith@test.de', "mailto correct in sent serial notification"); |
|
Lines 532-544
my $err3;
Link Here
|
| 532 |
warning_like { |
558 |
warning_like { |
| 533 |
$err3 = SendAlerts( 'issue', $serial->{serialid}, 'RLIST' ) } |
559 |
$err3 = SendAlerts( 'issue', $serial->{serialid}, 'RLIST' ) } |
| 534 |
qr|Fake send_or_die|, |
560 |
qr|Fake send_or_die|, |
| 535 |
"SendAlerts is using the mocked sendmail routine"; |
561 |
"SendAlerts is using the mocked send_or_die routine"; |
| 536 |
is($email_object->email->header('To'), 'robert.tables@mail.com', "mailto address overwritten by SendAllMailsTo preference"); |
562 |
is($email_object->email->header('To'), 'robert.tables@mail.com', "mailto address overwritten by SendAllMailsTo preference"); |
|
|
563 |
|
| 564 |
my $mocked_koha_email = Test::MockModule->new('Koha::Email'); |
| 565 |
$mocked_koha_email->mock( 'send_or_die', sub { |
| 566 |
Email::Sender::Failure->throw('something went wrong'); |
| 567 |
}); |
| 568 |
|
| 569 |
warning_like { |
| 570 |
$err = SendAlerts( 'issue', $serial->{serialid} , 'RLIST' ); } |
| 571 |
qr{something went wrong}, |
| 572 |
'Warning is printed'; |
| 573 |
|
| 574 |
is($err->{error}, 'something went wrong', "Send exception, error message returned"); |
| 575 |
|
| 537 |
} |
576 |
} |
| 538 |
t::lib::Mocks::mock_preference( 'SendAllEmailsTo', '' ); |
577 |
t::lib::Mocks::mock_preference( 'SendAllEmailsTo', '' ); |
| 539 |
|
578 |
|
| 540 |
subtest 'SendAlerts - claimissue' => sub { |
579 |
subtest 'SendAlerts - claimissue' => sub { |
| 541 |
plan tests => 11; |
580 |
plan tests => 13; |
| 542 |
|
581 |
|
| 543 |
use C4::Serials; |
582 |
use C4::Serials; |
| 544 |
|
583 |
|
|
Lines 605-611
subtest 'SendAlerts - claimissue' => sub {
Link Here
|
| 605 |
warning_like { |
644 |
warning_like { |
| 606 |
$err = SendAlerts( 'claimissues', \@serialids , 'TESTSERIALCLAIM' ) } |
645 |
$err = SendAlerts( 'claimissues', \@serialids , 'TESTSERIALCLAIM' ) } |
| 607 |
qr|Fake send_or_die|, |
646 |
qr|Fake send_or_die|, |
| 608 |
"SendAlerts is using the mocked sendmail routine (claimissues)"; |
647 |
"SendAlerts is using the mocked send_or_die routine (claimissues)"; |
| 609 |
is( $err, 1, "Successfully sent claim" ); |
648 |
is( $err, 1, "Successfully sent claim" ); |
| 610 |
is( $email_object->email->header('To'), |
649 |
is( $email_object->email->header('To'), |
| 611 |
'testemail@mydomain.com', "mailto correct in sent claim" ); |
650 |
'testemail@mydomain.com', "mailto correct in sent claim" ); |
|
Lines 614-619
subtest 'SendAlerts - claimissue' => sub {
Link Here
|
| 614 |
"$serialids[0]|2013-01-01|Silence in the library|xxxx-yyyy", |
653 |
"$serialids[0]|2013-01-01|Silence in the library|xxxx-yyyy", |
| 615 |
'Serial claim letter for 1 issue constructed successfully' |
654 |
'Serial claim letter for 1 issue constructed successfully' |
| 616 |
); |
655 |
); |
|
|
656 |
|
| 657 |
my $mocked_koha_email = Test::MockModule->new('Koha::Email'); |
| 658 |
$mocked_koha_email->mock( 'send_or_die', sub { |
| 659 |
Email::Sender::Failure->throw('something went wrong'); |
| 660 |
}); |
| 661 |
|
| 662 |
warning_like { |
| 663 |
$err = SendAlerts( 'claimissues', \@serialids , 'TESTSERIALCLAIM' ); } |
| 664 |
qr{something went wrong}, |
| 665 |
'Warning is printed'; |
| 666 |
|
| 667 |
is($err->{error}, 'something went wrong', "Send exception, error message returned"); |
| 617 |
} |
668 |
} |
| 618 |
|
669 |
|
| 619 |
{ |
670 |
{ |
|
Lines 625-631
subtest 'SendAlerts - claimissue' => sub {
Link Here
|
| 625 |
|
676 |
|
| 626 |
warning_like { $err = SendAlerts( 'claimissues', \@serialids, 'TESTSERIALCLAIM' ); } |
677 |
warning_like { $err = SendAlerts( 'claimissues', \@serialids, 'TESTSERIALCLAIM' ); } |
| 627 |
qr|Fake send_or_die|, |
678 |
qr|Fake send_or_die|, |
| 628 |
"SendAlerts is using the mocked sendmail routine (claimissues)"; |
679 |
"SendAlerts is using the mocked send_or_die routine (claimissues)"; |
| 629 |
|
680 |
|
| 630 |
is( |
681 |
is( |
| 631 |
$email_object->email->body, |
682 |
$email_object->email->body, |
|
Lines 773-779
subtest 'SendQueuedMessages' => sub {
Link Here
|
| 773 |
|
824 |
|
| 774 |
warning_like { C4::Letters::SendQueuedMessages(); } |
825 |
warning_like { C4::Letters::SendQueuedMessages(); } |
| 775 |
qr|Fake send_or_die|, |
826 |
qr|Fake send_or_die|, |
| 776 |
"SendAlerts is using the mocked sendmail routine (claimissues)"; |
827 |
"SendAlerts is using the mocked send_or_die routine (claimissues)"; |
| 777 |
|
828 |
|
| 778 |
my $message = $schema->resultset('MessageQueue')->search({ |
829 |
my $message = $schema->resultset('MessageQueue')->search({ |
| 779 |
borrowernumber => $borrowernumber, |
830 |
borrowernumber => $borrowernumber, |
|
Lines 794-800
subtest 'SendQueuedMessages' => sub {
Link Here
|
| 794 |
$message_id = C4::Letters::EnqueueLetter($my_message); |
845 |
$message_id = C4::Letters::EnqueueLetter($my_message); |
| 795 |
warning_like { C4::Letters::SendQueuedMessages(); } |
846 |
warning_like { C4::Letters::SendQueuedMessages(); } |
| 796 |
qr|Fake send_or_die|, |
847 |
qr|Fake send_or_die|, |
| 797 |
"SendAlerts is using the mocked sendmail routine (claimissues)"; |
848 |
"SendAlerts is using the mocked send_or_die routine (claimissues)"; |
| 798 |
|
849 |
|
| 799 |
$message = $schema->resultset('MessageQueue')->search({ |
850 |
$message = $schema->resultset('MessageQueue')->search({ |
| 800 |
borrowernumber => $borrowernumber, |
851 |
borrowernumber => $borrowernumber, |
|
Lines 819-825
subtest 'SendQueuedMessages' => sub {
Link Here
|
| 819 |
|
870 |
|
| 820 |
warning_like { C4::Letters::SendQueuedMessages(); } |
871 |
warning_like { C4::Letters::SendQueuedMessages(); } |
| 821 |
qr|Fake send_or_die|, |
872 |
qr|Fake send_or_die|, |
| 822 |
"SendAlerts is using the mocked sendmail routine (claimissues)"; |
873 |
"SendAlerts is using the mocked send_or_die routine (claimissues)"; |
| 823 |
|
874 |
|
| 824 |
my $sms_message_address = $schema->resultset('MessageQueue')->search({ |
875 |
my $sms_message_address = $schema->resultset('MessageQueue')->search({ |
| 825 |
borrowernumber => $borrowernumber, |
876 |
borrowernumber => $borrowernumber, |
| 826 |
- |
|
|