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