| Line 0
          
      
      
        Link Here | 
          
            
              | 0 | -  | 1 | #!/usr/bin/perl | 
            
              |  |  | 2 |  | 
            
              | 3 | # Copyright The National Library of Finland, University of Helsinki 2020 | 
            
              | 4 | # | 
            
              | 5 | # This file is part of Koha. | 
            
              | 6 | # | 
            
              | 7 | # Koha is free software; you can redistribute it and/or modify it under the | 
            
              | 8 | # terms of the GNU General Public License as published by the Free Software | 
            
              | 9 | # Foundation; either version 3 of the License, or (at your option) any later | 
            
              | 10 | # version. | 
            
              | 11 | # | 
            
              | 12 | # Koha is distributed in the hope that it will be useful, but WITHOUT ANY | 
            
              | 13 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | 
            
              | 14 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. | 
            
              | 15 | # | 
            
              | 16 | # You should have received a copy of the GNU General Public License along | 
            
              | 17 | # with Koha; if not, see <http://www.gnu.org/licenses>. | 
            
              | 18 |  | 
            
              | 19 | use Modern::Perl; | 
            
              | 20 |  | 
            
              | 21 | use C4::Context; | 
            
              | 22 | use Koha::CirculationRules; | 
            
              | 23 |  | 
            
              | 24 | use Test::More tests => 10; | 
            
              | 25 |  | 
            
              | 26 | use t::lib::TestBuilder; | 
            
              | 27 | use t::lib::Mocks; | 
            
              | 28 | use Koha::Holds; | 
            
              | 29 |  | 
            
              | 30 | use Koha::Account; | 
            
              | 31 | use Koha::Account::DebitTypes; | 
            
              | 32 |  | 
            
              | 33 | BEGIN { | 
            
              | 34 |     use_ok('C4::Reserves'); | 
            
              | 35 | } | 
            
              | 36 |  | 
            
              | 37 | my $schema = Koha::Database->schema; | 
            
              | 38 | $schema->storage->txn_begin; | 
            
              | 39 | my $dbh = C4::Context->dbh; | 
            
              | 40 |  | 
            
              | 41 | my $builder = t::lib::TestBuilder->new; | 
            
              | 42 |  | 
            
              | 43 | my $library1 = $builder->build({ | 
            
              | 44 |     source => 'Branch', | 
            
              | 45 | }); | 
            
              | 46 |  | 
            
              | 47 | my $bib_title = "Test Title"; | 
            
              | 48 |  | 
            
              | 49 | my $borrower = $builder->build({ | 
            
              | 50 |     source => 'Borrower', | 
            
              | 51 |     value => { | 
            
              | 52 |         branchcode => $library1->{branchcode}, | 
            
              | 53 |     } | 
            
              | 54 | }); | 
            
              | 55 |  | 
            
              | 56 | my $borrowernumber = $borrower->{borrowernumber}; | 
            
              | 57 | my $library_A_code = $library1->{branchcode}; | 
            
              | 58 |  | 
            
              | 59 | my $biblio = $builder->build_sample_biblio({itemtype=>'BK'}); | 
            
              | 60 | my $biblionumber = $biblio->biblionumber; | 
            
              | 61 | my $item1 = $builder->build_sample_item({ | 
            
              | 62 |     biblionumber => $biblionumber, | 
            
              | 63 |     itype => 'CF', | 
            
              | 64 |     homebranch => $library_A_code, | 
            
              | 65 |     holdingbranch => $library_A_code | 
            
              | 66 | }); | 
            
              | 67 | my $item2 = $builder->build_sample_item({ | 
            
              | 68 |     biblionumber => $biblionumber, | 
            
              | 69 |     itype => 'MU', | 
            
              | 70 |     homebranch => $library_A_code, | 
            
              | 71 |     holdingbranch => $library_A_code | 
            
              | 72 | }); | 
            
              | 73 | my $item3 = $builder->build_sample_item({ | 
            
              | 74 |     biblionumber => $biblionumber, | 
            
              | 75 |     itype => 'MX', | 
            
              | 76 |     homebranch => $library_A_code, | 
            
              | 77 |     holdingbranch => $library_A_code | 
            
              | 78 | }); | 
            
              | 79 |  | 
            
              | 80 | $dbh->do("DELETE FROM circulation_rules"); | 
            
              | 81 | Koha::CirculationRules->set_rules( | 
            
              | 82 |     { | 
            
              | 83 |         itemtype     => 'CF', | 
            
              | 84 |         categorycode => undef, | 
            
              | 85 |         branchcode   => undef, | 
            
              | 86 |         rules        => { | 
            
              | 87 |             expire_reserves_charge => '111' | 
            
              | 88 |         } | 
            
              | 89 |     } | 
            
              | 90 | ); | 
            
              | 91 | Koha::CirculationRules->set_rules( | 
            
              | 92 |     { | 
            
              | 93 |         itemtype     => 'MU', | 
            
              | 94 |         categorycode => undef, | 
            
              | 95 |         branchcode   => undef, | 
            
              | 96 |         rules        => { | 
            
              | 97 |             expire_reserves_charge => undef | 
            
              | 98 |         } | 
            
              | 99 |     } | 
            
              | 100 | ); | 
            
              | 101 |  | 
            
              | 102 | my $reserve_id; | 
            
              | 103 | my $account; | 
            
              | 104 | my $status; | 
            
              | 105 | my $start_balance; | 
            
              | 106 |  | 
            
              | 107 | # TEST: Hold Computer File item | 
            
              | 108 | $reserve_id = AddReserve( | 
            
              | 109 |     { | 
            
              | 110 |         branchcode       => $library_A_code, | 
            
              | 111 |         borrowernumber   => $borrowernumber, | 
            
              | 112 |         biblionumber     => $biblionumber, | 
            
              | 113 |         priority         => 1, | 
            
              | 114 |         itemnumber       => $item1->itemnumber, | 
            
              | 115 |     } | 
            
              | 116 | ); | 
            
              | 117 |  | 
            
              | 118 | $account = Koha::Account->new({ patron_id => $borrowernumber }); | 
            
              | 119 |  | 
            
              | 120 | ( $status ) = CheckReserves($item1->id); | 
            
              | 121 | is( $status, 'Reserved', "Hold for the CF created" ); | 
            
              | 122 |  | 
            
              | 123 | $start_balance = $account->balance(); | 
            
              | 124 |  | 
            
              | 125 | Koha::Holds->find( $reserve_id )->cancel({ charge_cancel_fee => 1 }); | 
            
              | 126 |  | 
            
              | 127 | ( $status ) = CheckReserves($item1->id); | 
            
              | 128 | is( $status, '', "Hold for the CF cancelled" ); | 
            
              | 129 |  | 
            
              | 130 | is( $account->balance() - $start_balance, 111, "Account debt is 111" ); | 
            
              | 131 |  | 
            
              | 132 | # TEST: Hold Music item that has 'expire_reserves_charge' set undef | 
            
              | 133 | t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 222); | 
            
              | 134 |  | 
            
              | 135 | $reserve_id = AddReserve( | 
            
              | 136 |     { | 
            
              | 137 |         branchcode       => $library_A_code, | 
            
              | 138 |         borrowernumber   => $borrowernumber, | 
            
              | 139 |         biblionumber     => $biblionumber, | 
            
              | 140 |         priority         => 1, | 
            
              | 141 |         itemnumber       => $item2->itemnumber, | 
            
              | 142 |     } | 
            
              | 143 | ); | 
            
              | 144 |  | 
            
              | 145 | $account = Koha::Account->new({ patron_id => $borrowernumber }); | 
            
              | 146 |  | 
            
              | 147 | ( $status ) = CheckReserves($item2->id); | 
            
              | 148 | is( $status, 'Reserved', "Hold for the MU created" ); | 
            
              | 149 |  | 
            
              | 150 | $start_balance = $account->balance(); | 
            
              | 151 |  | 
            
              | 152 | Koha::Holds->find( $reserve_id )->cancel({ charge_cancel_fee => 1 }); | 
            
              | 153 |  | 
            
              | 154 | ( $status ) = CheckReserves($item2->id); | 
            
              | 155 | is( $status, '', "Hold for the MU cancelled" ); | 
            
              | 156 |  | 
            
              | 157 | is( $account->balance() - $start_balance, 222, "Account debt is 222" ); | 
            
              | 158 |  | 
            
              | 159 | # TEST: Hold MX item that has no circulation rules | 
            
              | 160 | t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 333); | 
            
              | 161 |  | 
            
              | 162 | $reserve_id = AddReserve( | 
            
              | 163 |     { | 
            
              | 164 |         branchcode       => $library_A_code, | 
            
              | 165 |         borrowernumber   => $borrowernumber, | 
            
              | 166 |         biblionumber     => $biblionumber, | 
            
              | 167 |         priority         => 1, | 
            
              | 168 |         itemnumber       => $item3->itemnumber, | 
            
              | 169 |     } | 
            
              | 170 | ); | 
            
              | 171 |  | 
            
              | 172 | $account = Koha::Account->new({ patron_id => $borrowernumber }); | 
            
              | 173 |  | 
            
              | 174 | ( $status ) = CheckReserves($item3->id); | 
            
              | 175 | is( $status, 'Reserved', "Hold for the MX created" ); | 
            
              | 176 |  | 
            
              | 177 | $start_balance = $account->balance(); | 
            
              | 178 |  | 
            
              | 179 | Koha::Holds->find( $reserve_id )->cancel({ charge_cancel_fee => 1 }); | 
            
              | 180 |  | 
            
              | 181 | ( $status ) = CheckReserves($item3->id); | 
            
              | 182 | is( $status, '', "Hold for the MX cancelled" ); | 
            
              | 183 |  | 
            
              | 184 | is( $account->balance() - $start_balance, 333, "Account debt is 333" ); | 
            
              | 185 |  | 
            
              | 186 | $schema->storage->txn_rollback; |