From 9d412ff58669b4bae60de7d052eb8f76a803e4db Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 5 Oct 2021 14:17:22 +0200 Subject: [PATCH] Bug 3142: Add tests And fix a bug! Signed-off-by: Marcel de Rooy Signed-off-by: Nick Clemens Signed-off-by: Jonathan Druart (cherry picked from commit 70a303a5de4c8b351b6be1c7b7b9553a4f1c62a3) Signed-off-by: Andrew Fuerste-Henry --- Koha/Items.pm | 2 +- t/db_dependent/Koha/Items.t | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Koha/Items.pm b/Koha/Items.pm index 5fb8c6979c..efa467e47e 100644 --- a/Koha/Items.pm +++ b/Koha/Items.pm @@ -64,7 +64,7 @@ sub filter_by_for_hold { withdrawn => 0, notforloan => { '<=' => 0 } , # items with negative or zero notforloan value are holdable - ( C4::Context->preference('AllowHoldsOnDamagedItems') ? ( damaged => 0 ) : () ), + ( ! C4::Context->preference('AllowHoldsOnDamagedItems' ) ? ( damaged => 0 ) : () ), itype => { -not_in => \@hold_not_allowed_itypes }, } ); diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index 900004d912..d9c721b421 100755 --- a/t/db_dependent/Koha/Items.t +++ b/t/db_dependent/Koha/Items.t @@ -1471,7 +1471,7 @@ subtest 'can_be_transferred' => sub { }; subtest 'filter_by_for_hold' => sub { - plan tests => 4; + plan tests => 8; my $biblio = $builder->build_sample_biblio; is( $biblio->items->filter_by_for_hold->count, 0, 'no item yet' ); @@ -1482,6 +1482,21 @@ subtest 'filter_by_for_hold' => sub { $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => -1 } ); is( $biblio->items->filter_by_for_hold->count, 2, '2 items for hold' ); + $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 0 } ); + $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 1 } ); + is( $biblio->items->filter_by_for_hold->count, 3, '3 items for hold - itemlost' ); + + $builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 0 } ); + $builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 1 } ); + is( $biblio->items->filter_by_for_hold->count, 4, '4 items for hold - withdrawn' ); + + $builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 0 } ); + $builder->build_sample_item( { biblionumber => $biblio->biblionumber, damaged => 1 } ); + t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 0); + is( $biblio->items->filter_by_for_hold->count, 5, '5 items for hold - not damaged if not AllowHoldsOnDamagedItems' ); + t::lib::Mocks::mock_preference('AllowHoldsOnDamagedItems', 1); + is( $biblio->items->filter_by_for_hold->count, 6, '6 items for hold - damaged if AllowHoldsOnDamagedItems' ); + $biblio->delete; }; -- 2.39.5