From 68416611023168f72cee3d0d734695e62dd5fe5c Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@afi-sa.fr>
Date: Fri, 17 Jul 2015 10:51:01 +0200
Subject: [PATCH] dev #24821 valence user notices

fix popup notifications with quotes
---
 library/Class/ScriptLoader.php                    |  2 +-
 library/Class/TextReplacements.php                |  2 ++
 .../opac/controllers/PanierControllerTest.php     | 15 ++++++++++++---
 tests/library/Class/ScriptLoaderTest.php          |  4 ++--
 4 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/library/Class/ScriptLoader.php b/library/Class/ScriptLoader.php
index ed5b1401967..1f4be04427c 100644
--- a/library/Class/ScriptLoader.php
+++ b/library/Class/ScriptLoader.php
@@ -326,7 +326,7 @@ class Class_ScriptLoader {
 		$notifications->eachDo(
 													 function($n) use (&$popup_messages, &$bar_messages) {
 														 $n->isPopup()
-															 ? $popup_messages []= $n->getMessage()
+															 ? $popup_messages []= htmlspecialchars($n->getMessage(), ENT_QUOTES)
 															 : $bar_messages []= $n->getMessage();
 													 });
 
diff --git a/library/Class/TextReplacements.php b/library/Class/TextReplacements.php
index 05c6f96c063..c9c79cde2bc 100644
--- a/library/Class/TextReplacements.php
+++ b/library/Class/TextReplacements.php
@@ -50,6 +50,8 @@ class Class_TextReplacements  {
 
 
 	public function getReplacement($text) {
+		if (false !== strpos($text, 'Vous avez '))
+			xdebug_break();
 		foreach($this->_replacements as $search => $replace) {
 			if (false !== strpos($text, $search))
 				return str_replace($search, $replace, $text);
diff --git a/tests/application/modules/opac/controllers/PanierControllerTest.php b/tests/application/modules/opac/controllers/PanierControllerTest.php
index c428b46fc98..30114c3a842 100644
--- a/tests/application/modules/opac/controllers/PanierControllerTest.php
+++ b/tests/application/modules/opac/controllers/PanierControllerTest.php
@@ -168,7 +168,8 @@ class PanierControllerIndexActionWithTextReplacmentsTest extends PanierControlle
 																													['Vos paniers de documents;Votre sélection de documents',
 																													 ' ',
 																													 ' panier ;  sélection;',
-																													 'erreur']
+																													 'erreur',
+																													 'Afficher en résultat de recherche;L\'afficher en recherche']
 																				)]);
 		Class_TextReplacements::reset();
 		$this->dispatch('/opac/panier', true);
@@ -177,14 +178,22 @@ class PanierControllerIndexActionWithTextReplacmentsTest extends PanierControlle
 
 	/** @test */
 	public function h1ShouldContainsVotreSelectionDeDocuments() {
-		$this->assertXPathContentContains('//h1', 'Votre sélection de documents',
-																			$this->_response->getBody());
+		$this->assertXPathContentContains('//h1', 'Votre sélection de documents');
 	}
 
+
 	/** @test */
 	public function spanShouldContainsVousAvezDeuxSelections() {
 		$this->assertXPathContentContains('//span[@class="abonne"]', 'Vous avez 2 sélections');
 	}
+
+
+	/** @test */
+	public function thShouldContainsLAfficherEnRecherche() {
+		$this->assertXPathContentContains('//table[@class="soustitre"]//th',
+																			'L\'afficher en recherche');
+
+	}
 }
 
 
diff --git a/tests/library/Class/ScriptLoaderTest.php b/tests/library/Class/ScriptLoaderTest.php
index e47360c48f9..1a197504644 100644
--- a/tests/library/Class/ScriptLoaderTest.php
+++ b/tests/library/Class/ScriptLoaderTest.php
@@ -244,7 +244,7 @@ class ScriptLoaderNotificationsBarTest extends Storm_Test_ModelTestCase {
 		$messenger->addNotification('First message');
 		$messenger->addNotification('Second message');
 		$messenger->addNotification('Third message', ['display' => 'popup']);
-		$messenger->addNotification('Fourth message', ['display' => 'popup']);
+		$messenger->addNotification('Fourth\'message', ['display' => 'popup']);
 
 		ZendAfi_Controller_Action_Helper_FlashMessenger::reset();
 		$this->_html = Class_ScriptLoader::getInstance()->showNotifications()->html();
@@ -267,7 +267,7 @@ class ScriptLoaderNotificationsBarTest extends Storm_Test_ModelTestCase {
 
 	/** @test */
 	public function messageThreeAndFourShouldBePopupedUpInJQueryDialog() {
-		$this->assertContains("$('<p title=\"Information\">Third message<br> Fourth message</p>').dialog()",
+		$this->assertContains("$('<p title=\"Information\">Third message<br> Fourth&#039;message</p>').dialog()",
 													$this->_html);
 	}
 }
-- 
GitLab