From 8f913c0ebada618bea1107b47716eb2fd965d6ca Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Tue, 23 Oct 2018 16:05:35 +0200 Subject: [PATCH] hotline #80953 utf8 encode data only on non-unicode files --- .../Class/Cosmogramme/Generator/AbstractTask.php | 6 ++++-- .../Integration/PhasePrepareIntegrationsTest.php | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/library/Class/Cosmogramme/Generator/AbstractTask.php b/library/Class/Cosmogramme/Generator/AbstractTask.php index 79fd9f58aa7..1d7c57a8cfa 100644 --- a/library/Class/Cosmogramme/Generator/AbstractTask.php +++ b/library/Class/Cosmogramme/Generator/AbstractTask.php @@ -82,8 +82,10 @@ abstract class Class_Cosmogramme_Generator_AbstractTask { protected function _extract($data) { - $data = utf8_encode($data); - return explode('|', $data); + return explode('|', + mb_detect_encoding($data, 'UTF-8', true) + ? $data + : utf8_encode($data)); } diff --git a/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php b/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php index 77df3e6b127..c6dac7b3f68 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php @@ -348,7 +348,9 @@ class PhasePrepareIntegrationsNanookStandardTest ->whenCalled('getLibrariesOf')->with('foo') ->answers(['BIB_SPS_UTT|ID_SITE|LIBELLE', - '2|My library']) + '2|Ma library', + '6|Ma bibliothèque', + '8|' . iconv('UTF-8', 'ISO-8859-1', 'Ma médiathèque')]) ->whenCalled('getSectionsOf')->with('foo') ->answers(['BIB_C_SECTION|CODE|LIBELLE', @@ -624,6 +626,18 @@ class PhasePrepareIntegrationsNanookStandardTest } + /** @test */ + public function libraryIdSixLabelShouldBeMaBibliothèque() { + $this->assertEquals('Ma bibliothèque', Class_Cosmogramme_Generator_FixedIdBib::find(6)->getLibelle()); + } + + + /** @test */ + public function libraryIdEigthLabelShouldBeMaMédiathèque() { + $this->assertEquals('Ma médiathèque', Class_Cosmogramme_Generator_FixedIdBib::find(8)->getLibelle()); + } + + /** @test */ public function plannedIntegrationsOfRemovedLibraryShouldBeDeleted() { $this->assertEmpty(Class_IntMajAuto::findAllBy(['id_bib' => 3])); -- GitLab