From 3d59e37bf0ea8f94e8edc76fc7f71fbf86fe9ef6 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Sat, 24 Aug 2013 14:15:19 +0000
Subject: [PATCH] Ajout lien modification biographie

---
 .../scripts/upload/biographie-notice.phtml    |  3 +-
 library/Class/NoticeHtml.php                  | 58 ---------------
 library/Class/WebService/AllServices.php      |  2 +-
 library/ZendAfi/View/Helper/Biographie.php    | 71 ++++++++++++++++++-
 .../controllers/NoticeAjaxControllerTest.php  | 57 +++++++++++++++
 5 files changed, 129 insertions(+), 62 deletions(-)

diff --git a/application/modules/admin/views/scripts/upload/biographie-notice.phtml b/application/modules/admin/views/scripts/upload/biographie-notice.phtml
index 23d75320ca0..cdead047fc6 100644
--- a/application/modules/admin/views/scripts/upload/biographie-notice.phtml
+++ b/application/modules/admin/views/scripts/upload/biographie-notice.phtml
@@ -1,7 +1,6 @@
-<h1 style="text-align: center; margin-bottom: 10px"><?php echo $this->_('Modifier la vignette'); ?></h1>
+<h1 style="text-align: center; margin-bottom: 10px"><?php echo $this->_('Modifier la biographie'); ?></h1>
 
 <div class="formTable" style="margin: 0 auto">
-
 <?php 
 if ($this->error)
 	echo '<div class="error">'.$this->_('Erreur: ').$this->error.'</div>';
diff --git a/library/Class/NoticeHtml.php b/library/Class/NoticeHtml.php
index 7e1c2396243..455f00e01ad 100644
--- a/library/Class/NoticeHtml.php
+++ b/library/Class/NoticeHtml.php
@@ -164,64 +164,6 @@ class Class_NoticeHtml {
 	}
 
 
-//------------------------------------------------------------------------------------------------------
-// Biographie
-//------------------------------------------------------------------------------------------------------
-	public function getBiographie($data,$notice)	{
-		if(!$data["biographie"]) 
-			return $this->getNonTrouve("",true);
-
-		$auteur = $notice->getAuteurPrincipal();
-		$html=$this->haut_onglet;
-		$html.='<table width="100%">';
-		$html.=sprintf('<tr><td class="notice_info_titre" align="left" width="100%%">%s<font size="-2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(%s : %s)</font></td></tr>',
-									 $auteur,
-									 $this->_translate->_('Source'),
-									 $data["source"]);
-		$suite = false;
-		foreach ($data["biographie"] as $ligne)	{
-			if(!isset($ligne["texte"])) continue;
-			if(isset($ligne["liste"])){
-				$liste='<ul class="notice_info">';
-				foreach($ligne["liste"] as $item) $liste.='<li class="notice_liste">'.$item.'</li>';
-				$liste.='</ul>';
-				$ligne["texte"]=str_replace("@LISTE@",$liste,$ligne["texte"]);
-			}
-			if ($suite){
-				if(isset($ligne["titre"])) 
-					$html.='<tr><td class="notice_info_titre" align="left" width="100%">'.$ligne["titre"].'</td></tr>';
-
-				$html.='<tr><td class="notice_info" align="left" width="100%">'.$ligne["texte"].'</td></tr>';
-			}
-			else
-			{
-				if(!$data["vignette"]) $vignette='';
-				else
-				{
-					$vignette = $this->_translate->_('<img src="%s" style="%s" alt="%s" />',
-																					 $data["vignette"],
-																					 'border:0;width:100px;float:left;margin-right:5px;cursor:pointer',
-																					 $this->_translate->_('Vignette'));
-					if($data["image"])
-					{
-						$id="auteur_".$notice->getId();
-						$vignette='<a id="'.$id.'" href="'.$data["image"].'" rel="lightbox" title="'.$auteur.'">'.$vignette;
-						$vignette.='</a>';
-						$vignette.='<script type="text/javascript">$("a[id=\''.$id.'\']").slimbox({}, null, null)</script>';
-					}
-				}
-				
-				$html.='<tr><td><table>';
-				$html.='<tr><td class="notice_info">'.$vignette;
-				$html.=$ligne["texte"].'</td></tr>';
-				$html.='</table></td></tr>';
-				$suite=true;
-			}
-		}
-		$html.='</table>';
-		return $html;
-	}
-
 //------------------------------------------------------------------------------------------------------
 // Bande annonce
 //------------------------------------------------------------------------------------------------------	
diff --git a/library/Class/WebService/AllServices.php b/library/Class/WebService/AllServices.php
index 97b8d396a42..d6cebee106a 100644
--- a/library/Class/WebService/AllServices.php
+++ b/library/Class/WebService/AllServices.php
@@ -174,7 +174,7 @@ class Class_WebService_AllServices {
 
 		$args['src'] = self::createSecurityKey();
 		$args['action'] = $service;
-///		$args['XDEBUG_SESSION_START'] = 1;
+		$args['XDEBUG_SESSION_START'] = 1;
 
 		return json_decode(self::httpGet($url_service, $args),
 											 true);
diff --git a/library/ZendAfi/View/Helper/Biographie.php b/library/ZendAfi/View/Helper/Biographie.php
index 04fdaa7bf28..d3c33f6623b 100644
--- a/library/ZendAfi/View/Helper/Biographie.php
+++ b/library/ZendAfi/View/Helper/Biographie.php
@@ -33,8 +33,77 @@ class ZendAfi_View_Helper_Biographie extends Zend_View_Helper_HtmlElement {
 						 'clef_oeuvre' => $notice->getClefOeuvre()];
 
 		$data = Class_WebService_AllServices::runServiceAfiBiographie($args);
-		return $notice_html->getBiographie($data, $notice);
+		return $this->renderModifierBiographieLink($notice)
+			.$this->renderBiographie($data, $notice);
 	}
+
+
+	public function renderModifierBiographieLink($notice)	{
+		return sprintf('<a href="#" onclick="showPopWin(\'%s\', 750, 350); return false;">%s</a>',
+									 $this->view->url(['module' => 'admin', 
+																		 'controller' => 'upload',
+																		 'action' => 'biographie-notice',
+																		 'id' => $notice->getId(),
+																			]),
+									 $this->view->_('Modifier la biographie'));
+	}
+
+
+	public function renderBiographie($data,$notice)	{
+		if(!$data["biographie"]) 
+			return $this->getNonTrouve("",true);
+
+		$auteur = $notice->getAuteurPrincipal();
+
+		$html = '<table width="100%">';
+		$html.=sprintf('<tr><td class="notice_info_titre" align="left" width="100%%">%s<font size="-2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(%s : %s)</font></td></tr>',
+									 $auteur,
+									 $this->view->_('Source'),
+									 $data["source"]);
+		$suite = false;
+		foreach ($data["biographie"] as $ligne)	{
+			if(!isset($ligne["texte"])) continue;
+			if(isset($ligne["liste"])){
+				$liste='<ul class="notice_info">';
+				foreach($ligne["liste"] as $item) $liste.='<li class="notice_liste">'.$item.'</li>';
+				$liste.='</ul>';
+				$ligne["texte"]=str_replace("@LISTE@",$liste,$ligne["texte"]);
+			}
+			if ($suite){
+				if(isset($ligne["titre"])) 
+					$html.='<tr><td class="notice_info_titre" align="left" width="100%">'.$ligne["titre"].'</td></tr>';
+
+				$html.='<tr><td class="notice_info" align="left" width="100%">'.$ligne["texte"].'</td></tr>';
+			}
+			else
+			{
+				if(!$data["vignette"]) $vignette='';
+				else
+				{
+					$vignette = $this->view->_('<img src="%s" style="%s" alt="%s" />',
+																		 $data["vignette"],
+																		 'border:0;width:100px;float:left;margin-right:5px;cursor:pointer',
+																		 $this->view->_('Vignette'));
+					if($data["image"])
+					{
+						$id="auteur_".$notice->getId();
+						$vignette='<a id="'.$id.'" href="'.$data["image"].'" rel="lightbox" title="'.$auteur.'">'.$vignette;
+						$vignette.='</a>';
+						$vignette.='<script type="text/javascript">$("a[id=\''.$id.'\']").slimbox({}, null, null)</script>';
+					}
+				}
+				
+				$html.='<tr><td><table>';
+				$html.='<tr><td class="notice_info">'.$vignette;
+				$html.=$ligne["texte"].'</td></tr>';
+				$html.='</table></td></tr>';
+				$suite=true;
+			}
+		}
+		$html.='</table>';
+		return $html;
+	}
+
 }
 
 ?>
\ No newline at end of file
diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php
index 0e79abd71e6..16d916c69ec 100644
--- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php
+++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php
@@ -1020,4 +1020,61 @@ class NoticeAjaxControllerErrorTagsTest extends AbstractControllerTestCase {
 	}
 }
 
+
+
+
+class NoticeAjaxControllerBiographieTest extends AbstractControllerTestCase {
+	public function setUp() {
+		parent::setUp();
+
+		Class_Notice::newInstanceWithId(23, ['auteur_principal' => 'J.K Rowling',
+																				 'clef_oeuvre' => 'HARRY_POTTER']);
+
+		Class_CosmoVar::newInstanceWithId('url_services', ['valeur' => 'http://cache.org']);
+
+		Class_WebService_AllServices::setHttpClient($http_client = Storm_Test_ObjectWrapper::mock()
+																								->whenCalled('open_url')
+																								->with('http://cache.org'
+																											 .'?auteur='.urlencode('J.K Rowling')
+																											 .'&clef_oeuvre=HARRY_POTTER'
+																											 .'&src='.Class_WebService_AllServices::createSecurityKey()
+																											 .'&action=8')
+
+																								->answers(json_encode(['statut_recherche' => '0', 
+																																			 'source' => 'Wikipedia',
+																																			 'vignette' => 'rowling.jpg',
+																																			 'image' => 'rowling_big.jpg',
+																																			 'biographie' => [
+																																				 ['texte' => 'Auteur de H.Potter']
+																																				 ]
+																																				])));
+
+		$this->dispatch('/opac/noticeajax/biographie/id_notice/23', true);
+	}
+
+
+	/** @test */
+	public function htmlShouldContainsTDWithAuteurDeHarryPotter() {
+		$this->assertXPathContentContains('//td', 'Auteur de H.Potter', $this->_response->getBody());
+	}
+
+
+	/** @test */
+	public function imgShouldContainsRowlingDotJpg() {
+		$this->assertXPath('//img[@src="rowling.jpg"]');
+	}
+
+
+	/** @test */
+	public function anchorShouldContainsRowlingBigDotJpg() {
+		$this->assertXPath('//a[@href="rowling_big.jpg"]');
+	}
+
+
+	/** @test */
+	public function linkModifierLaBiographieShouldBeVisible() {
+		$this->assertXPathContentContains('//a', 'Modifier la biographie');
+	}
+}
+
 ?>
\ No newline at end of file
-- 
GitLab