Lines 957-963
subtest 'Test SMS handling in SendQueuedMessages' => sub {
Link Here
|
957 |
|
957 |
|
958 |
subtest 'Test guarantor handling in SendQueuedMessages' => sub { |
958 |
subtest 'Test guarantor handling in SendQueuedMessages' => sub { |
959 |
|
959 |
|
960 |
plan tests => 7; |
960 |
plan tests => 19; |
961 |
|
961 |
|
962 |
t::lib::Mocks::mock_preference( 'borrowerRelationship', 'test' ); |
962 |
t::lib::Mocks::mock_preference( 'borrowerRelationship', 'test' ); |
963 |
|
963 |
|
Lines 982-990
subtest 'Test guarantor handling in SendQueuedMessages' => sub {
Link Here
|
982 |
}; |
982 |
}; |
983 |
$message_id = C4::Letters::EnqueueLetter($my_message); |
983 |
$message_id = C4::Letters::EnqueueLetter($my_message); |
984 |
|
984 |
|
|
|
985 |
# feature disabled |
986 |
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '0' ); |
987 |
|
988 |
warning_like { C4::Letters::SendQueuedMessages(); } |
989 |
qr|No 'to_address', email address or guarantors email address for borrowernumber|, |
990 |
"SendQueuedMessages fails when no to_address, patron notice email and RedirectGuaranteeEmail is not set"; |
991 |
|
985 |
# feature enabled |
992 |
# feature enabled |
986 |
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '1' ); |
993 |
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '1' ); |
987 |
|
994 |
|
|
|
995 |
# reset message - testing without to or borrower valid email |
996 |
Koha::Notice::Messages->find($message_id)->delete; |
997 |
$message_id = C4::Letters::EnqueueLetter($my_message); |
998 |
|
988 |
warning_like { C4::Letters::SendQueuedMessages(); } |
999 |
warning_like { C4::Letters::SendQueuedMessages(); } |
989 |
qr|Fake send_or_die|, |
1000 |
qr|Fake send_or_die|, |
990 |
"SendQueuedMessages is using the mocked send_or_die routine"; |
1001 |
"SendQueuedMessages is using the mocked send_or_die routine"; |
Lines 1011-1026
subtest 'Test guarantor handling in SendQueuedMessages' => sub {
Link Here
|
1011 |
is( $email_object->email->header('To'), $guarantor1->email, "mailto correctly uses first guarantor" ); |
1022 |
is( $email_object->email->header('To'), $guarantor1->email, "mailto correctly uses first guarantor" ); |
1012 |
is( $email_object->email->header('Cc'), $guarantor2->email, "cc correctly uses second guarantor" ); |
1023 |
is( $email_object->email->header('Cc'), $guarantor2->email, "cc correctly uses second guarantor" ); |
1013 |
|
1024 |
|
1014 |
# feature disabled |
1025 |
# reset message - testing borrower with valid email |
1015 |
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '0' ); |
|
|
1016 |
|
1017 |
# reset message |
1018 |
Koha::Notice::Messages->find($message_id)->delete; |
1026 |
Koha::Notice::Messages->find($message_id)->delete; |
|
|
1027 |
$message_id = C4::Letters::EnqueueLetter($my_message); |
1028 |
|
1029 |
$patron->email('patron@example.com')->store(); |
1030 |
|
1031 |
warning_like { C4::Letters::SendQueuedMessages(); } |
1032 |
qr|Fake send_or_die|, |
1033 |
"SendQueuedMessages is using the mocked send_or_die routine"; |
1034 |
|
1035 |
$message = $schema->resultset('MessageQueue')->search( |
1036 |
{ |
1037 |
borrowernumber => $borrowernumber, |
1038 |
status => 'sent' |
1039 |
} |
1040 |
)->next(); |
1041 |
|
1042 |
is( |
1043 |
$message->to_address(), |
1044 |
$patron->email, |
1045 |
'SendQueuedMessages uses patron email when defined' |
1046 |
); |
1047 |
|
1048 |
is( |
1049 |
$message->cc_address(), |
1050 |
$guarantor1->email.",".$guarantor2->email, |
1051 |
'SendQueuedMessages sets cc address to both guarantor emails when patron has email defined' |
1052 |
); |
1053 |
|
1054 |
is( $email_object->email->header('To'), $patron->email, "mailto correctly uses patrons email address" ); |
1055 |
is( $email_object->email->header('Cc'), $guarantor1->email.", ".$guarantor2->email, "cc correctly uses both guarantors" ); |
1019 |
|
1056 |
|
|
|
1057 |
|
1058 |
# reset message - testing explicit to passed to enqueue |
1059 |
Koha::Notice::Messages->find($message_id)->delete; |
1060 |
$my_message->{'to_address'} = 'to@example.com'; |
1020 |
$message_id = C4::Letters::EnqueueLetter($my_message); |
1061 |
$message_id = C4::Letters::EnqueueLetter($my_message); |
|
|
1062 |
|
1021 |
warning_like { C4::Letters::SendQueuedMessages(); } |
1063 |
warning_like { C4::Letters::SendQueuedMessages(); } |
1022 |
qr|No 'to_address', email address or guarantors email address for borrowernumber|, |
1064 |
qr|Fake send_or_die|, |
1023 |
"SendQueuedMessages fails when no to_address, patron notice email and RedirectGuaranteeEmail is not set"; |
1065 |
"SendQueuedMessages is using the mocked send_or_die routine"; |
|
|
1066 |
|
1067 |
$message = $schema->resultset('MessageQueue')->search( |
1068 |
{ |
1069 |
borrowernumber => $borrowernumber, |
1070 |
status => 'sent' |
1071 |
} |
1072 |
)->next(); |
1073 |
|
1074 |
is( |
1075 |
$message->to_address(), |
1076 |
'to@example.com', |
1077 |
'SendQueuedMessages uses to_address if it was specified at enqueue time' |
1078 |
); |
1079 |
|
1080 |
is( |
1081 |
$message->cc_address(), |
1082 |
$guarantor1->email.",".$guarantor2->email, |
1083 |
'SendQueuedMessages sets cc address to both guarantor emails when "to" is already specified' |
1084 |
); |
1085 |
|
1086 |
is( $email_object->email->header('To'), 'to@example.com', "mailto correctly uses passed email" ); |
1087 |
is( $email_object->email->header('Cc'), $guarantor1->email.", ".$guarantor2->email, "cc correctly uses both guarantors" ); |
1024 |
|
1088 |
|
1025 |
# clear borrower queue |
1089 |
# clear borrower queue |
1026 |
Koha::Notice::Messages->find($message_id)->delete; |
1090 |
Koha::Notice::Messages->find($message_id)->delete; |
1027 |
- |
|
|