Browse Source

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 <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
tags/v20.05.00
parent
commit
b1c6d14d14
Signed by: martin.renvoize <martin.renvoize@ptfs-europe.com> GPG Key ID: 422B469130441A0F
2 changed files with 10 additions and 12 deletions
  1. +6
    -11
      Koha/Template/Plugin/AuthorisedValues.pm
  2. +4
    -1
      t/db_dependent/Template/Plugin/AuthorisedValues.t

+ 6
- 11
Koha/Template/Plugin/AuthorisedValues.pm View File

@@ -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;


+ 4
- 1
t/db_dependent/Template/Plugin/AuthorisedValues.t View File

@@ -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;
};

Loading…
Cancel
Save