From 2cf25085ac8bfd3efe0316b76873dbed1f193f69 Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Wed, 17 Jun 2020 23:36:27 +0200 Subject: [PATCH] Bug 25408: Added unit tests for opacitemholds policy --- t/db_dependent/Reserves.t | 90 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index e9f1de6f86..84c02599a0 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -921,7 +921,7 @@ subtest 'ChargeReserveFee tests' => sub { }; subtest 'reserves.item_level_hold' => sub { - plan tests => 2; + plan tests => 3; my $item = $builder->build_sample_item; my $patron = $builder->build_object( @@ -989,6 +989,94 @@ subtest 'reserves.item_level_hold' => sub { $hold->delete; }; + subtest 'test opacitemholds rules' => sub { + plan tests => 6; + + Koha::CirculationRules->set_rules( + { + branchcode => undef, + categorycode => undef, + itemtype => undef, + rules => { + reservesallowed => 25, + opacitemholds => 'F', + } + } + ); + + my $canreserve = C4::Reserves::CanBookBeReserved( + $patron->borrowernumber, + $item->biblionumber, + ); + + is( $canreserve->{status}, + 'RecordHoldNotAllowed', + 'record-level holds should not be possible with opacitemholds set to "Force"' ); + + $canreserve = C4::Reserves::CanItemBeReserved( + $patron->borrowernumber, + $item->itemnumber, + ); + + is( $canreserve->{status}, 'OK', + 'item-level holds should be possible with opacitemholds set to "Force"' ); + + Koha::CirculationRules->set_rules( + { + branchcode => undef, + categorycode => undef, + itemtype => undef, + rules => { + reservesallowed => 25, + opacitemholds => 'N', + } + } + ); + + $canreserve = C4::Reserves::CanBookBeReserved( + $patron->borrowernumber, + $item->biblionumber, + ); + + is( $canreserve->{status}, 'OK', + 'record-level holds should be possible with opacitemholds set to "No"' ); + + $canreserve = C4::Reserves::CanItemBeReserved( + $patron->borrowernumber, + $item->itemnumber, + ); + + is( $canreserve->{status}, 'notReservable', + 'item-level holds should not be possible with opacitemholds set to "No"' ); + + Koha::CirculationRules->set_rules( + { + branchcode => undef, + categorycode => undef, + itemtype => undef, + rules => { + reservesallowed => 25, + opacitemholds => 'Y', + } + } + ); + + $canreserve = C4::Reserves::CanBookBeReserved( + $patron->borrowernumber, + $item->biblionumber, + ); + + is( $canreserve->{status}, 'OK', + 'record-level holds should be possible with opacitemholds set to "Yes"' ); + + $canreserve = C4::Reserves::CanItemBeReserved( + $patron->borrowernumber, + $item->itemnumber, + ); + + is( $canreserve->{status}, 'OK', + 'item-level holds should be possible with opacitemholds set to "Yes"' ); + }; }; subtest 'MoveReserve additional test' => sub { -- 2.11.0