From 941ecba35c5d806b922e8a8bfd349446a7eac4f1 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 Signed-off-by: Victor Grousset/tuxayo --- t/db_dependent/Reserves.t | 132 +++++++++++++++++++++++++++++++++++++- 1 file changed, 131 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 9616d8f160..644ccfdfd4 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -923,7 +923,7 @@ subtest 'ChargeReserveFee tests' => sub { }; subtest 'reserves.item_level_hold' => sub { - plan tests => 2; + plan tests => 4; my $item = $builder->build_sample_item; my $patron = $builder->build_object( @@ -991,6 +991,136 @@ 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, + $item, + ); + + 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, + $item, + ); + + is( $canreserve->{status}, 'recordHoldsOnly', + '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, + $item, + ); + + is( $canreserve->{status}, 'OK', + 'item-level holds should be possible with opacitemholds set to "Yes"' ); + }; + + subtest 'test opacitemholds rules in staff context' => sub { + plan tests => 2; + + C4::Context->interface('intranet'); + Koha::CirculationRules->set_rules( + { + branchcode => undef, + categorycode => undef, + itemtype => undef, + rules => { + reservesallowed => 25, + opacitemholds => 'N', + } + } + ); + + my $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, + $item); + + is( $canreserve->{status}, 'OK', + 'item-level holds should still be possible in staff context, even with opacitemholds set to "No"' ); + }; + + Koha::CirculationRules->set_rules( + { + branchcode => undef, + categorycode => undef, + itemtype => undef, + rules => { + opacitemholds => undef, + } + } + ); }; subtest 'MoveReserve additional test' => sub { -- 2.30.2