From d883dc5b2565769db791fc52d132e855c00a3777 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Wed, 4 Dec 2013 09:37:24 +0000
Subject: [PATCH] Refacto rendu articles

---
 .../views/scripts/cms/article_partial.phtml   | 31 ++-------
 .../modules/opac/views/scripts/head.phtml     |  3 +-
 .../View/Helper/Article/RenderAbstract.php    | 64 +++++++++++++++----
 public/admin/js/onload_utils.js               | 11 ++++
 public/opac/css/global.css                    |  6 ++
 .../opac/controllers/CmsControllerTest.php    | 34 ++++++++--
 .../View/Helper/ViewHelperTestCase.php        |  1 +
 7 files changed, 104 insertions(+), 46 deletions(-)

diff --git a/application/modules/opac/views/scripts/cms/article_partial.phtml b/application/modules/opac/views/scripts/cms/article_partial.phtml
index 5ef79862c3f..974c1f1fb44 100644
--- a/application/modules/opac/views/scripts/cms/article_partial.phtml
+++ b/application/modules/opac/views/scripts/cms/article_partial.phtml
@@ -3,6 +3,12 @@ if (!isset($this->show_content)) {
 	$this->show_content = 'FullContent';
 }
 
+
+if ($this->show_content == 'FullContent') { 
+	echo $this->article_RenderFullContent($this->article);
+	return;
+}
+
 $titre = '';
 
 if (
@@ -34,34 +40,9 @@ echo $this->tagEditArticle($this->article);
 					$this->url($this->article->getUrl()),
 					$this->_("Lire l'article complet")
 				);?>
-	<?php }
-
-	if ($this->show_content == 'FullContent') { ?>
-	<?php echo $this->article->getFullContent();?>
 	<?php } ?>
 	<!-- RSPEAK_STOP -->
 
-	<?php if ($this->show_content == 'FullContent') { ?>
-		<?php echo $this->renderLieu($this->article->getLieu(), array('size' => '300x200')) ?>
-		<div id="reseaux-sociaux-<?php echo $this->article->getId();?>">
-			<?php echo $this->tagImg(URL_IMG . 'patience.gif');?>
-		</div>
-		<script type="text/javascript">
-		 $('#reseaux-sociaux-<?php echo $this->article->getId();?>').load('<?php
-				echo $this->url([
-					'controller'	=> 'cms',
-					'action'			=> 'reseau',
-					'id_article'	=> $this->article->getId()
-				], null, true);
-			?>');
-		</script>
-
-		<?php
-		if (1 == $this->article->getAvis()) { 
-			echo $this->avisCms($this->article);
-		} ?>
-
-	<?php } ?>
 </div>
 
 <?php echo $this->closeBoite(); ?>
diff --git a/application/modules/opac/views/scripts/head.phtml b/application/modules/opac/views/scripts/head.phtml
index 937fa4e1446..9b1e83794d6 100644
--- a/application/modules/opac/views/scripts/head.phtml
+++ b/application/modules/opac/views/scripts/head.phtml
@@ -45,7 +45,8 @@ $head_scripts = Class_ScriptLoader::newInstance()
        initializeNoticeMurAnimation();
        initializeImgHover();
        initializePopups();
-       initializeDivisionFive();')
+       initializeDivisionFive();
+       initializeReseauxSociaux();')
 	->addJQueryBackEnd(sprintf('$("#select_clef_profil").parent().prepend(\'%s\')',
 													 $this->tagImg(URL_ADMIN_IMG.'ico/lock.png',
 																				 ['alt' => $this->_("Afficher les outils d\'administration"),
diff --git a/library/ZendAfi/View/Helper/Article/RenderAbstract.php b/library/ZendAfi/View/Helper/Article/RenderAbstract.php
index ca92d5067a1..8e04ca318aa 100644
--- a/library/ZendAfi/View/Helper/Article/RenderAbstract.php
+++ b/library/ZendAfi/View/Helper/Article/RenderAbstract.php
@@ -21,13 +21,25 @@
 abstract class ZendAfi_View_Helper_Article_RenderAbstract extends ZendAfi_View_Helper_BaseHelper {
 	public function renderArticle($article, $html_class) {
 		return
-			'<div class="auto_resize '.$html_class.'">'
-			.$this->view->tagEditArticle($article)
-			.$this->renderDraftStatus($article)
-			.$this->renderTitreHeader($article)
-			.$this->view->tagArticleEvent($article)
-			.$this->renderContent($article)
-			.'</div>';
+			$this->renderArticleHTML(
+				'<div class="auto_resize '.$html_class.'"><!-- RSPEAK_START -->'
+				.$this->view->tagEditArticle($article)
+				.$this->renderReadSpeaker($article)
+				.$this->renderTitreHeader($article)
+				.$this->renderDraftStatus($article)
+				.$this->view->tagArticleEvent($article)
+				.$this->renderContent($article)
+				.$this->renderLieu($article)
+				.$this->renderReseauxSociaux($article)
+				.$this->renderAvis($article)
+				.'<!-- RSPEAK_STOP --></div>',
+
+				$article);
+	}
+
+
+	public function renderArticleHTML($html, $article) {
+		return $html;
 	}
 
 
@@ -37,12 +49,14 @@ abstract class ZendAfi_View_Helper_Article_RenderAbstract extends ZendAfi_View_H
 
 
 	public function renderTitreHeader($article) {
-		return '<h2>'
-			.$this->renderTitre($article)
-			.$this->view->readSpeaker('cms',
-																'articleread',
-																["id" => $article->getId()])
-			.'</h2>';
+		return '<h2>'.$this->renderTitre($article).'</h2>';
+	}
+
+
+	public function renderReadSpeaker($article){
+		return $this->view->readSpeaker('cms',
+     																'articleread',
+     																["id" => $article->getId()]);
 	}
 
 
@@ -61,6 +75,30 @@ abstract class ZendAfi_View_Helper_Article_RenderAbstract extends ZendAfi_View_H
 																													 ['class' => 'article_read_full']);
 	}
 
+
+	public function renderReseauxSociaux($article) {
+		$url_reseau = $this->view->url(['controller'	=> 'cms',
+																		'action'			=> 'reseau',
+																		'id_article'	=> $article->getId()], null, true);
+
+		return 
+			'<div class="reseaux-sociaux" data-article-url="'.$url_reseau.'">'
+			.$this->view->tagImg(URL_IMG . 'patience.gif')
+			.'</div>';
+	}
+
+
+	public function renderLieu($article) {
+		return $this->view->renderLieu($article->getLieu(),
+																	 ['size' => '300x200']);
+	}
+
+
+	public function renderAvis($article) {
+		return $article->getAvis() == 1 
+			? $this->view->avisCms($article)
+			: '';
+	}
 }
 
 ?>
\ No newline at end of file
diff --git a/public/admin/js/onload_utils.js b/public/admin/js/onload_utils.js
index e464c0864c9..691dd68f853 100644
--- a/public/admin/js/onload_utils.js
+++ b/public/admin/js/onload_utils.js
@@ -106,3 +106,14 @@ var initializeImgHover = function() {
 																 function(){image.attr('src', image.data('out'));});
   });
 }
+
+
+
+var initializeReseauxSociaux = function() {
+	$('.reseaux-sociaux[data-article-url]').each(
+		function(index,element) {
+			$element = $(element);
+			$element.load($element.attr('data-article-url'));
+		}
+	);
+}
diff --git a/public/opac/css/global.css b/public/opac/css/global.css
index a70d445a7b0..23cfd5fb59c 100644
--- a/public/opac/css/global.css
+++ b/public/opac/css/global.css
@@ -2556,3 +2556,9 @@ form.ajout_panier + div  a {
 .colFlottant table.contenu_panier {
 		max-width: 400px;
 }
+
+
+
+a.readspeaker {
+		float: right;
+}
\ No newline at end of file
diff --git a/tests/application/modules/opac/controllers/CmsControllerTest.php b/tests/application/modules/opac/controllers/CmsControllerTest.php
index 1da8ce5d2ca..d3c9c5fba7b 100644
--- a/tests/application/modules/opac/controllers/CmsControllerTest.php
+++ b/tests/application/modules/opac/controllers/CmsControllerTest.php
@@ -222,8 +222,9 @@ abstract class AbstractCmsControllerArticleViewByDateTest extends AbstractContro
 	}
 
 	public function setUp() {
-		Class_AdminVar::set('WORKFLOW','');
 		parent::setUp();
+
+		Class_AdminVar::newInstanceWithId('WORKFLOW',['valeur' => '']);
 	 
 		$articles = [	Class_Article::getLoader()
 									->newInstanceWithId(1)
@@ -296,11 +297,11 @@ abstract class AbstractCmsControllerArticleViewByDateTest extends AbstractContro
 
 
 class CmsControllerArticleViewByDateTest extends AbstractCmsControllerArticleViewByDateTest {
-
 	public function setUp() {
 		$this->display_mode='Title';
 		parent::setUp();
 	}
+
 	/** @test */
 	public function feteDeLaBananeTitleShouldBePresent() {
 		$this->assertXpathContentContains('//ul//li//a', 'La fête de la banane');
@@ -342,7 +343,6 @@ class CmsControllerArticleViewByDateTest extends AbstractCmsControllerArticleVie
 	public function emptyBibliothequeLibelleShouldBeDisplayedAsPortail() {
 		$this->assertXpathContentContains('//h2', 'Portail');
 	}
-
 }
 
 
@@ -633,6 +633,9 @@ class CmsControllerArticleViewTest extends CmsControllerWithFeteDeLaFriteTestCas
 	
 	public function setUp() {
 		parent::setUp();
+
+		Class_AdminVar::newInstanceWithId('ID_READ_SPEAKER', ['valeur' => '1234']);
+
 		$this->dispatch('/cms/articleview/id/224', true);
 	}
 
@@ -657,15 +660,14 @@ class CmsControllerArticleViewTest extends CmsControllerWithFeteDeLaFriteTestCas
 
 	/** @test */
 	public function socialNetworksContainerShouldBePresent() {
-		$this->assertXpath('//div[@id="reseaux-sociaux-224"]/img[contains(@src, "patience.gif")]');
+		$this->assertXpath('//div[@class="reseaux-sociaux"][contains(@data-article-url, "cms/reseau/id_article/224")]/img[contains(@src, "patience.gif")]');
 	}
 
 
 	/** @test */
-	public function socialNetworksScriptShouldBePresent() {
+	public function initializeResauxSociauxScriptShouldBePresent() {
 		$this->assertXPathContentContains('//script', 
-																			"$('#reseaux-sociaux-224').load('/cms/reseau/id_article/224')",
-																			$this->_response->getBody());
+																			"initializeReseauxSociaux");
 	}
 
 
@@ -718,6 +720,24 @@ class CmsControllerArticleViewTest extends CmsControllerWithFeteDeLaFriteTestCas
 		$this->assertXPath('//div[@class="lieu"]//img[contains(@src,"http://maps.googleapis.com/maps")]');
 	}
 
+	
+	/** @test */
+	public function readSpeakerLinkShouldBePresent() {
+		$this->assertXPath('//a[@class="readspeaker"][contains(@onclick, "/cms/articleread?id=224")]',
+											 $this->_response->getBody());
+	}
+
+
+	/** @test */
+	public function speakStartMarkerShouldBePresent() {
+		$this->assertXpathContentContains('//div[@class="auto_resize article"]', '<!-- RSPEAK_START -->');
+	}
+
+	/** @test */
+	public function speakStopMarkerShouldBePresent() {
+		$this->assertXpathContentContains('//div[@class="auto_resize article"]', '<!-- RSPEAK_STOP -->');
+	}
+
 }
 
 
diff --git a/tests/library/ZendAfi/View/Helper/ViewHelperTestCase.php b/tests/library/ZendAfi/View/Helper/ViewHelperTestCase.php
index c206f266405..8c9b94f1838 100644
--- a/tests/library/ZendAfi/View/Helper/ViewHelperTestCase.php
+++ b/tests/library/ZendAfi/View/Helper/ViewHelperTestCase.php
@@ -86,6 +86,7 @@ abstract class ViewHelperTestCase extends PHPUnit_Framework_TestCase {
 	public function setUp() {
 		parent::setUp();
 
+		Class_ScriptLoader::resetInstance();
 		Storm_Model_Abstract::unsetLoaders();
 
 		if (!defined("URL_IMG"))
-- 
GitLab