From e0937a16bdacbb2dced192ed715f114fbe776e4f Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 23 Dec 2021 16:49:34 +0000 Subject: [PATCH] Bug 29102: Unit tests --- t/db_dependent/DecreaseLoanHighHolds.t | 56 +++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/DecreaseLoanHighHolds.t b/t/db_dependent/DecreaseLoanHighHolds.t index 8722a5c907..e981e32aee 100755 --- a/t/db_dependent/DecreaseLoanHighHolds.t +++ b/t/db_dependent/DecreaseLoanHighHolds.t @@ -30,7 +30,7 @@ use Koha::CirculationRules; use t::lib::TestBuilder; use t::lib::Mocks; -use Test::More tests => 21; +use Test::More tests => 22; my $dbh = C4::Context->dbh; my $schema = Koha::Database->new()->schema(); @@ -246,4 +246,58 @@ Koha::CirculationRules->set_rule( $data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); is( $data->{duration}, 2, "Circulation rules override system preferences" ); + +subtest "Test patron's own holds do not count towards HighHolds count" => sub { + + plan tests => 2; + + my $item = $builder->build_sample_item(); + my $item2 = $builder->build_sample_item({ biblionumber => $item->biblionumber }); + my $item3 = $builder->build_sample_item({ biblionumber => $item->biblionumber }); + + my $patron = $builder->build_object({ + class => 'Koha::Patrons', + value => { + branchcode => $item->homebranch + } + }); + my $hold = $builder->build_object({ + class => 'Koha::Holds', + value => { + biblionumber => $item->biblionumber, + borrowernumber => $patron->id, + suspend => 0, + found => undef + } + }); + + Koha::CirculationRules->set_rules( + { + branchcode => $item->homebranch, + categorycode => undef, + itemtype => $item->itype, + rules => { + issuelength => '14', + lengthunit => 'days', + reservesallowed => '99', + holds_per_record => '1', + } + } + ); + + t::lib::Mocks::mock_preference( 'decreaseLoanHighHolds', 1 ); + t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsDuration', 1 ); + t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 1 ); + t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl', 'static' ); + t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsIgnoreStatuses', 'damaged,itemlost,notforloan,withdrawn' ); + + my $data = C4::Circulation::checkHighHolds( $item->unblessed , $patron->unblessed ); + ok( !$data->{exceeded}, "Patron's hold on the record does not limit their own circulation if static decrease"); + t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl', 'dynamic' ); + # 3 items on record, patron has 1 hold + $data = C4::Circulation::checkHighHolds( $item->unblessed , $patron->unblessed ); + ok( !$data->{exceeded}, "Patron's hold on the record does not limit their own circulation if dynamic decrease"); + +}; + $schema->storage->txn_rollback(); -- 2.30.2