| Line 0
          
      
      
        Link Here | 
          
            
              | 0 | -  | 1 | #!/usr/bin/perl | 
            
              |  |  | 2 |  | 
            
              | 3 | # Copyright 2019 Biblibre | 
            
              | 4 | # | 
            
              | 5 | # This file is part of Koha. | 
            
              | 6 | # | 
            
              | 7 | # Koha is free software; you can redistribute it and/or modify it | 
            
              | 8 | # under the terms of the GNU General Public License as published by | 
            
              | 9 | # the Free Software Foundation; either version 3 of the License, or | 
            
              | 10 | # (at your option) any later version. | 
            
              | 11 | # | 
            
              | 12 | # Koha is distributed in the hope that it will be useful, but | 
            
              | 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
              | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
            
              | 15 | # GNU General Public License for more details. | 
            
              | 16 | # | 
            
              | 17 | # You should have received a copy of the GNU General Public License | 
            
              | 18 | # along with Koha; if not, see <http://www.gnu.org/licenses>. | 
            
              | 19 |  | 
            
              | 20 | use Modern::Perl; | 
            
              | 21 |  | 
            
              | 22 | use Test::More tests => 11; | 
            
              | 23 | use t::lib::TestBuilder; | 
            
              | 24 |  | 
            
              | 25 | use C4::Reserves qw( CanBookBeReserved ); | 
            
              | 26 |  | 
            
              | 27 | my $schema = Koha::Database->new->schema; | 
            
              | 28 | $schema->storage->txn_begin; | 
            
              | 29 |  | 
            
              | 30 | my $builder = t::lib::TestBuilder->new(); | 
            
              | 31 | my $library = $builder->build( | 
            
              | 32 |     { | 
            
              | 33 |         source => 'Branch', | 
            
              | 34 |     } | 
            
              | 35 | ); | 
            
              | 36 |  | 
            
              | 37 | my $category = $builder->build( | 
            
              | 38 |     { | 
            
              | 39 |         source => 'Category', | 
            
              | 40 |     } | 
            
              | 41 | ); | 
            
              | 42 | my $patron = $builder->build( | 
            
              | 43 |     { | 
            
              | 44 |         source => 'Borrower', | 
            
              | 45 |         value  => { | 
            
              | 46 |             categorycode => $category->{categorycode}, | 
            
              | 47 |             branchcode   => $library->{branchcode}, | 
            
              | 48 |         }, | 
            
              | 49 |     } | 
            
              | 50 | ); | 
            
              | 51 |  | 
            
              | 52 | my $itemtype1 = $builder->build( | 
            
              | 53 |     { | 
            
              | 54 |         source => 'Itemtype' | 
            
              | 55 |     } | 
            
              | 56 | ); | 
            
              | 57 |  | 
            
              | 58 | my $biblio = $builder->build( | 
            
              | 59 |     { | 
            
              | 60 |         source => 'Biblio', | 
            
              | 61 |         value  => { | 
            
              | 62 |             title => 'Title 1', | 
            
              | 63 |         }, | 
            
              | 64 |     } | 
            
              | 65 | ); | 
            
              | 66 | my $biblioitem = $builder->build( | 
            
              | 67 |     { | 
            
              | 68 |         source => 'Biblioitem', | 
            
              | 69 |         value  => { biblionumber => $biblio->{biblionumber} } | 
            
              | 70 |     } | 
            
              | 71 | ); | 
            
              | 72 | my $item1 = $builder->build( | 
            
              | 73 |     { | 
            
              | 74 |         source => 'Item', | 
            
              | 75 |         value  => { | 
            
              | 76 |             biblionumber  => $biblio->{biblionumber}, | 
            
              | 77 |             itype         => $itemtype1->{itemtype}, | 
            
              | 78 |             homebranch    => $library->{branchcode}, | 
            
              | 79 |             holdingbranch => $library->{branchcode}, | 
            
              | 80 |             damaged       => 0, | 
            
              | 81 |         }, | 
            
              | 82 |     } | 
            
              | 83 | ); | 
            
              | 84 |  | 
            
              | 85 | my $rules_rs = Koha::Database->new()->schema()->resultset('Issuingrule'); | 
            
              | 86 | $rules_rs->delete(); | 
            
              | 87 |  | 
            
              | 88 | my $rule1 = $rules_rs->new( | 
            
              | 89 |     { | 
            
              | 90 |         categorycode     => '*', | 
            
              | 91 |         itemtype         => '*', | 
            
              | 92 |         branchcode       => '*', | 
            
              | 93 |         reservesallowed  => 1, | 
            
              | 94 |         holds_per_record => 1, | 
            
              | 95 |     } | 
            
              | 96 | )->insert(); | 
            
              | 97 |  | 
            
              | 98 | my $can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber}); | 
            
              | 99 |  | 
            
              | 100 | is($can->{issuingrule}{reservesallowed}, 1, 'Matched rule #1 says 1 reserve allowed'); | 
            
              | 101 | is($can->{issuingrule}{holds_per_record}, 1, 'Matched rule #1 says 1 reserve per record allowed'); | 
            
              | 102 | is($can->{issuingrule}{itemtype}, '*', 'Matched rule is for all item types'); | 
            
              | 103 | is($can->{issuingrule}{categorycode}, '*', 'Matched rule is for all patron categories'); | 
            
              | 104 | is($can->{issuingrule}{branchcode}, '*', 'Matched rule is for all branches'); | 
            
              | 105 |  | 
            
              | 106 | is($can->{circulation_rule}, undef, 'No rule matched for holds policy'); | 
            
              | 107 |  | 
            
              | 108 | my $rule2 = $rules_rs->new( | 
            
              | 109 |     { | 
            
              | 110 |         categorycode     => $patron->{categorycode}, | 
            
              | 111 |         itemtype         => '*', | 
            
              | 112 |         branchcode       => $library->{branchcode}, | 
            
              | 113 |         reservesallowed  => 5, | 
            
              | 114 |         holds_per_record => 2, | 
            
              | 115 |     } | 
            
              | 116 | )->insert(); | 
            
              | 117 |  | 
            
              | 118 | $can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber}); | 
            
              | 119 |  | 
            
              | 120 | is($can->{issuingrule}{reservesallowed}, 5, 'Matched rule #2 says 5 reserve allowed'); | 
            
              | 121 | is($can->{issuingrule}{holds_per_record}, 2, 'Matched rule #2 says 2 reserve per record allowed'); | 
            
              | 122 |  | 
            
              | 123 | Koha::CirculationRules->set_rule({ branchcode => $library->{branchcode}, categorycode => $patron->{categorycode}, itemtype => undef, rule_name => 'max_holds', rule_value => '10'}); | 
            
              | 124 |  | 
            
              | 125 | $can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber}); | 
            
              | 126 | is($can->{circulation_rule}->branchcode, $library->{branchcode}); | 
            
              | 127 | is($can->{circulation_rule}->categorycode, $patron->{categorycode}); | 
            
              | 128 | is($can->{circulation_rule}->rule_value, 10); | 
            
              | 129 |  | 
            
              | 130 | $schema->storage->txn_rollback; |