Lines 715-721
subtest 'Backend core methods' => sub {
Link Here
|
715 |
|
715 |
|
716 |
subtest 'Helpers' => sub { |
716 |
subtest 'Helpers' => sub { |
717 |
|
717 |
|
718 |
plan tests => 21; |
718 |
plan tests => 20; |
719 |
|
719 |
|
720 |
$schema->storage->txn_begin; |
720 |
$schema->storage->txn_begin; |
721 |
|
721 |
|
Lines 817-878
subtest 'Helpers' => sub {
Link Here
|
817 |
"Correct error when missing type" |
817 |
"Correct error when missing type" |
818 |
); |
818 |
); |
819 |
|
819 |
|
820 |
#get_staff_to_address |
|
|
821 |
# Mock a KohaAdminEmailAddress syspref |
822 |
t::lib::Mocks::mock_preference( |
823 |
'KohaAdminEmailAddress', |
824 |
'kohaadmin@nowhere.com' |
825 |
); |
826 |
# No branch addresses defined and no ILLDefaultStaffEmail, so should |
827 |
# fall back to Koha admin address |
828 |
my $email_kohaadmin = $illrq_obj->get_staff_to_address; |
829 |
ok( |
830 |
$email_kohaadmin eq 'kohaadmin@nowhere.com', |
831 |
'get_staff_to_address falls back to Koha admin in the absence of other alternatives' |
832 |
); |
833 |
# General branch address defined, should fall back to that |
834 |
$builder->delete({ source => 'Branch', records => $illbrn }); |
835 |
$illbrn = $builder->build({ |
836 |
source => 'Branch', |
837 |
value => { |
838 |
branchcode => 'HDE', |
839 |
branchemail => 'branch@nowhere.com', |
840 |
branchillemail => "", |
841 |
branchreplyto => "" |
842 |
} |
843 |
}); |
844 |
my $email_gen_branch = $illrq_obj->get_staff_to_address; |
845 |
ok( |
846 |
$email_gen_branch eq 'branch@nowhere.com', |
847 |
'get_staff_to_address falls back to general branch address when defined' |
848 |
); |
849 |
# ILL staff syspref address defined, should fall back to that |
850 |
t::lib::Mocks::mock_preference( |
851 |
'ILLDefaultStaffEmail', |
852 |
'illstaff@nowhere.com' |
853 |
); |
854 |
my $email_syspref = $illrq_obj->get_staff_to_address; |
855 |
ok( |
856 |
$email_syspref eq 'illstaff@nowhere.com', |
857 |
'get_staff_to_address falls back to ILLDefaultStaffEmail when defined' |
858 |
); |
859 |
# Branch ILL address defined, should use that |
860 |
$builder->delete({ source => 'Branch', records => $illbrn }); |
861 |
$illbrn = $builder->build({ |
862 |
source => 'Branch', |
863 |
value => { |
864 |
branchcode => 'HDE', |
865 |
branchemail => 'branch@nowhere.com', |
866 |
branchillemail => 'branchill@nowhere.com', |
867 |
branchreplyto => "" |
868 |
} |
869 |
}); |
870 |
my $email_branch = $illrq_obj->get_staff_to_address; |
871 |
ok( |
872 |
$email_branch eq 'branchill@nowhere.com', |
873 |
'get_staff_to_address uses branch ILL address when defined' |
874 |
); |
875 |
|
876 |
#send_staff_notice |
820 |
#send_staff_notice |
877 |
# Specify that no staff notices should be send |
821 |
# Specify that no staff notices should be send |
878 |
t::lib::Mocks::mock_preference('ILLSendStaffNotices', ''); |
822 |
t::lib::Mocks::mock_preference('ILLSendStaffNotices', ''); |
Lines 883-903
subtest 'Helpers' => sub {
Link Here
|
883 |
{ error => 'notice_not_enabled' }, |
827 |
{ error => 'notice_not_enabled' }, |
884 |
"Does not send notices that are not enabled" |
828 |
"Does not send notices that are not enabled" |
885 |
); |
829 |
); |
|
|
830 |
my $queue = $schema->resultset('MessageQueue')->search({ |
831 |
letter_code => 'ILL_REQUEST_CANCEL' |
832 |
}); |
833 |
is($queue->count, 0, "Notice is not queued"); |
834 |
|
886 |
# Specify that the cancel notice can be sent |
835 |
# Specify that the cancel notice can be sent |
887 |
t::lib::Mocks::mock_preference('ILLSendStaffNotices', 'ILL_REQUEST_CANCEL'); |
836 |
t::lib::Mocks::mock_preference('ILLSendStaffNotices', 'ILL_REQUEST_CANCEL'); |
888 |
my $return_staff_cancel = $illrq_obj->send_staff_notice( |
837 |
my $return_staff_cancel = $illrq_obj->send_staff_notice( |
889 |
'ILL_REQUEST_CANCEL' |
838 |
'ILL_REQUEST_CANCEL' |
890 |
); |
839 |
); |
891 |
my $cancel = $schema->resultset('MessageQueue')->search({ |
|
|
892 |
letter_code => 'ILL_REQUEST_CANCEL', |
893 |
message_transport_type => 'email', |
894 |
to_address => 'branchill@nowhere.com' |
895 |
})->next()->letter_code; |
896 |
is_deeply( |
840 |
is_deeply( |
897 |
$return_staff_cancel, |
841 |
$return_staff_cancel, |
898 |
{ success => 'notice_queued' }, |
842 |
{ success => 'notice_queued' }, |
899 |
"Correct return when staff notice created" |
843 |
"Correct return when staff notice created" |
900 |
); |
844 |
); |
|
|
845 |
$queue = $schema->resultset('MessageQueue')->search({ |
846 |
letter_code => 'ILL_REQUEST_CANCEL' |
847 |
}); |
848 |
is($queue->count, 1, "Notice queued as expected"); |
901 |
|
849 |
|
902 |
my $return_staff_fail = $illrq_obj->send_staff_notice(); |
850 |
my $return_staff_fail = $illrq_obj->send_staff_notice(); |
903 |
is_deeply( |
851 |
is_deeply( |
Lines 905-910
subtest 'Helpers' => sub {
Link Here
|
905 |
{ error => 'notice_no_type' }, |
853 |
{ error => 'notice_no_type' }, |
906 |
"Correct error when missing type" |
854 |
"Correct error when missing type" |
907 |
); |
855 |
); |
|
|
856 |
$queue = $schema->resultset('MessageQueue')->search({ |
857 |
letter_code => 'ILL_REQUEST_CANCEL' |
858 |
}); |
859 |
is($queue->count, 1, "Notice is not queued"); |
908 |
|
860 |
|
909 |
#get_notice |
861 |
#get_notice |
910 |
my $not = $illrq_obj->get_notice({ |
862 |
my $not = $illrq_obj->get_notice({ |