From a608563b6a8ae8b4fd99794441834584b46bfc25 Mon Sep 17 00:00:00 2001
From: Ghislain Loas <ghislo@sandbox.pergame.net>
Date: Fri, 29 May 2015 15:56:19 +0200
Subject: [PATCH] sandbox fix RechercheControllerPrintActionTest

---
 .../scripts/recherche/resultatRecherche.phtml |  2 +-
 library/ZendAfi/View/Helper/TagPrintLink.php  |  4 ++-
 .../RechercheControllerPrintActionTest.php    | 31 ++++++++++++++-----
 3 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml b/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml
index ed283d33f09..354c53c86e7 100644
--- a/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml
+++ b/application/modules/opac/views/scripts/recherche/resultatRecherche.phtml
@@ -18,7 +18,7 @@ if ($this->is_pertinence) {
 ?>
 <div class="print">
 <?php
-echo $this->tagPrintLink($this->list, 'recherche');
+echo $this->tagPrintLink($this->liste, 'recherche');
 ?>
 </div>
 <div class="resultats_page">
diff --git a/library/ZendAfi/View/Helper/TagPrintLink.php b/library/ZendAfi/View/Helper/TagPrintLink.php
index 7bef27b3ee2..f1f6e777854 100644
--- a/library/ZendAfi/View/Helper/TagPrintLink.php
+++ b/library/ZendAfi/View/Helper/TagPrintLink.php
@@ -23,7 +23,9 @@
 class ZendAfi_View_Helper_TagPrintLink  extends Zend_View_Helper_HtmlElement {
 
 	public function tagPrintLink($models, $strategy) {
-		xdebug_break();
+		if(!$models)
+			return '';
+
 		if(!$model_fusion = Class_ModeleFusion::getFusionForStrategy($strategy))
 			return '';
 
diff --git a/tests/application/modules/opac/controllers/RechercheControllerPrintActionTest.php b/tests/application/modules/opac/controllers/RechercheControllerPrintActionTest.php
index 6862d9c3824..7f79c1385ab 100644
--- a/tests/application/modules/opac/controllers/RechercheControllerPrintActionTest.php
+++ b/tests/application/modules/opac/controllers/RechercheControllerPrintActionTest.php
@@ -20,10 +20,10 @@
  */
 
 class RechercheControllerPrintActionLinkTest extends AbstractControllerTestCase {
+	protected $_storm_default_to_volatile = true;
 
 	public function setUp() {
   parent::setUp();
-	Storm_Model_Loader::defaultToVolatile();
 
 	$this->fixture('Class_ModeleFusion', ['id' => 1,
 																				'nom' => 'recherche',
@@ -35,23 +35,32 @@ class RechercheControllerPrintActionLinkTest extends AbstractControllerTestCase
 										'libelle' => 'Nouveautés',
 										'auteur' => 'Paul']);
 
+		$mock_sql = $this->mock()
+										 ->whenCalled('fetchAllByColumn')
+										 ->answers([1])
+										 ->whenCalled('fetchOne')
+										 ->answers(1)
+										 ->whenCalled('fetchAll')
+										 ->answers([$this->fixture('Class_Notice',
+																							 ['id' => 1])->toArray()]);
+		Zend_Registry::set('sql', $mock_sql);
 		$this->dispatch('/recherche/simple/id_catalogue/3/id_module/9/aleatoire/1', true);
 	}
 
 
   /** @test */
 	public function printLinkShouldBePresent() {
-		$this->assertXPathContentContains('//a[contains(@href, "/recherche/print/id_catalogue/3/id_module/9/aleatoire/1/strategy/recherche/modele_fusion/1")]', 'Imprimer', $this->_response->getBody());
+		$this->assertXPathContentContains('//a[contains(@href, "/recherche/print/id_catalogue/3/id_module/9/aleatoire/1/ids/1/strategy/recherche/modele_fusion/1")]', 'Imprimer');
 	}
 }
 
 
 
 class RechercheControllerPrintActionWithRecordsTest extends AbstractControllerTestCase {
+	protected $_storm_default_to_volatile = true;
 
 	public function setUp() {
   parent::setUp();
-	Storm_Model_Loader::defaultToVolatile();
 
 	$this->fixture('Class_ModeleFusion', ['id' => 1,
 																				'nom' => 'recherche',
@@ -71,15 +80,23 @@ class RechercheControllerPrintActionWithRecordsTest extends AbstractControllerTe
 																																					'notice' => new Class_Notice(),
 																																					'type_doc_id' => Class_TypeDoc::ARTICLE]));
 
-  $this->dispatch("/recherche/print/expressionRecherche/pomme/strategy/notice/ids/1%3B2/modele_fusion/1",true);
+  $this->dispatch("/recherche/print/expressionRecherche/pomme/strategy/recherche/ids/1%3B2/modele_fusion/1",true);
 	}
 
-	public function tearDown() {
-		Storm_Model_Loader::defaultToDb();
-		parent::tearDown();
+
+	/** @test */
+	public function articlePommeShouldBeIndexed() {
+		$this->assertNotNull(Class_Notice::findFirstBy(['titres' => 'POMME']));
 	}
 
 
+	/** @test */
+	public function recordPommeShouldBeLinkedToPommeArticle() {
+		$this->assertNotNull(Class_Notice::findFirstBy(['titres' => 'POMME'])->getArticle());
+	}
+
+
+
 	/** @test */
 	public function displayShouldprintContent() {
 		$this->assertXPathContentContains("//div//p", "bd", $this->_response->getBody());
-- 
GitLab