From b21fc990933e2e91afa2beaf31f9c3233dff5535 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Tue, 16 Apr 2024 12:47:16 +0000 Subject: [PATCH] Bug 29087: Add unit tests prove t/db_dependent/Koha/Items.t Signed-off-by: David Nind --- t/db_dependent/Koha/Items.t | 42 ++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index ddf47a871a..7a8b35bfa9 100755 --- a/t/db_dependent/Koha/Items.t +++ b/t/db_dependent/Koha/Items.t @@ -1998,16 +1998,50 @@ subtest 'search_ordered' => sub { subtest 'filter_by_for_hold' => sub { - plan tests => 13; + plan tests => 15; $schema->storage->txn_begin; + # Set default rule + Koha::CirculationRules->set_rule( + { + branchcode => undef, + itemtype => undef, + rule_name => 'holdallowed', + rule_value => 'not_allowed', + } + ); + my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); + my $not_holdable_itemtype = $itemtype->itemtype; + my $itemtype2 = $builder->build_object({ class => 'Koha::ItemTypes' }); + my $holdable_itemtype = $itemtype2->itemtype; + Koha::CirculationRules->set_rule( + { + branchcode => undef, + itemtype => $holdable_itemtype, + rule_name => 'holdallowed', + rule_value => 'from_any_library', + } + ); + my $biblio = $builder->build_sample_biblio; my $library = $builder->build_object({ class => 'Koha::Libraries' }); - t::lib::Mocks::mock_preference('IndependentBranches', 0); # more robust tests - is( $biblio->items->filter_by_for_hold->count, 0, 'no item yet' ); + $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0, itype => $not_holdable_itemtype } ); + is( $biblio->items->filter_by_for_hold->count, 0, 'default rule prevents hold' ); + $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0, itype => $holdable_itemtype } ); + is( $biblio->items->filter_by_for_hold->count, 1, 'hold allowed despite default rule' ); + + # Reset items and circ rules to remove default rule + $biblio->items->delete; + Koha::CirculationRules->search( + { + rule_name => 'holdallowed', + rule_value => 'not_allowed', + } + )->delete; + $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 1 } ); is( $biblio->items->filter_by_for_hold->count, 0, 'no item for hold' ); $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => 0 } ); @@ -2030,8 +2064,6 @@ subtest 'filter_by_for_hold' => sub { t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 1); is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - damaged if AllowHoldsOnDamagedItems' ); - my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); - my $not_holdable_itemtype = $itemtype->itemtype; $builder->build_sample_item( { biblionumber => $biblio->biblionumber, -- 2.37.1 (Apple Git-137.1)