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