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>
20.05.x
Jonathan Druart 4 years ago
committed by Martin Renvoize
parent
commit
b1c6d14d14
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 17
      Koha/Template/Plugin/AuthorisedValues.pm
  2. 5
      t/db_dependent/Template/Plugin/AuthorisedValues.t

17
Koha/Template/Plugin/AuthorisedValues.pm

@ -81,17 +81,12 @@ sub GetDescriptionByKohaField {
authorised_value => $params->{authorised_value}, authorised_value => $params->{authorised_value},
} }
); );
my $av_check = $params->{authorised_value};
if ($params->{opac}) { my $description = $av->{lib} || $params->{authorised_value} || '';
if ($av->{opac_description}) {
$av_check = $av->{opac_description} return $params->{opac}
} elsif ($av->{lib}) { ? $av->{opac_description} || $description
$av_check = $av->{lib} : $description;
}
} elsif ($av->{lib}) {
$av_check = $av->{lib}
}
return $av_check
} }
1; 1;

5
t/db_dependent/Template/Plugin/AuthorisedValues.t

@ -73,7 +73,7 @@ subtest 'GetByCode' => sub {
subtest 'GetDescriptionByKohaField' => sub { subtest 'GetDescriptionByKohaField' => sub {
plan tests => 7; plan tests => 8;
$schema->storage->txn_begin; $schema->storage->txn_begin;
@ -145,6 +145,9 @@ subtest 'GetDescriptionByKohaField' => sub {
$av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField( $av = Koha::Template::Plugin::AuthorisedValues->GetDescriptionByKohaField(
{ kohafield => 'dummy.field', authorised_value => $non_existent_av } ); { 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'); 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; $schema->storage->txn_rollback;
}; };

Loading…
Cancel
Save