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 => 90; |
21 |
use Test::More tests => 91; |
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 869-875
subtest 'Test SMS handling in SendQueuedMessages' => sub {
Link Here
|
869 |
t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' ); |
869 |
t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' ); |
870 |
t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', ''); |
870 |
t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', ''); |
871 |
|
871 |
|
872 |
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '0' ); |
|
|
873 |
my $patron = Koha::Patrons->find($borrowernumber); |
872 |
my $patron = Koha::Patrons->find($borrowernumber); |
874 |
$dbh->do(q| |
873 |
$dbh->do(q| |
875 |
INSERT INTO message_queue(borrowernumber, subject, content, message_transport_type, status, letter_code) |
874 |
INSERT INTO message_queue(borrowernumber, subject, content, message_transport_type, status, letter_code) |
Lines 953-958
subtest 'Test SMS handling in SendQueuedMessages' => sub {
Link Here
|
953 |
})->next()->to_address(); |
952 |
})->next()->to_address(); |
954 |
is( $sms_message_address, '5555555555', 'SendQueuedMessages populates the to address correctly for SMS by SMS::Send driver to smsalertnumber when to_address is set incorrectly' ); |
953 |
is( $sms_message_address, '5555555555', 'SendQueuedMessages populates the to address correctly for SMS by SMS::Send driver to smsalertnumber when to_address is set incorrectly' ); |
955 |
|
954 |
|
|
|
955 |
$schema->resultset('MessageQueue')->search({borrowernumber => $borrowernumber, status => 'sent'})->delete(); #clear borrower queue |
956 |
}; |
957 |
|
958 |
subtest 'Test guarantor handling in SendQueuedMessages' => sub { |
959 |
|
960 |
plan tests => 8; |
961 |
|
962 |
t::lib::Mocks::mock_preference( 'borrowerRelationship', 'test' ); |
963 |
|
964 |
my $patron = Koha::Patrons->find($borrowernumber); |
965 |
my $guarantor1 = $builder->build_object( { class => 'Koha::Patrons', value => { email => 'g1@email.com' } } ); |
966 |
my $guarantor2 = $builder->build_object( { class => 'Koha::Patrons', value => { email => 'g2@email.com' } } ); |
967 |
$patron->add_guarantor( { guarantor_id => $guarantor1->borrowernumber, relationship => 'test' } ); |
968 |
$patron->add_guarantor( { guarantor_id => $guarantor2->borrowernumber, relationship => 'test' } ); |
969 |
|
970 |
$my_message = { |
971 |
'letter' => { |
972 |
'content' => 'a message', |
973 |
'metadata' => 'metadata', |
974 |
'code' => 'TEST_MESSAGE', |
975 |
'content_type' => 'text/plain', |
976 |
'title' => 'message title' |
977 |
}, |
978 |
'borrowernumber' => $borrowernumber, |
979 |
'to_address' => undef, |
980 |
'message_transport_type' => 'email', |
981 |
'from_address' => 'from@example.com' |
982 |
}; |
983 |
$message_id = C4::Letters::EnqueueLetter($my_message); |
984 |
|
985 |
# feature enabled |
986 |
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '1' ); |
987 |
|
988 |
warning_like { C4::Letters::SendQueuedMessages(); } |
989 |
qr|Fake send_or_die|, |
990 |
"SendQueuedMessages is using the mocked send_or_die routine"; |
991 |
|
992 |
$message = $schema->resultset('MessageQueue')->search( |
993 |
{ |
994 |
borrowernumber => $borrowernumber, |
995 |
status => 'sent' |
996 |
} |
997 |
)->next(); |
998 |
|
999 |
is( |
1000 |
$message->to_address(), |
1001 |
$guarantor1->email, |
1002 |
'SendQueuedMessages uses first guarantor email for "to" when patron has no email' |
1003 |
); |
1004 |
|
1005 |
is( |
1006 |
$message->cc_address(), |
1007 |
$guarantor2->email, |
1008 |
'SendQueuedMessages sets cc address to second guarantor email when "to" takes first guarantor email' |
1009 |
); |
1010 |
|
1011 |
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" ); |
1013 |
|
1014 |
# feature disabled |
1015 |
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '0' ); #FIXME: This mock is failing!? |
1016 |
|
1017 |
# reset message |
1018 |
$schema->resultset('MessageQueue')->search( { borrowernumber => $borrowernumber, status => 'sent' } ) |
1019 |
->update( { status => 'pending', failure_code => undef } ); |
1020 |
|
1021 |
warning_like { C4::Letters::SendQueuedMessages(); } |
1022 |
qr|No 'to_address', email address or guarantors email address for borrowernumber|, |
1023 |
"SendQueuedMessages fails when no to_address, patron notice email and RedirectGuaranteeEmail is not set"; |
1024 |
|
1025 |
# clear borrower queue |
1026 |
$schema->resultset('MessageQueue')->search( { borrowernumber => $borrowernumber, status => 'sent' } )->delete(); |
956 |
}; |
1027 |
}; |
957 |
|
1028 |
|
958 |
subtest 'get_item_content' => sub { |
1029 |
subtest 'get_item_content' => sub { |
959 |
- |
|
|