Bug 33188: Remove warning from Koha::Item->hidden_in_opac

"Use of uninitialized value in string eq"

Test plan:
  prove t/db_dependent/Koha/Item.t
should return green

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Edit: tidied the tests (tcohen)
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit f575d4cd73)
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2024-10-29 14:41:19 +01:00 committed by Lucas Gass
parent 81ad98eeed
commit 1b27067e9a
2 changed files with 9 additions and 3 deletions

View File

@ -920,7 +920,7 @@ sub hidden_in_opac {
foreach my $field ( keys %{$rules} ) {
if ( any { $self->$field eq $_ } @{ $rules->{$field} } ) {
if ( any { defined $self->$field && $self->$field eq $_ } @{ $rules->{$field} } ) {
$hidden_in_opac = 1;
last;
}

View File

@ -23,6 +23,7 @@ use utf8;
use Test::More tests => 35;
use Test::Exception;
use Test::MockModule;
use Test::Warn;
use C4::Biblio qw( GetMarcSubfieldStructure );
use C4::Circulation qw( AddIssue AddReturn );
@ -326,7 +327,7 @@ subtest 'remove_from_bundle tests' => sub {
subtest 'hidden_in_opac() tests' => sub {
plan tests => 4;
plan tests => 5;
$schema->storage->txn_begin;
@ -351,7 +352,12 @@ subtest 'hidden_in_opac() tests' => sub {
ok( $item->hidden_in_opac({ rules => $rules }), 'Rule matching itype passed, should hide' );
$rules = { ccode => ['FOO'] };
$item = $item->ccode(undef)->store->get_from_storage;
warning_is {
$item->hidden_in_opac( { rules => $rules } )
}
undef, 'No warning from hidden_in_opac';
$schema->storage->txn_rollback;
};