From b969254e198a9156edb4fa7299760bd67f2b857a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 24 Mar 2020 11:04:28 +0100 Subject: [PATCH] Bug 21503: Restore existing ternary operator logic This syntax is much more readable IMO. Precendent patch also missed the case where the parameter was undef. I think we are good now. Signed-off-by: Jonathan Druart --- Koha/Template/Plugin/AuthorisedValues.pm | 17 ++++++----------- .../Template/Plugin/AuthorisedValues.t | 5 ++++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Koha/Template/Plugin/AuthorisedValues.pm b/Koha/Template/Plugin/AuthorisedValues.pm index ae90288fb7..a4e163430a 100644 --- a/Koha/Template/Plugin/AuthorisedValues.pm +++ b/Koha/Template/Plugin/AuthorisedValues.pm @@ -81,17 +81,12 @@ sub GetDescriptionByKohaField { authorised_value => $params->{authorised_value}, } ); - my $av_check = $params->{authorised_value}; - if ($params->{opac}) { - if ($av->{opac_description}) { - $av_check = $av->{opac_description} - } elsif ($av->{lib}) { - $av_check = $av->{lib} - } - } elsif ($av->{lib}) { - $av_check = $av->{lib} - } - return $av_check + + my $description = $av->{lib} || $params->{authorised_value} || ''; + + return $params->{opac} + ? $av->{opac_description} || $description + : $description; } 1; diff --git a/t/db_dependent/Template/Plugin/AuthorisedValues.t b/t/db_dependent/Template/Plugin/AuthorisedValues.t index 8d2382536b..722a229f0f 100644 --- a/t/db_dependent/Template/Plugin/AuthorisedValues.t +++ b/t/db_dependent/Template/Plugin/AuthorisedValues.t @@ -73,7 +73,7 @@ subtest 'GetByCode' => sub { subtest 'GetDescriptionByKohaField' => sub { - plan tests => 7; + plan tests => 8; $schema->storage->txn_begin; @@ -145,6 +145,9 @@ subtest 'GetDescriptionByKohaField' => sub { $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( { kohafield => 'dummy.field', authorised_value => $non_existent_av } ); is( $av, $non_existent_av, 'If both OPAC and staff descriptions are missing, the parameter should be displayed'); + $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( + { kohafield => 'dummy.field', authorised_value => undef } ); + is( $av, '', 'If both OPAC and staff descriptions are missing, and the parameter is undef, an empty string should be displayed'); $schema->storage->txn_rollback; }; -- 2.20.1