From 0f84d7ebf4395f56fd49e69e6a7315b0cbf71fb0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 29 Oct 2024 14:41:19 +0100 Subject: [PATCH] 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 --- Koha/Item.pm | 2 +- t/db_dependent/Koha/Item.t | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 16f66a8c68e..334813fbf6f 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -960,7 +960,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; } diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index 3e290a8d9e0..f15c9cba01d 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -23,6 +23,7 @@ use utf8; use Test::More tests => 38; use Test::Exception; use Test::MockModule; +use Test::Warn; use C4::Biblio qw( GetMarcSubfieldStructure ); use C4::Circulation qw( AddIssue AddReturn ); @@ -410,7 +411,7 @@ subtest 'remove_from_bundle tests' => sub { subtest 'hidden_in_opac() tests' => sub { - plan tests => 4; + plan tests => 5; $schema->storage->txn_begin; @@ -435,7 +436,10 @@ 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; }; -- 2.34.1