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 <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomas Cohen Arazi 2021-04-23 15:30:03 -03:00 committed by Jonathan Druart
parent 7998536866
commit 98263bf009
2 changed files with 30 additions and 6 deletions

View File

@ -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<OpacHiddenItems> and
I<OpacHiddenItemsHidesRecord> 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);
}

View File

@ -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 ] };
ok( !$biblio->hidden_in_opac({ rules => { withdrawn => [ 2 ] } }), 'Biblio not hidden if there is no item attached' );
t::lib::Mocks::mock_preference( 'OpacHiddenItemsHidesRecord', 0 );
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;
};