From 3072df9cf4be8a61006ff569aefb569cc637fd2c Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@afi-sa.fr>
Date: Tue, 17 Jun 2014 11:49:03 +0200
Subject: [PATCH] dev #14378 autocomplete

fix locale setup
---
 library/ZendAfi/Controller/Plugin/SetupLocale.php     |  2 ++
 .../opac/controllers/RechercheControllerTest.php      | 11 +++++++++++
 tests/library/Class/Autocomplete/index/titles         |  3 ++-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/library/ZendAfi/Controller/Plugin/SetupLocale.php b/library/ZendAfi/Controller/Plugin/SetupLocale.php
index 681e11d3770..7fa50d74eee 100644
--- a/library/ZendAfi/Controller/Plugin/SetupLocale.php
+++ b/library/ZendAfi/Controller/Plugin/SetupLocale.php
@@ -51,6 +51,8 @@ class ZendAfi_Controller_Plugin_SetupLocale extends Zend_Controller_Plugin_Abstr
 		$this->_appendLocaleCodes($language, $locale_params);
 		call_user_func_array('setlocale', $locale_params);
 
+		putenv('LANG='.$locale_params[1]);
+
 		if ('admin' ==  $request->getModuleName())
 			Class_Profil::setDefaultTranslator(new Class_Profil_NullTranslator(null));
 	}
diff --git a/tests/application/modules/opac/controllers/RechercheControllerTest.php b/tests/application/modules/opac/controllers/RechercheControllerTest.php
index b717e9b4150..1bd70b9f0c7 100644
--- a/tests/application/modules/opac/controllers/RechercheControllerTest.php
+++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php
@@ -2000,6 +2000,7 @@ class RechercheController_IndexSearcherTest extends AbstractControllerTestCase {
 		return [
 			['<span>Jean-P</span>ierre Cuq','jean-p'],
 			["<span>L'île</span> <span>de</span> <span>maïté</span>", "l'ile dE Maite"],
+			["Dis-moi la <span>vérité</span>.", "verite"],
 			["<span>Ô</span> Mireille si tu savais, <span>où</span> je suis.", 'o ou'],
 			["Centre interdépartemental de gestion de la Petite couronne de la région <span>d'Ile</span>-de-France", "d'ile"],
 			['Jacques <span>Réda</span>', 'reda'],
@@ -2014,6 +2015,16 @@ class RechercheController_IndexSearcherTest extends AbstractControllerTestCase {
 	public function autocompleteTermShouldBeFound($expected_result, $search_expression) {
 		$this->assertEquals($expected_result, $this->searchFor($search_expression));
 	}
+
+
+	/** @test */
+	public function envLocaleShouldBeForcedToCurrentLocale() {
+		putenv('LANG=en_EN');
+		setlocale('LC_ALL', 'en');
+		$this->dispatch('/opac/recherche/suggestajax/startsWith/verite/language/fr', true);
+		$this->assertEquals("Dis-moi la <span>vérité</span>.", $this->searchFor('verite'));
+		$this->assertEquals('UTF-8', exec('locale charmap'));
+	}
 }
 
 ?>
\ No newline at end of file
diff --git a/tests/library/Class/Autocomplete/index/titles b/tests/library/Class/Autocomplete/index/titles
index f1989dfb6e2..709da050cc0 100644
--- a/tests/library/Class/Autocomplete/index/titles
+++ b/tests/library/Class/Autocomplete/index/titles
@@ -9,4 +9,5 @@ Blue Bay Palace de Nathacha Appanah
 Bleu de chauffe de Nan Aurousseau
 L'île de maïté
 Ô Mireille si tu savais, où je suis.
-Association Villeparisis et son passé
\ No newline at end of file
+Association Villeparisis et son passé
+Dis-moi la vérité.
\ No newline at end of file
-- 
GitLab