From eb80d3f664b57ecaa9677cfc8ae5959003ec69ef Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 23 Apr 2021 15:30:03 -0300 Subject: [PATCH] Bug 18989: (QA follow-up) Make Koha::Biblio->hidden_in_opac aware of OpacHiddenItemsHidesRecord This patch makes the method aware of the new syspref. It will only eval the rules against items if the OpacHiddenItemsHidesRecord syspref is set. Tests are added to reflect this. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Biblio.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: Tomas Cohen Arazi --- Koha/Biblio.pm | 6 +++++- t/db_dependent/Koha/Biblio.t | 30 +++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index fc1affe2333..92adf709e96 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -234,7 +234,8 @@ sub pickup_locations { my $bool = $biblio->hidden_in_opac({ [ rules => $rules ] }) Returns true if the biblio matches the hidding criteria defined in $rules. -Returns false otherwise. +Returns false otherwise. It involves the I and +I system preferences. Takes HASHref that can have the following parameters: OPTIONAL PARAMETERS: @@ -254,6 +255,9 @@ sub hidden_in_opac { return 0 unless @items; # Do not hide if there is no item + # Ok, there are items, don't even try the rules unless OpacHiddenItemsHidesRecord + return 0 unless C4::Context->preference('OpacHiddenItemsHidesRecord'); + return !(any { !$_->hidden_in_opac({ rules => $rules }) } @items); } diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index c396bd88248..ac5699ee125 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -63,13 +63,26 @@ subtest 'metadata() tests' => sub { subtest 'hidden_in_opac() tests' => sub { - plan tests => 4; + plan tests => 6; $schema->storage->txn_begin; my $biblio = $builder->build_sample_biblio(); + my $rules = { withdrawn => [ 2 ] }; + + t::lib::Mocks::mock_preference( 'OpacHiddenItemsHidesRecord', 0 ); - ok( !$biblio->hidden_in_opac({ rules => { withdrawn => [ 2 ] } }), 'Biblio not hidden if there is no item attached' ); + ok( + !$biblio->hidden_in_opac({ rules => $rules }), + 'Biblio not hidden if there is no item attached (!OpacHiddenItemsHidesRecord)' + ); + + t::lib::Mocks::mock_preference( 'OpacHiddenItemsHidesRecord', 1 ); + + ok( + !$biblio->hidden_in_opac({ rules => $rules }), + 'Biblio not hidden if there is no item attached (OpacHiddenItemsHidesRecord)' + ); my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); @@ -77,17 +90,24 @@ subtest 'hidden_in_opac() tests' => sub { $item_1->withdrawn( 1 )->store->discard_changes; $item_2->withdrawn( 1 )->store->discard_changes; - ok( !$biblio->hidden_in_opac({ rules => { withdrawn => [ 2 ] } }), 'Biblio not hidden' ); + ok( !$biblio->hidden_in_opac({ rules => $rules }), 'Biblio not hidden' ); $item_2->withdrawn( 2 )->store->discard_changes; $biblio->discard_changes; # refresh - ok( !$biblio->hidden_in_opac({ rules => { withdrawn => [ 2 ] } }), 'Biblio not hidden' ); + ok( !$biblio->hidden_in_opac({ rules => $rules }), 'Biblio not hidden' ); $item_1->withdrawn( 2 )->store->discard_changes; $biblio->discard_changes; # refresh - ok( $biblio->hidden_in_opac({ rules => { withdrawn => [ 2 ] } }), 'Biblio hidden' ); + ok( $biblio->hidden_in_opac({ rules => $rules }), 'Biblio hidden' ); + + t::lib::Mocks::mock_preference( 'OpacHiddenItemsHidesRecord', 0 ); + ok( + !$biblio->hidden_in_opac( { rules => $rules } ), + 'Biblio hidden (!OpacHiddenItemsHidesRecord)' + ); + $schema->storage->txn_rollback; }; -- 2.31.1