From a1ea5511620a23d13c44db3ee06f50c4ab818b9e Mon Sep 17 00:00:00 2001
From: Ghislain Loas <ghislo@sandbox.pergame.net>
Date: Wed, 5 Nov 2014 11:45:24 +0100
Subject: [PATCH] dev #16652 disable cache on search widget when select_bib is
 enabled

---
 .../opac/controllers/BibController.php        |  1 -
 .../opac/views/scripts/bib/selection.phtml    |  3 +-
 .../Controller/Plugin/SelectionBib.php        |  2 +-
 .../View/Helper/Accueil/RechSimple.php        |  8 ++++
 .../View/Helper/Accueil/RechSimpleTest.php    | 40 +++++++++++++++++++
 .../View/Helper/TagRechercheSimpleTest.php    |  5 +--
 6 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/application/modules/opac/controllers/BibController.php b/application/modules/opac/controllers/BibController.php
index 6dd31c5fce5..7123dc1e0b9 100644
--- a/application/modules/opac/controllers/BibController.php
+++ b/application/modules/opac/controllers/BibController.php
@@ -88,7 +88,6 @@ class BibController extends ZendAfi_Controller_Action {
 
 
 	function selectionAction() {
-		xdebug_break();
 		$this->view->titre = $this->view->_('Sélection de bibliothèques pour la recherche');
 		$this->view->zones = Class_Zone::findAll();
 		$this->view->id_bibs_session = [];
diff --git a/application/modules/opac/views/scripts/bib/selection.phtml b/application/modules/opac/views/scripts/bib/selection.phtml
index a4369d215c5..c1400e2b730 100644
--- a/application/modules/opac/views/scripts/bib/selection.phtml
+++ b/application/modules/opac/views/scripts/bib/selection.phtml
@@ -14,7 +14,8 @@ foreach($this->zones as $zone )
 {
   echo '<li>' . $this->tag('h2', $zone->getLibelle());
 	$bibs = Class_Bib::findAllBy(['id_zone' => $zone->getId(),
-																'visibilite' => 2]);
+																'visibilite' => 2,
+																'order' => 'libelle']);
 	echo ('<ul>');
   foreach($bibs as $bib) {
     $coche = in_array($bib->getId(), $this->id_bibs_session) ? ['checked' => 'checked'] : [];
diff --git a/library/ZendAfi/Controller/Plugin/SelectionBib.php b/library/ZendAfi/Controller/Plugin/SelectionBib.php
index da03cd565f1..c612a17120d 100644
--- a/library/ZendAfi/Controller/Plugin/SelectionBib.php
+++ b/library/ZendAfi/Controller/Plugin/SelectionBib.php
@@ -101,7 +101,7 @@ class ZendAfi_Controller_Plugin_SelectionBib extends Zend_Controller_Plugin_Abst
 
 	protected function setIdBibsParams($request) {
 		if(! $id_bibs = $request->getParam('bib_select'))
-			return [];
+			return;
 
 		if(!is_array($id_bibs))
 			$id_bibs = explode(',', $id_bibs);
diff --git a/library/ZendAfi/View/Helper/Accueil/RechSimple.php b/library/ZendAfi/View/Helper/Accueil/RechSimple.php
index c68a6424862..4f81002c351 100644
--- a/library/ZendAfi/View/Helper/Accueil/RechSimple.php
+++ b/library/ZendAfi/View/Helper/Accueil/RechSimple.php
@@ -57,4 +57,12 @@ class ZendAfi_View_Helper_Accueil_RechSimple extends ZendAfi_View_Helper_Accueil
 																										 $this->division);
 		return $this->getHtmlArray();
 	}
+
+
+	public function shouldCacheContent() {
+		if ((int)$this->preferences["select_bib"] !== 1)
+			return parent::shouldCacheContent();
+
+		return false;
+	}
 }
\ No newline at end of file
diff --git a/tests/library/ZendAfi/View/Helper/Accueil/RechSimpleTest.php b/tests/library/ZendAfi/View/Helper/Accueil/RechSimpleTest.php
index 03cb2b7234e..3154c52c3ea 100644
--- a/tests/library/ZendAfi/View/Helper/Accueil/RechSimpleTest.php
+++ b/tests/library/ZendAfi/View/Helper/Accueil/RechSimpleTest.php
@@ -78,4 +78,44 @@ class ZendAfi_View_Helper_Accueil_RechSimpleWithoutAutocompleteTest extends Zend
 		$this->assertNotXPath($this->_head_script, '//script[contains(@src,"search_autocomplete.js")]');
 	}
 }
+
+
+
+class ZendAfi_View_Helper_Accueil_RechSimpleWithCacheActifTest extends ZendAfi_View_Helper_Accueil_RechSimpleTestCase {
+	public function setUp() {
+		parent::setUp();
+		Class_AdminVar::newInstanceWithId('CACHE_ACTIF', ['valeur' => '1']);
+
+	}
+
+
+	/** @test */
+	public function cacheContentShouldBeEnabled() {
+		$this->assertTrue($this->_helper->shouldCacheContent());
+	}
+}
+
+
+
+class ZendAfi_View_Helper_Accueil_RechSimpleWithCacheActifAndSelectBibEnabledTest extends ViewHelperTestCase {
+	public function setUp() {
+		parent::setUp();
+		Class_AdminVar::newInstanceWithId('CACHE_ACTIF', ['valeur' => '1']);
+		$this->_helper = new ZendAfi_View_Helper_Accueil_RechSimple(1,
+																																['division' => 1,
+																																 'type_module' => 'RECH_SIMPLE',
+																																 'preferences' => [
+																																									 'boite' => '',
+																																									 'titre' => 'Search widget',
+																																									 'select_bib' => '1']]);
+
+		$this->_helper->setView(new ZendAfi_Controller_Action_Helper_View());
+	}
+
+
+	/** @test */
+	public function cacheContentShouldBeDisabeld() {
+		$this->assertFalse($this->_helper->shouldCacheContent());
+	}
+}
 ?>
\ No newline at end of file
diff --git a/tests/library/ZendAfi/View/Helper/TagRechercheSimpleTest.php b/tests/library/ZendAfi/View/Helper/TagRechercheSimpleTest.php
index dd0447e093d..65140ed9c06 100644
--- a/tests/library/ZendAfi/View/Helper/TagRechercheSimpleTest.php
+++ b/tests/library/ZendAfi/View/Helper/TagRechercheSimpleTest.php
@@ -21,7 +21,7 @@
 
 require_once('ViewHelperTestCase.php');
 
-class ZendAfi_View_Helper_TagRechercheSimpleTest extends ViewHelperTestCase {
+class ZendAfi_View_Helper_TagRechercheSimpleDefaultTest extends ViewHelperTestCase {
 	/** @var ZendAfi_View_Helper_TagRechercheSimple */
 	protected $_helper;
 
@@ -33,7 +33,6 @@ class ZendAfi_View_Helper_TagRechercheSimpleTest extends ViewHelperTestCase {
 
 	public function setUp() {
 		parent::setUp();
-
 		$view = new ZendAfi_Controller_Action_Helper_View();
 		$this->_helper = new ZendAfi_View_Helper_TagRechercheSimple();
 		$this->_helper->setView($view);
@@ -77,7 +76,7 @@ class ZendAfi_View_Helper_TagRechercheSimpleTest extends ViewHelperTestCase {
 
 
 
-class ZendAfi_View_Helper_TagRechercheSimpleTestWithSessionParams extends ViewHelperTestCase {
+class ZendAfi_View_Helper_TagRechercheSimpleWithSessionParamsTest extends ViewHelperTestCase {
 
 	public function setUp() {
 		parent::setUp();
-- 
GitLab