From bf5cc80e3e4d24c52ef84506dd2e328954017787 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Thu, 9 Jan 2020 11:02:33 +0100
Subject: [PATCH] Bug 20307: Fix existing tests

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
---
 Koha/AuthorisedValue.pm           | 11 +++++++----
 t/db_dependent/AuthorisedValues.t | 11 ++++++-----
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/Koha/AuthorisedValue.pm b/Koha/AuthorisedValue.pm
index 8eee2fc450..2ff8cad245 100644
--- a/Koha/AuthorisedValue.pm
+++ b/Koha/AuthorisedValue.pm
@@ -67,15 +67,18 @@ sub opac_translated_description {
              : $self->lib;
     }
     $lang ||= C4::Languages::getlanguage;
+
+    return $self->translated_description unless $self->lib_opac;
+
     my $translated_description = Koha::Localizations->search({
-        code => sprintf "%s_%s", $self->category, $self->authorised_value,
+        code => sprintf( "%s_%s", $self->category, $self->authorised_value ),
         entity => 'authorised_values',
         lang => $lang,
         interface => 'opac',
     })->next;
     return $translated_description
          ? $translated_description->translation
-         : $self->translated_description; # FIXME Is that what we really want?
+         : $self->lib_opac;
 }
 
 =head3 translated_description
@@ -94,7 +97,7 @@ sub translated_description {
     }
     $lang ||= C4::Languages::getlanguage;
     my $translated_description = Koha::Localizations->search({
-        code => sprintf "%s_%s", $self->category, $self->authorised_value,
+        code => sprintf( "%s_%s", $self->category, $self->authorised_value ),
         entity => 'authorised_values',
         lang => $lang,
     })->next;
@@ -111,7 +114,7 @@ sub translated_descriptions {
     my ( $self ) = @_;
     my @translated_descriptions = Koha::Localizations->search(
         {   entity => 'authorised_values',
-            code => sprintf "%s_%s", $self->category, $self->authorised_value,
+            code => sprintf( "%s_%s", $self->category, $self->authorised_value ),
         }
     );
     return [ map {
diff --git a/t/db_dependent/AuthorisedValues.t b/t/db_dependent/AuthorisedValues.t
index d16d282731..44ae89ca09 100644
--- a/t/db_dependent/AuthorisedValues.t
+++ b/t/db_dependent/AuthorisedValues.t
@@ -4,6 +4,7 @@ use Modern::Perl;
 use Test::More tests => 15;
 
 use t::lib::TestBuilder;
+use t::lib::Mocks;
 
 use Koha::Database;
 use C4::Context;
@@ -213,15 +214,15 @@ subtest 'search_by_*_field + find_by_koha_field + get_description' => sub {
         is_deeply(
             \@descriptions,
             [
-                {
-                    authorised_value => '',
-                    lib              => $av_empty_string->lib,
-                    opac_description => $av_empty_string->lib_opac
-                },
                 {
                     authorised_value => $av_0->authorised_value,
                     lib              => $av_0->lib,
                     opac_description => $av_0->lib_opac
+                },
+                {
+                    authorised_value => '',
+                    lib              => $av_empty_string->lib,
+                    opac_description => $av_empty_string->lib_opac
                 }
             ],
         );
-- 
2.20.1