Lines 18-24
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 => 94; |
21 |
use Test::More tests => 99; |
22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
23 |
use Test::Warn; |
23 |
use Test::Warn; |
24 |
use Test::Exception; |
24 |
use Test::Exception; |
Lines 520-551
t::lib::Mocks::mock_preference( 'ClaimsLog', 'on' );
Link Here
|
520 |
t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'library@domain.com' ); |
520 |
t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'library@domain.com' ); |
521 |
|
521 |
|
522 |
{ |
522 |
{ |
523 |
warning_like { |
523 |
warning_like { |
524 |
$err = SendAlerts( 'orderacquisition', $basketno , 'TESTACQORDER' ) } |
524 |
$err = SendAlerts( 'orderacquisition', $basketno, 'TESTACQORDER' ) |
|
|
525 |
} |
525 |
qr|Fake send_or_die|, |
526 |
qr|Fake send_or_die|, |
526 |
"SendAlerts is using the mocked send_or_die routine (orderacquisition)"; |
527 |
"SendAlerts is using the mocked send_or_die routine (orderacquisition)"; |
527 |
is($err, 1, "Successfully sent order."); |
528 |
is( $err, 1, "Successfully sent order." ); |
528 |
is($email_object->email->header('To'), 'testemail@mydomain.com', "mailto correct in sent order"); |
529 |
is( $email_object->email->header('To'), 'testemail@mydomain.com', "mailto correct in sent order" ); |
529 |
is($email_object->email->body, 'my vendor|John Smith|Ordernumber ' . $ordernumber . ' (Silence in the library) (1 ordered) Basket name: The basket name', 'Order notice text constructed successfully'); |
530 |
is( defined( $email_object->email->header('Reply-To') ), '', "No reply-to address is set" ); |
|
|
531 |
is( |
532 |
$email_object->email->body, |
533 |
'my vendor|John Smith|Ordernumber ' |
534 |
. $ordernumber |
535 |
. ' (Silence in the library) (1 ordered) Basket name: The basket name', |
536 |
'Order notice text constructed successfully' |
537 |
); |
530 |
|
538 |
|
531 |
my $mocked_koha_email = Test::MockModule->new('Koha::Email'); |
539 |
# SendAlerts should use specific email addresses if set |
532 |
$mocked_koha_email->mock( 'send_or_die', sub { |
540 |
t::lib::Mocks::mock_preference( 'AcquisitionsDefaultEMailAddress', 'acq-default@domain.com' ); |
533 |
Email::Sender::Failure->throw('something went wrong'); |
541 |
t::lib::Mocks::mock_preference( 'AcquisitionsDefaultReplyTo', 'acq-replyto@domain.com' ); |
534 |
}); |
|
|
535 |
|
542 |
|
536 |
warning_like { |
543 |
warning_like { |
537 |
$err = SendAlerts( 'orderacquisition', $basketno , 'TESTACQORDER' ); } |
544 |
$err = SendAlerts( 'orderacquisition', $basketno, 'TESTACQORDER' ) |
|
|
545 |
} |
546 |
qr|Fake send_or_die|, |
547 |
"SendAlerts is using the mocked send_or_die routine (orderacquisition)"; |
548 |
is( |
549 |
$email_object->email->header('From'), 'acq-default@domain.com', |
550 |
"AcquisitionsDefaultEMailAddress is used to sent acq notification" |
551 |
); |
552 |
is( |
553 |
$email_object->email->header('Reply-To'), 'acq-replyto@domain.com', |
554 |
"AcquisitionsDefaultReplyTo is used to sent acq notification" |
555 |
); |
556 |
|
557 |
my $mocked_koha_email = Test::MockModule->new('Koha::Email'); |
558 |
$mocked_koha_email->mock( |
559 |
'send_or_die', |
560 |
sub { |
561 |
Email::Sender::Failure->throw('something went wrong'); |
562 |
} |
563 |
); |
564 |
|
565 |
warning_like { |
566 |
$err = SendAlerts( 'orderacquisition', $basketno, 'TESTACQORDER' ); |
567 |
} |
538 |
qr{something went wrong}, |
568 |
qr{something went wrong}, |
539 |
'Warning is printed'; |
569 |
'Warning is printed'; |
540 |
|
570 |
|
541 |
is($err->{error}, 'something went wrong', "Send exception, error message returned"); |
571 |
is( $err->{error}, 'something went wrong', "Send exception, error message returned" ); |
542 |
|
572 |
|
543 |
$dbh->do(q{DELETE FROM letter WHERE code = 'TESTACQORDER';}); |
573 |
$dbh->do(q{DELETE FROM letter WHERE code = 'TESTACQORDER';}); |
544 |
warning_like { |
574 |
warning_like { |
545 |
$err = SendAlerts( 'orderacquisition', $basketno , 'TESTACQORDER' ) } |
575 |
$err = SendAlerts( 'orderacquisition', $basketno, 'TESTACQORDER' ) |
|
|
576 |
} |
546 |
qr/No orderacquisition TESTACQORDER letter transported by email/, |
577 |
qr/No orderacquisition TESTACQORDER letter transported by email/, |
547 |
"GetPreparedLetter warns about missing notice template"; |
578 |
"GetPreparedLetter warns about missing notice template"; |
548 |
is($err->{'error'}, 'no_letter', "No TESTACQORDER letter was defined."); |
579 |
is( $err->{'error'}, 'no_letter', "No TESTACQORDER letter was defined." ); |
549 |
} |
580 |
} |
550 |
|
581 |
|
551 |
{ |
582 |
{ |
Lines 656-662
subtest '_parseletter' => sub {
Link Here
|
656 |
}; |
687 |
}; |
657 |
|
688 |
|
658 |
subtest 'SendAlerts - claimissue' => sub { |
689 |
subtest 'SendAlerts - claimissue' => sub { |
659 |
plan tests => 13; |
690 |
plan tests => 18; |
660 |
|
691 |
|
661 |
use C4::Serials; |
692 |
use C4::Serials; |
662 |
|
693 |
|
Lines 733-743
subtest 'SendAlerts - claimissue' => sub {
Link Here
|
733 |
is( $err, 1, "Successfully sent claim" ); |
764 |
is( $err, 1, "Successfully sent claim" ); |
734 |
is( $email_object->email->header('To'), |
765 |
is( $email_object->email->header('To'), |
735 |
'testemail@mydomain.com', "mailto correct in sent claim" ); |
766 |
'testemail@mydomain.com', "mailto correct in sent claim" ); |
|
|
767 |
is( defined($email_object->email->header('Reply-To')), |
768 |
'', "reply-to is not set" ); |
736 |
is( |
769 |
is( |
737 |
$email_object->email->body, |
770 |
$email_object->email->body, |
738 |
"$serialids[0]|2013-01-01|Silence in the library|xxxx-yyyy", |
771 |
"$serialids[0]|2013-01-01|Silence in the library|xxxx-yyyy", |
739 |
'Serial claim letter for 1 issue constructed successfully' |
772 |
'Serial claim letter for 1 issue constructed successfully' |
740 |
); |
773 |
); |
|
|
774 |
} |
775 |
|
776 |
t::lib::Mocks::mock_preference( 'SerialsDefaultEMailAddress', 'ser-default@domain.com' ); |
777 |
t::lib::Mocks::mock_preference( 'SerialsDefaultReplyTo', 'ser-replyto@domain.com' ); |
778 |
|
779 |
{ |
780 |
warning_like { |
781 |
$err = SendAlerts( 'claimissues', \@serialids , 'TESTSERIALCLAIM' ) } |
782 |
qr|Fake send_or_die|, |
783 |
"SendAlerts is using the mocked send_or_die routine (claimissues)"; |
784 |
is( $email_object->email->header('From'), |
785 |
'ser-default@domain.com', "SerialsDefaultEMailAddress is used to serial claim issue" ); |
786 |
is( $email_object->email->header('Reply-To'), |
787 |
'ser-replyto@domain.com', "SerialsDefaultReplyTo is used to sent serial claim issue" ); |
741 |
|
788 |
|
742 |
my $mocked_koha_email = Test::MockModule->new('Koha::Email'); |
789 |
my $mocked_koha_email = Test::MockModule->new('Koha::Email'); |
743 |
$mocked_koha_email->mock( 'send_or_die', sub { |
790 |
$mocked_koha_email->mock( 'send_or_die', sub { |
744 |
- |
|
|