|
Lines 29-34
use Koha::Patrons;
Link Here
|
| 29 |
use Koha::ItemTypes; |
29 |
use Koha::ItemTypes; |
| 30 |
use Koha::Items; |
30 |
use Koha::Items; |
| 31 |
use Koha::Libraries; |
31 |
use Koha::Libraries; |
|
|
32 |
use Koha::MessageAttributes; |
| 33 |
use Koha::MessageAttribute; |
| 34 |
use Koha::Notice::Templates; |
| 32 |
use Koha::AuthorisedValueCategories; |
35 |
use Koha::AuthorisedValueCategories; |
| 33 |
use Koha::AuthorisedValues; |
36 |
use Koha::AuthorisedValues; |
| 34 |
use t::lib::Mocks; |
37 |
use t::lib::Mocks; |
|
Lines 515-521
subtest 'Backend testing (mocks)' => sub {
Link Here
|
| 515 |
|
518 |
|
| 516 |
subtest 'Backend core methods' => sub { |
519 |
subtest 'Backend core methods' => sub { |
| 517 |
|
520 |
|
| 518 |
plan tests => 19; |
521 |
plan tests => 18; |
| 519 |
|
522 |
|
| 520 |
$schema->storage->txn_begin; |
523 |
$schema->storage->txn_begin; |
| 521 |
|
524 |
|
|
Lines 706-725
subtest 'Backend core methods' => sub {
Link Here
|
| 706 |
}) } |
709 |
}) } |
| 707 |
"Generic confirm: missing to dies OK."; |
710 |
"Generic confirm: missing to dies OK."; |
| 708 |
|
711 |
|
| 709 |
dies_ok { $illrq->generic_confirm({ |
|
|
| 710 |
current_branchcode => $illbrn->{branchcode}, |
| 711 |
partners => $partner1->{email}, |
| 712 |
stage => 'draft' |
| 713 |
}) } |
| 714 |
"Generic confirm: missing from dies OK."; |
| 715 |
|
| 716 |
$schema->storage->txn_rollback; |
712 |
$schema->storage->txn_rollback; |
| 717 |
}; |
713 |
}; |
| 718 |
|
714 |
|
| 719 |
|
715 |
|
| 720 |
subtest 'Helpers' => sub { |
716 |
subtest 'Helpers' => sub { |
| 721 |
|
717 |
|
| 722 |
plan tests => 7; |
718 |
plan tests => 21; |
| 723 |
|
719 |
|
| 724 |
$schema->storage->txn_begin; |
720 |
$schema->storage->txn_begin; |
| 725 |
|
721 |
|
|
Lines 727-732
subtest 'Helpers' => sub {
Link Here
|
| 727 |
my $backend = Test::MockObject->new; |
723 |
my $backend = Test::MockObject->new; |
| 728 |
$backend->set_isa('Koha::Illbackends::Mock'); |
724 |
$backend->set_isa('Koha::Illbackends::Mock'); |
| 729 |
$backend->set_always('name', 'Mock'); |
725 |
$backend->set_always('name', 'Mock'); |
|
|
726 |
$backend->mock( |
| 727 |
'metadata', |
| 728 |
sub { |
| 729 |
my ( $self, $rq ) = @_; |
| 730 |
return { |
| 731 |
title => 'mytitle', |
| 732 |
author => 'myauthor' |
| 733 |
} |
| 734 |
} |
| 735 |
); |
| 730 |
|
736 |
|
| 731 |
my $config = Test::MockObject->new; |
737 |
my $config = Test::MockObject->new; |
| 732 |
$config->set_always('backend_dir', "/tmp"); |
738 |
$config->set_always('backend_dir', "/tmp"); |
|
Lines 735-743
subtest 'Helpers' => sub {
Link Here
|
| 735 |
source => 'Borrower', |
741 |
source => 'Borrower', |
| 736 |
value => { categorycode => "A" } |
742 |
value => { categorycode => "A" } |
| 737 |
}); |
743 |
}); |
|
|
744 |
# Create a mocked branch with no email addressed defined |
| 745 |
my $illbrn = $builder->build({ |
| 746 |
source => 'Branch', |
| 747 |
value => { |
| 748 |
branchcode => 'HDE', |
| 749 |
branchemail => "", |
| 750 |
branchillemail => "", |
| 751 |
branchreplyto => "" |
| 752 |
} |
| 753 |
}); |
| 738 |
my $illrq = $builder->build({ |
754 |
my $illrq = $builder->build({ |
| 739 |
source => 'Illrequest', |
755 |
source => 'Illrequest', |
| 740 |
value => { branchcode => "CPL", borrowernumber => $patron->{borrowernumber} } |
756 |
value => { branchcode => "HDE", borrowernumber => $patron->{borrowernumber} } |
| 741 |
}); |
757 |
}); |
| 742 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
758 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
| 743 |
$illrq_obj->_config($config); |
759 |
$illrq_obj->_config($config); |
|
Lines 745-756
subtest 'Helpers' => sub {
Link Here
|
| 745 |
|
761 |
|
| 746 |
# getPrefix |
762 |
# getPrefix |
| 747 |
$config->set_series('getPrefixes', |
763 |
$config->set_series('getPrefixes', |
| 748 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
764 |
{ HDE => "TEST", TSL => "BAR", default => "DEFAULT" }, |
| 749 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
765 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
| 750 |
is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "CPL" }), "TEST", |
766 |
is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "HDE" }), "TEST", |
| 751 |
"getPrefix: branch"); |
767 |
"getPrefix: branch"); |
| 752 |
$config->set_series('getPrefixes', |
768 |
$config->set_series('getPrefixes', |
| 753 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
769 |
{ HDE => "TEST", TSL => "BAR", default => "DEFAULT" }, |
| 754 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
770 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
| 755 |
is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "", |
771 |
is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "", |
| 756 |
"getPrefix: default"); |
772 |
"getPrefix: default"); |
|
Lines 760-770
subtest 'Helpers' => sub {
Link Here
|
| 760 |
|
776 |
|
| 761 |
# id_prefix |
777 |
# id_prefix |
| 762 |
$config->set_series('getPrefixes', |
778 |
$config->set_series('getPrefixes', |
| 763 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
779 |
{ HDE => "TEST", TSL => "BAR", default => "DEFAULT" }, |
| 764 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
780 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
| 765 |
is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch"); |
781 |
is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch"); |
| 766 |
$config->set_series('getPrefixes', |
782 |
$config->set_series('getPrefixes', |
| 767 |
{ CPLT => "TEST", TSLT => "BAR", default => "DEFAULT" }, |
783 |
{ HDET => "TEST", TSLT => "BAR", default => "DEFAULT" }, |
| 768 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
784 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
| 769 |
is($illrq_obj->id_prefix, "", "id_prefix: default"); |
785 |
is($illrq_obj->id_prefix, "", "id_prefix: default"); |
| 770 |
|
786 |
|
|
Lines 774-779
subtest 'Helpers' => sub {
Link Here
|
| 774 |
$illrq_obj->status('CANCREQ')->store; |
790 |
$illrq_obj->status('CANCREQ')->store; |
| 775 |
is($illrq_obj->requires_moderation, 'CANCREQ', "requires_moderation: Yes."); |
791 |
is($illrq_obj->requires_moderation, 'CANCREQ', "requires_moderation: Yes."); |
| 776 |
|
792 |
|
|
|
793 |
#send_patron_notice |
| 794 |
my $attr = Koha::MessageAttributes->find({ message_name => 'Ill_ready' }); |
| 795 |
C4::Members::Messaging::SetMessagingPreference({ |
| 796 |
borrowernumber => $patron->{borrowernumber}, |
| 797 |
message_attribute_id => $attr->message_attribute_id, |
| 798 |
message_transport_types => ['email'] |
| 799 |
}); |
| 800 |
my $return_patron = $illrq_obj->send_patron_notice('ILL_PICKUP_READY'); |
| 801 |
my $notice = $schema->resultset('MessageQueue')->search({ |
| 802 |
letter_code => 'ILL_PICKUP_READY', |
| 803 |
message_transport_type => 'email', |
| 804 |
borrowernumber => $illrq_obj->borrowernumber |
| 805 |
})->next()->letter_code; |
| 806 |
is_deeply( |
| 807 |
$return_patron, |
| 808 |
{ result => { success => ['email'], fail => [] } }, |
| 809 |
"Correct return when notice created" |
| 810 |
); |
| 811 |
is($notice, 'ILL_PICKUP_READY' ,"Notice is correctly created"); |
| 812 |
|
| 813 |
my $return_patron_fail = $illrq_obj->send_patron_notice(); |
| 814 |
is_deeply( |
| 815 |
$return_patron_fail, |
| 816 |
{ error => 'notice_no_type' }, |
| 817 |
"Correct error when missing type" |
| 818 |
); |
| 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 |
| 877 |
# Specify that no staff notices should be send |
| 878 |
t::lib::Mocks::mock_preference('ILLSendStaffNotices', ''); |
| 879 |
my $return_staff_cancel_fail = |
| 880 |
$illrq_obj->send_staff_notice('ILL_REQUEST_CANCEL'); |
| 881 |
is_deeply( |
| 882 |
$return_staff_cancel_fail, |
| 883 |
{ error => 'notice_not_enabled' }, |
| 884 |
"Does not send notices that are not enabled" |
| 885 |
); |
| 886 |
# Specify that the cancel notice can be sent |
| 887 |
t::lib::Mocks::mock_preference('ILLSendStaffNotices', 'ILL_REQUEST_CANCEL'); |
| 888 |
my $return_staff_cancel = $illrq_obj->send_staff_notice( |
| 889 |
'ILL_REQUEST_CANCEL' |
| 890 |
); |
| 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( |
| 897 |
$return_staff_cancel, |
| 898 |
{ success => 'notice_queued' }, |
| 899 |
"Correct return when staff notice created" |
| 900 |
); |
| 901 |
|
| 902 |
my $return_staff_fail = $illrq_obj->send_staff_notice(); |
| 903 |
is_deeply( |
| 904 |
$return_staff_fail, |
| 905 |
{ error => 'notice_no_type' }, |
| 906 |
"Correct error when missing type" |
| 907 |
); |
| 908 |
|
| 909 |
#get_notice |
| 910 |
my $not = $illrq_obj->get_notice({ |
| 911 |
notice_code => 'ILL_REQUEST_CANCEL', |
| 912 |
transport => 'email' |
| 913 |
}); |
| 914 |
|
| 915 |
# We test the properties of the hashref separately because the random |
| 916 |
# hash ordering of the metadata means we can't test the entire thing |
| 917 |
# with is_deeply |
| 918 |
ok( |
| 919 |
$not->{module} eq 'ill', |
| 920 |
'Correct module return from get_notice' |
| 921 |
); |
| 922 |
ok( |
| 923 |
$not->{name} eq 'ILL request cancelled', |
| 924 |
'Correct name return from get_notice' |
| 925 |
); |
| 926 |
ok( |
| 927 |
$not->{message_transport_type} eq 'email', |
| 928 |
'Correct message_transport_type return from get_notice' |
| 929 |
); |
| 930 |
ok( |
| 931 |
$not->{title} eq 'Interlibrary loan request cancelled', |
| 932 |
'Correct title return from get_notice' |
| 933 |
); |
| 934 |
|
| 777 |
$schema->storage->txn_rollback; |
935 |
$schema->storage->txn_rollback; |
| 778 |
}; |
936 |
}; |
| 779 |
|
937 |
|
| 780 |
- |
|
|