From 73b1ddc134bad6eb1224dbb759f253192384259e Mon Sep 17 00:00:00 2001
From: pbarroca <pbarroca@afi-sa.fr>
Date: Wed, 12 Nov 2014 17:21:24 +0100
Subject: [PATCH] rel #17078: kiosk html render use profil_redirect setting

---
 .../ZendAfi/View/Helper/Accueil/Kiosque.php   | 11 +++++
 .../Resultat/TimelineJsonVisitor.php          | 18 ++++----
 library/ZendAfi/View/Helper/UrlNotice.php     | 20 ++++----
 .../ProfilOptionsControllerTest.php           |  6 +--
 .../View/Helper/Accueil/KiosqueTest.php       | 46 ++++++++++++++++++-
 .../View/Helper/ViewHelperTestCase.php        |  2 +-
 6 files changed, 80 insertions(+), 23 deletions(-)

diff --git a/library/ZendAfi/View/Helper/Accueil/Kiosque.php b/library/ZendAfi/View/Helper/Accueil/Kiosque.php
index 1b1e4c7963a..db3c7c79466 100644
--- a/library/ZendAfi/View/Helper/Accueil/Kiosque.php
+++ b/library/ZendAfi/View/Helper/Accueil/Kiosque.php
@@ -21,6 +21,17 @@
 class ZendAfi_View_Helper_Accueil_Kiosque extends ZendAfi_View_Helper_Accueil_Base {
 	protected $_nombre_notices_par_page;
 
+
+	public function __construct($id_module, $params) {
+		parent::__construct($id_module, $params);
+		if ('' != $this->preferences['profil_redirect']) {
+			$this->preferences['id_profil'] = $this->preferences['profil_redirect'];
+			$this->preferences['id_module'] = Class_Profil::getCurrentProfil()->getId()
+				. '-' . $id_module;
+		}
+	}
+
+
 	protected function _renderHeadScriptsOn($script_loader) {
 		$script_loader->addJQueryReady('$(".embedcode>div:first-child").click(function(){$(this).next().toggle("fast")})');
 		if($this->isModeMur() || $this->isModeVignettes()){
diff --git a/library/ZendAfi/View/Helper/MoteurRecherche/Resultat/TimelineJsonVisitor.php b/library/ZendAfi/View/Helper/MoteurRecherche/Resultat/TimelineJsonVisitor.php
index 625fbd91b39..bd8fe3a5119 100644
--- a/library/ZendAfi/View/Helper/MoteurRecherche/Resultat/TimelineJsonVisitor.php
+++ b/library/ZendAfi/View/Helper/MoteurRecherche/Resultat/TimelineJsonVisitor.php
@@ -16,14 +16,14 @@
  *
  * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
  * along with AFI-OPAC 2.0; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 class ZendAfi_View_Helper_MoteurRecherche_Resultat_TimelineJsonVisitor extends Zend_View_Helper_HtmlElement {
 	use Trait_Translator, Trait_NoticeVisitor;
-	
-	protected 
-		$_json, 
-		$_dates, 
+
+	protected
+		$_json,
+		$_dates,
 		$_current_date,
 		$_preferences;
 
@@ -42,22 +42,22 @@ class ZendAfi_View_Helper_MoteurRecherche_Resultat_TimelineJsonVisitor extends Z
 				'date' => $this->_dates,
 				]
 			];
-		return json_encode($this->_json);		
+		return json_encode($this->_json);
 	}
 
 
 	public function visitNotice($notice) {
-		$this->_url_notice = $this->view->urlNotice($notice);
+		$this->_url_notice = $this->view->urlNotice($notice, $this->_preferences);
 
 		$this->_current_date = ['asset' => [],
 														'startDate' => date('Y'),
-														'headline' => 
+														'headline' =>
 														'<div>'.$this->view->tagAnchor($this->_url_notice, $notice->getTitrePrincipal()).'</div>'.
 														'<div>'.$notice->getAuteurPrincipal().'</div>'
 			];
 
 		$notice->acceptVisitor($this);
-	
+
 		$this->_dates[] = $this->_current_date;
 	}
 
diff --git a/library/ZendAfi/View/Helper/UrlNotice.php b/library/ZendAfi/View/Helper/UrlNotice.php
index c91ec5bf840..79e33a64c87 100644
--- a/library/ZendAfi/View/Helper/UrlNotice.php
+++ b/library/ZendAfi/View/Helper/UrlNotice.php
@@ -16,7 +16,7 @@
  *
  * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
  * along with AFI-OPAC 2.0; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 class ZendAfi_View_Helper_UrlNotice extends Zend_View_Helper_HtmlElement {
@@ -27,8 +27,8 @@ class ZendAfi_View_Helper_UrlNotice extends Zend_View_Helper_HtmlElement {
 		if (!$notice)
 			return $this->view->url(['controller'=>'recherche',
 															 'action' => 'simple']);
-		
-		if (is_array($notice)) 
+
+		if (is_array($notice))
 			$notice = Class_Notice::find($notice['id_notice']);
 
 		$type_doc = $notice->getTypeDoc();
@@ -39,28 +39,28 @@ class ZendAfi_View_Helper_UrlNotice extends Zend_View_Helper_HtmlElement {
 														 Class_TypeDoc::CVS]))	{
 			$id_ressource=$notice->getChamp856b();
 			switch($type_doc)	{
-			case Class_TypeDoc::ARTICLE: 
+			case Class_TypeDoc::ARTICLE:
 				$options = ['controller' => 'cms',
 										'action' => 'articleview',
 										'id' => $id_ressource];
 				break;
 
-			case Class_TypeDoc::RSS: 
+			case Class_TypeDoc::RSS:
 				$options = ['controller' => 'rss',
 										'action' => 'main',
-										'id_flux' => $id_ressource]; 
+										'id_flux' => $id_ressource];
 				break;
 
 			case Class_TypeDoc::SITE:
 				$options = ['controller' => 'sito',
 										'action' => 'sitoview',
-										'id_items' => $id_ressource]; 
+										'id_items' => $id_ressource];
 				break;
 
 			case Class_TypeDoc::CVS:
 				$options = ['controller' => 'modules',
 										'action' => 'cvs',
-										'docid' => $notice->getId()]; 
+										'docid' => $notice->getId()];
 				break;
 
 			}
@@ -74,7 +74,9 @@ class ZendAfi_View_Helper_UrlNotice extends Zend_View_Helper_HtmlElement {
 																								 ['retour_panier' => '',
 																									'id_panier' => 0,
 																									'id_catalogue' => 0,
-																									'tri' => '']));
+																									'tri' => '',
+																									'id_profil' => null,
+																									'id_module' => null]));
 		}
 
 		return $this->view->url(array_filter($options));
diff --git a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php
index 1da340ff9dd..e0d800b4b32 100644
--- a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php
+++ b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php
@@ -816,7 +816,8 @@ class ProfilOptionsControllerProfilAdulteAsAdminPostConfigKiosqueStyleReloadTest
 												 'aleatoire' => 0,
 												 'tri' => 0,
 												 'only_img' => 0,
-												 'id_catalogue' => 0]);
+												 'id_catalogue' => 0,
+												 'profil_redirect' => '']);
 	}
 
 
@@ -1249,8 +1250,7 @@ class ProfilOptionsControllerProfilJeunesseViewPageJeuxTest extends ProfilOption
 
 	/** @test */
 	public function boiteKiosqueTitleShouldLinkToMenuCatalogue() {
-		$this->assertXPath(
-											 "//div[@class='boite kiosque']//div//a[contains(@href, 'recherche/simple/titre/Kiosque/style_liste/cube/nb_notices/20/only_img/1/aleatoire/1/tri/date_creation+desc/nb_analyse/50/op_hauteur_img/90/op_transition//op_largeur_img/0/op_auto/0/op_scroll/1/rss_avis/1/id_catalogue/0/id_panier/0/boite/boite_de_la_division_gauche')]",
+		$this->assertXPath("//div[@class='boite kiosque']//div//a[contains(@href, 'recherche/simple/titre/Kiosque/style_liste/cube/nb_notices/20/only_img/1/aleatoire/1/tri/date_creation+desc/nb_analyse/50/op_hauteur_img/90/op_transition//op_largeur_img/0/op_auto/0/op_scroll/1/rss_avis/1/id_catalogue/0/id_panier/0/profil_redirect//boite/boite_de_la_division_gauche')]",
 											 $this->_response->getBody());
 	}
 
diff --git a/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php b/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php
index cf12b7466c8..a198d514a71 100644
--- a/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php
+++ b/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php
@@ -490,6 +490,7 @@ class ZendAfi_View_Helper_Accueil_KiosqueTitle extends ViewHelperTestCase {
 			];
 	}
 
+
 	/** @test */
 	public function titleShouldRemoveSlashesInUrl() {
 		$this->assertContains(
@@ -499,4 +500,47 @@ class ZendAfi_View_Helper_Accueil_KiosqueTitle extends ViewHelperTestCase {
 
 }
 
-?>
\ No newline at end of file
+
+
+class ZendAfi_View_Helper_Accueil_KiosqueProfileRedirectTest extends ZendAfi_View_Helper_Accueil_KiosqueTestCase {
+	public function getPreferences() {
+		return ['type_module' => 'KIOSQUE',
+						'division' => 3,
+						'preferences' => []];
+	}
+
+
+	protected function getPreferencesWith($prefs) {
+		$result = $this->getPreferences();
+		$result['preferences'] = $prefs;
+		return $result;
+	}
+
+
+	public function datas() {
+		return [
+						[$this->getPreferencesWith(['style_liste' => 'mur',
+																				'profil_redirect' => '142']),
+						 '//a[contains(@href, "id_profil/142")][contains(@href, "id_module/2-3")]'],
+						[$this->getPreferencesWith(['style_liste' => 'vignettes',
+																				'profil_redirect' => '142']),
+						 '//a[contains(@href, "id_profil/142")][contains(@href, "id_module/2-3")]'],
+						[$this->getPreferencesWith(['style_liste' => 'chrono',
+																				'profil_redirect' => '142']),
+						 '//script[contains(., "id_profil\\/142")][contains(., "id_module\\/2-3")]']
+		];
+	}
+
+
+	/**
+	 * @test
+	 * @dataProvider datas
+	 */
+	public function recordLinksShouldBeAsExpected($prefs, $xpath) {
+		$this->_helper = new ZendAfi_View_Helper_Accueil_Kiosque(3, $prefs);
+		$this->_helper->setView(new ZendAfi_Controller_Action_Helper_View());
+
+		$this->_html = $this->_helper->getHtml()['CONTENU'];
+		$this->assertXPath($this->_html, $xpath, $this->_html);
+	}
+}
\ No newline at end of file
diff --git a/tests/library/ZendAfi/View/Helper/ViewHelperTestCase.php b/tests/library/ZendAfi/View/Helper/ViewHelperTestCase.php
index 353e02cde83..61a531d99b2 100644
--- a/tests/library/ZendAfi/View/Helper/ViewHelperTestCase.php
+++ b/tests/library/ZendAfi/View/Helper/ViewHelperTestCase.php
@@ -97,7 +97,7 @@ abstract class ViewHelperTestCase extends PHPUnit_Framework_TestCase {
 			define("URL_IMG", 'public/opac/skins/original/images');
 
 		Class_AdminVar::getLoader()->newInstanceWithId('CACHE_ACTIF')->setValeur(false);
-		Class_Profil::setCurrentProfil(Class_Profil::getLoader()->newInstanceWithId(2));
+		Class_Profil::setCurrentProfil($this->fixture('Class_Profil', ['id' => 2]));
 
 		$router = new Zend_Controller_Router_Rewrite();
 		$router->addDefaultRoutes();
-- 
GitLab