From 66ce157dc34a358733a893191add71ebbd9af490 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Tue, 5 Jun 2012 16:52:11 +0000
Subject: [PATCH] =?UTF-8?q?Correction=20recherche=20oai=20co=CC=82te=CC=81?=
 =?UTF-8?q?=20opac?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../controllers/RechercheoaiController.php    | 53 +++++++---------
 .../modules/opac/views/scripts/footer.phtml   |  2 +-
 .../modules/opac/views/scripts/head.phtml     |  2 +-
 .../views/scripts/rechercheoai/index.phtml    |  2 +-
 .../views/scripts/rechercheoai/resultat.phtml | 23 ++++---
 library/Class/NoticeOAI.php                   |  8 ++-
 .../modules/AbstractControllerTestCase.php    |  2 +-
 .../admin/controllers/OaiControllerTest.php   |  9 +--
 .../opac/controllers/OAIControllerTest.php    | 62 +++++++++++++++++++
 9 files changed, 110 insertions(+), 53 deletions(-)

diff --git a/application/modules/opac/controllers/RechercheoaiController.php b/application/modules/opac/controllers/RechercheoaiController.php
index 5a731598bef..0cbca41d050 100644
--- a/application/modules/opac/controllers/RechercheoaiController.php
+++ b/application/modules/opac/controllers/RechercheoaiController.php
@@ -22,46 +22,37 @@
 // OPAC3 - Controleur pour les recherches OAI
 //////////////////////////////////////////////////////////////////////////////////////////
 
-class RechercheoaiController extends Zend_Controller_Action
-{
-  								
-//------------------------------------------------------------------------------------------------------
-// Initialisation du controler
-//------------------------------------------------------------------------------------------------------
-	function init()
-	{
-		
-	}
-
-//------------------------------------------------------------------------------------------------------
-// INDEX
-//------------------------------------------------------------------------------------------------------
-	function indexAction()
-	{
+class RechercheoaiController extends Zend_Controller_Action {
+	function indexAction() {
 		$cls_oai=new Class_NoticeOAI();
 		$this->view->statut=$_REQUEST["statut"];
 		$this->view->id_entrepot=$_REQUEST["id_entrepot"];
 		$this->view->entrepots =$cls_oai->getEntrepots();
 	}
 
-//------------------------------------------------------------------------------------------------------
-// RESULTAT DE LA RECHERCHE
-//------------------------------------------------------------------------------------------------------
-	function resultatAction()
-	{
+
+	function resultatAction()	{
     $cls_oai=new Class_NoticeOAI();
 		$this->view->entrepots =$cls_oai->getEntrepots();
-		$this->view->expressionRecherche = $_REQUEST["expressionRecherche"];
-		$this->view->id_entrepot=$_REQUEST["id_entrepot"];
-		$resultat=$cls_oai->recherche($_REQUEST);
-		if($resultat["statut"]=="erreur") $this->view->erreur=$resultat["erreur"];
-		else
-		{
-			$this->view->recherche=$_REQUEST["expressionRecherche"];
-			$this->view->notices=$cls_oai->getPageResultat($resultat["req_liste"], $this->_getParam('page'));
-			$this->view->nombre=$resultat["nombre"];
+
+		$this->view->expressionRecherche = $this->_getParam("expressionRecherche", '');
+		$this->view->id_entrepot = $this->_getParam("id_entrepot", 0);
+
+		$params_recherche = array('expressionRecherche' => $this->view->expressionRecherche);
+		if ($this->view->id_entrepot)
+			$params_recherche['id_entrepot'] = $this->view->id_entrepot;
+
+		$resultat = $cls_oai->recherche($params_recherche);
+
+		if (isset($resultat["statut"])) {
+			$this->view->erreur=$resultat["erreur"];
+		}	else	{
+			$this->view->recherche = $this->_getParam("expressionRecherche", '');
+			$this->view->notices = $cls_oai->getPageResultat($resultat["req_liste"], 
+																											 $this->_getParam('page'));
+			$this->view->nombre = $resultat["nombre"];
 			$this->view->page = $this->_getParam('page');
-			$this->view->url_retour=BASE_URL."/rechercheoai/resultat?expressionRecherche=".$_REQUEST["expressionRecherche"]."&id_entrepot=".$_REQUEST["id_entrepot"];
+			$this->view->url_retour = $this->view->url($params_recherche);
 		}
 	}
 
diff --git a/application/modules/opac/views/scripts/footer.phtml b/application/modules/opac/views/scripts/footer.phtml
index 0e9fdbf5929..f8e893b3998 100644
--- a/application/modules/opac/views/scripts/footer.phtml
+++ b/application/modules/opac/views/scripts/footer.phtml
@@ -21,6 +21,6 @@
 		</table>
 	</div>
 </div>
-  <?php echo getVar('GOOGLE_ANALYTICS'); ?>
+<?php echo Class_AdminVar::get('GOOGLE_ANALYTICS'); ?>
 </body>
 </html>
diff --git a/application/modules/opac/views/scripts/head.phtml b/application/modules/opac/views/scripts/head.phtml
index 06804e72ab8..7b0b8657453 100644
--- a/application/modules/opac/views/scripts/head.phtml
+++ b/application/modules/opac/views/scripts/head.phtml
@@ -51,7 +51,7 @@ if ($this->accessibilite_on) {  //Feuilles de styles pour les déficiences visue
 		->addJQueryReady('initAccessibilityOptions();');
 }
 
-if (getVar('ID_READ_SPEAKER'))
+if (Class_AdminVar::get('ID_READ_SPEAKER'))
 	$head_scripts
 		->addJQueryReady(sprintf('$.getScript("http://wr.readspeaker.com/webreader/webreader.js.php?cid=%s")',
 														 getVar('ID_READ_SPEAKER')));
diff --git a/application/modules/opac/views/scripts/rechercheoai/index.phtml b/application/modules/opac/views/scripts/rechercheoai/index.phtml
index ba90ddced29..4241d70915e 100644
--- a/application/modules/opac/views/scripts/rechercheoai/index.phtml
+++ b/application/modules/opac/views/scripts/rechercheoai/index.phtml
@@ -2,7 +2,7 @@
 $this->openBoite("Recherche OAI");
 ?>
 <center>
-<form name="form" action="<?php echo BASE_URL ?>/opac/rechercheoai/resultat" method="post">
+<form name="form" action="<?php echo BASE_URL ?>/opac/rechercheoai/resultat" method="get">
 	<table width="100%">
 		<tr>
 			<td>
diff --git a/application/modules/opac/views/scripts/rechercheoai/resultat.phtml b/application/modules/opac/views/scripts/rechercheoai/resultat.phtml
index b6dfe5559bb..f30c97c6ea8 100644
--- a/application/modules/opac/views/scripts/rechercheoai/resultat.phtml
+++ b/application/modules/opac/views/scripts/rechercheoai/resultat.phtml
@@ -14,20 +14,25 @@ else
   else 
     $texte=$this->_("%s notices trouvées", $this->nombre);
 	echo BR.'<div class="liste_vignette">'.$texte.'</div>';
-	foreach($this->notices as $notice)
-	{
+	foreach($this->notices as $notice) {
 		echo '<div class="liste_vignette"><table width="100%">';
-		echo '<tr><td align="right" style="width:10%" valign="top">Titre : </td><td><a href="'.$this->url(array('action' => 'viewnotice', 'id' => $notice["id"])).'" target="_blank">'.$notice["titre"].'</a></td></tr>';
+		echo '<tr><td align="right" style="width:10%" valign="top">Titre : </td><td><a href="'.$this->url(array('action' => 'viewnotice', 'id' => $notice->getId())).'" target="_blank">'.$notice->getTitre().'</a></td></tr>';
 
     $line_format = '<tr><td align="right"  valign="top">%s</td><td>%s</td></tr>';
-		if($notice["auteur"]) printf($line_format, $this->_('Auteur :'), $notice["auteur"]);
-		if($notice["editeur"]) printf($line_format, $this->_('Editeur :'), $notice["editeur"]);
-		if($notice["date"]) printf($line_format, $this->_('Publié en :'), $notice["date"]);
 
-    //P.... de b.... de m..... faudrait arrêter d'écrire de la m..... quand même...... Laurent
-    printf($line_format, $this->_('Source :'), fetchOne("select libelle from oai_entrepots where id=".$notice["source"]));
+		if ($notice->hasAuteur()) 
+			printf($line_format, $this->_('Auteur :'), $notice->getAuteur());
+
+		if ($notice->hasEditeur()) 
+			printf($line_format, $this->_('Editeur :'), $notice->getEditeur());
+
+		if($notice->hasDate()) 
+			printf($line_format, $this->_('Publié en :'), $notice->getDate());
+
+    printf($line_format, $this->_('Source :'), $notice->getLibelleEntrepot());
 		echo '</table></div>';
 	 }
-	 echo '<br/><div style="width:100%;text-align:center;">'.$this->pager($this->nombre,10,$this->page,$this->url_retour).'</div>';
+
+	echo '<br/><div style="width:100%;text-align:center;">'.$this->pager($this->nombre,10,$this->page,$this->url_retour).'</div>';
 }
 ?>
\ No newline at end of file
diff --git a/library/Class/NoticeOAI.php b/library/Class/NoticeOAI.php
index 1ff8aadf397..d4d7ff39444 100644
--- a/library/Class/NoticeOAI.php
+++ b/library/Class/NoticeOAI.php
@@ -40,7 +40,8 @@ class Class_NoticeOAI extends Storm_Model_Abstract {
 	protected $_table_notices;
 	protected $_oai_service;
 	protected $_entrepot_oai;
-	protected $_default_attribute_values = array('data' => '');
+	protected $_default_attribute_values = array('data' => '', 
+																							 'date' => '');
 
 
 	public static function getLoader() {
@@ -98,6 +99,11 @@ class Class_NoticeOAI extends Storm_Model_Abstract {
 	}
 
 
+	public function getEditeur() {
+		return $this->extractData('editeur');
+	}
+
+
 	public function extractData($name) {
 	  $datas = $this->getDataAsArray();
 		return isset($datas[$name]) ? $datas[$name] : '';
diff --git a/tests/application/modules/AbstractControllerTestCase.php b/tests/application/modules/AbstractControllerTestCase.php
index d57de44eaf6..a9b5d00b73f 100644
--- a/tests/application/modules/AbstractControllerTestCase.php
+++ b/tests/application/modules/AbstractControllerTestCase.php
@@ -161,7 +161,7 @@ abstract class AbstractControllerTestCase extends Zend_Test_PHPUnit_ControllerTe
 			->setMethod('POST')
 			->setPost($data);
 
-		return $this->dispatch($url);
+		return $this->dispatch($url, true);
 	}
 
 	/**
diff --git a/tests/application/modules/admin/controllers/OaiControllerTest.php b/tests/application/modules/admin/controllers/OaiControllerTest.php
index 3a664f1116a..e0cd49bea3d 100644
--- a/tests/application/modules/admin/controllers/OaiControllerTest.php
+++ b/tests/application/modules/admin/controllers/OaiControllerTest.php
@@ -192,16 +192,9 @@ class Admin_OaiControllerImportIsaacAsimovFoundationTest extends Admin_OaiContro
 abstract class Admin_OaiControllerSearchActionTestCase extends Admin_OaiControllerTestCase  {
 	public function setUp() {
 		parent::setUp();
-		$this->old_sql = Zend_Registry::get('sql');
-		$this->mock_sql = Storm_Test_ObjectWrapper::on($this->old_sql);
+		$this->mock_sql = Storm_Test_ObjectWrapper::on(Zend_Registry::get('sql'));
 		Zend_Registry::set('sql', $this->mock_sql);
 	}
-
-
-	public function tearDown() {
-		Zend_Registry::set('sql', $this->old_sql);
-		parent::tearDown();
-	}
 }
 
 
diff --git a/tests/application/modules/opac/controllers/OAIControllerTest.php b/tests/application/modules/opac/controllers/OAIControllerTest.php
index 06006fc3202..5c3a18bb1e8 100644
--- a/tests/application/modules/opac/controllers/OAIControllerTest.php
+++ b/tests/application/modules/opac/controllers/OAIControllerTest.php
@@ -146,6 +146,68 @@ class OaiControllerUnknownVerbRequestTest extends OaiControllerRequestTestCase {
 																							'//oai:error[@code="badVerb"]',
 																							'Illegal OAI verb');
 	}
+}
+
+
+
+
+class OAIControllerResultatActionTest extends AbstractControllerTestCase  {
+	public function setUp() {
+		parent::setUp();
+		$this->mock_sql = Storm_Test_ObjectWrapper::on(Zend_Registry::get('sql'));
+		Zend_Registry::set('sql', $this->mock_sql);
+
+		$this->mock_sql
+			->whenCalled('fetchOne')
+			->with('select count(*) from exemplaires')
+			->answers(0)
+
+			->whenCalled('fetchAll')
+			->with("select distinct(id_entrepot) from oai_notices", false)
+			->answers(array(array('id_entrepot' => 1)))
+
+
+			->whenCalled('fetchOne')
+			->with("select libelle from oai_entrepots where id=1")
+			->answers('Gallica')
+
+			->whenCalled('fetchOne')
+			->with("Select count(*) from oai_notices where MATCH(recherche) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE)")
+			->answers(1)
+
+			->whenCalled('fetchAll')
+			->with("select id from oai_notices where MATCH(recherche) AGAINST('+(POMME POMMES POM)' IN BOOLEAN MODE) order by alpha_titre LIMIT 0,10",
+						 false)
+			->answers(array(array('id' => 2)))
+			->beStrict();
 
+		$pommes = Class_NoticeOAI::getLoader()
+			->newInstanceWithId(2)
+			->setTitre('Mangez des pommes')
+			->setEntrepot(Class_EntrepotOAI::getLoader()
+										->newInstanceWithId(3)
+										->setLibelle('Gallica'));
+
+		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_NoticeOAI')
+			->whenCalled('findAllBy')
+			->with(array('id' => array(2)))
+			->answers(array($pommes))
+			->beStrict();
+
+		$this->dispatch('/opac/rechercheoai/resultat/expressionRecherche/pomme', true);
+	}
+
+
+	public function tearDown() {
+		Zend_Registry::set('sql', $this->old_sql);
+		parent::tearDown();
+	}
+
+
+	/** @test */
+	public function tdShouldContainsMangezDesPommes() {
+		$this->assertXPathContentContains('//td', 'Mangez des pommes', $this->_response->getBody());
+	}
 }
+
 ?>
\ No newline at end of file
-- 
GitLab