From f575d4cd73567d5a0e0edc777f83bdf99959a526 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 Signed-off-by: David Nind Signed-off-by: Tomas Cohen Arazi Edit: tidied the tests (tcohen) Signed-off-by: Katrin Fischer --- Koha/Item.pm | 2 +- t/db_dependent/Koha/Item.t | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 7c692a7d92..572b5f1ff6 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -962,7 +962,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 3e290a8d9e..0822ccf4f0 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,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; }; -- 2.39.5