diff --git a/C4/Context.pm b/C4/Context.pm index 35c5025745..6406f340ec 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -348,6 +348,8 @@ sub yaml_preference { return; } + # TODO Remove next line when enforced elsewhere + if( $yaml && lc($preference) eq 'itemsdeniedrenewal' and ref($yaml) ne 'HASH' ) { warn "Hashref expected for $preference"; return; } return $yaml; } diff --git a/t/Context.t b/t/Context.t index b2091f0f96..e8115df8f0 100755 --- a/t/Context.t +++ b/t/Context.t @@ -31,7 +31,7 @@ BEGIN { subtest 'yaml_preference() tests' => sub { - plan tests => 3; + plan tests => 6; my $data = [ 'uno', 'dos', { 'tres' => 'cuatro' } ]; @@ -49,6 +49,12 @@ subtest 'yaml_preference() tests' => sub { 'Invalid YAML on syspref throws a warning'; is( $pref, undef, 'Invalid YAML on syspref makes it return undef' ); + $context->mock( 'preference', sub { return '{ a : 1 }' }); + is( ref( C4::Context->new->yaml_preference('ItemsDeniedRenewal') ), 'HASH', 'Got a hash as expected' ); + $context->mock( 'preference', sub { return '[ 1, 2 ]' }); + warning_like { $pref = C4::Context->new->yaml_preference('ITEMSDENIEDRENEWAL') } qr/Hashref expected/, 'Array not accepted for ItemsDeniedRenewal'; + is( $pref, undef, 'Returned undef' ); + $context->unmock( 'preference' ); };