@@ -, +, @@ aware of OpacHiddenItemsHidesRecord $ kshell k$ prove t/db_dependent/Koha/Biblio.t --- Koha/Biblio.pm | 6 +++++- t/db_dependent/Koha/Biblio.t | 30 +++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) --- a/Koha/Biblio.pm +++ a/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); } --- a/t/db_dependent/Koha/Biblio.t +++ a/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; }; --