@@ -, +, @@ --- t/db_dependent/Reserves/HoldRulesChecker.t | 130 +++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 t/db_dependent/Reserves/HoldRulesChecker.t --- a/t/db_dependent/Reserves/HoldRulesChecker.t +++ a/t/db_dependent/Reserves/HoldRulesChecker.t @@ -0,0 +1,130 @@ +#!/usr/bin/perl + +# Copyright 2019 Biblibre +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Test::More tests => 11; +use t::lib::TestBuilder; + +use C4::Reserves qw( CanBookBeReserved ); + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new(); +my $library = $builder->build( + { + source => 'Branch', + } +); + +my $category = $builder->build( + { + source => 'Category', + } +); +my $patron = $builder->build( + { + source => 'Borrower', + value => { + categorycode => $category->{categorycode}, + branchcode => $library->{branchcode}, + }, + } +); + +my $itemtype1 = $builder->build( + { + source => 'Itemtype' + } +); + +my $biblio = $builder->build( + { + source => 'Biblio', + value => { + title => 'Title 1', + }, + } +); +my $biblioitem = $builder->build( + { + source => 'Biblioitem', + value => { biblionumber => $biblio->{biblionumber} } + } +); +my $item1 = $builder->build( + { + source => 'Item', + value => { + biblionumber => $biblio->{biblionumber}, + itype => $itemtype1->{itemtype}, + homebranch => $library->{branchcode}, + holdingbranch => $library->{branchcode}, + damaged => 0, + }, + } +); + +my $rules_rs = Koha::Database->new()->schema()->resultset('Issuingrule'); +$rules_rs->delete(); + +my $rule1 = $rules_rs->new( + { + categorycode => '*', + itemtype => '*', + branchcode => '*', + reservesallowed => 1, + holds_per_record => 1, + } +)->insert(); + +my $can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber}); + +is($can->{issuingrule}{reservesallowed}, 1, 'Matched rule #1 says 1 reserve allowed'); +is($can->{issuingrule}{holds_per_record}, 1, 'Matched rule #1 says 1 reserve per record allowed'); +is($can->{issuingrule}{itemtype}, '*', 'Matched rule is for all item types'); +is($can->{issuingrule}{categorycode}, '*', 'Matched rule is for all patron categories'); +is($can->{issuingrule}{branchcode}, '*', 'Matched rule is for all branches'); + +is($can->{circulation_rule}, undef, 'No rule matched for holds policy'); + +my $rule2 = $rules_rs->new( + { + categorycode => $patron->{categorycode}, + itemtype => '*', + branchcode => $library->{branchcode}, + reservesallowed => 5, + holds_per_record => 2, + } +)->insert(); + +$can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber}); + +is($can->{issuingrule}{reservesallowed}, 5, 'Matched rule #2 says 5 reserve allowed'); +is($can->{issuingrule}{holds_per_record}, 2, 'Matched rule #2 says 2 reserve per record allowed'); + +Koha::CirculationRules->set_rule({ branchcode => $library->{branchcode}, categorycode => $patron->{categorycode}, itemtype => undef, rule_name => 'max_holds', rule_value => '10'}); + +$can = CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber}); +is($can->{circulation_rule}->branchcode, $library->{branchcode}); +is($can->{circulation_rule}->categorycode, $patron->{categorycode}); +is($can->{circulation_rule}->rule_value, 10); + +$schema->storage->txn_rollback; --