From b084d95e7438c06211ffa0a64115ad56e5ad72b2 Mon Sep 17 00:00:00 2001 From: lbrun <leo@sandbox.pergame.net> Date: Wed, 18 Nov 2015 17:22:36 +0100 Subject: [PATCH] dev#23223_sito_widget_pagination: test for cache --- .../opac/controllers/SitoController.php | 1 - library/ZendAfi/View/Helper/Accueil/Sito.php | 12 ++---- .../ZendAfi/View/Helper/Accueil/SitoTest.php | 42 +++++++++++++++++++ 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/application/modules/opac/controllers/SitoController.php b/application/modules/opac/controllers/SitoController.php index 767cff1bce9..b5a0a6eb072 100644 --- a/application/modules/opac/controllers/SitoController.php +++ b/application/modules/opac/controllers/SitoController.php @@ -107,7 +107,6 @@ class SitoController extends Zend_Controller_Action { $helper = new ZendAfi_View_Helper_Accueil_Sito($id_module, $module_params); $helper->setPage($page); $helper->setView($this->view); - $helper->disableCache(); $this->view->sito_helper = $helper; $viewRenderer = $this->getHelper('ViewRenderer'); diff --git a/library/ZendAfi/View/Helper/Accueil/Sito.php b/library/ZendAfi/View/Helper/Accueil/Sito.php index ee340700e3b..642bc18cf97 100644 --- a/library/ZendAfi/View/Helper/Accueil/Sito.php +++ b/library/ZendAfi/View/Helper/Accueil/Sito.php @@ -27,7 +27,7 @@ class ZendAfi_View_Helper_Accueil_Sito extends ZendAfi_View_Helper_Accueil_Base const DISPLAY_GROUPED = 2; const DISPLAY_HIERARCHY = 3; - protected $strategy, $page, $disable_cache = false; + protected $strategy, $page; protected function _renderHeadScriptsOn($script_loader) { $this->getStrategy()->renderHeadScriptsOn($script_loader); @@ -35,9 +35,9 @@ class ZendAfi_View_Helper_Accueil_Sito extends ZendAfi_View_Helper_Accueil_Base public function shouldCacheContent() { - if ($this->disable_cache) - return false; - return parent::shouldCacheContent(); + return $this->isTypeAffichagePaged() + ? false + : parent::shouldCacheContent(); } @@ -98,10 +98,6 @@ class ZendAfi_View_Helper_Accueil_Sito extends ZendAfi_View_Helper_Accueil_Base $this->page = $page; return $this; } - - public function disableCache() { - $this->disable_cache = true; - } } diff --git a/tests/library/ZendAfi/View/Helper/Accueil/SitoTest.php b/tests/library/ZendAfi/View/Helper/Accueil/SitoTest.php index d2a2eeaef84..bb4c7e962b8 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/SitoTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/SitoTest.php @@ -33,6 +33,12 @@ abstract class SitoViewHelperTestCase extends ViewHelperTestCase { public function setUp() { parent::setUp(); + Storm_Cache::beVolatile(); + $this->fixture('Class_AdminVar', + ['id' => 'CACHE_ACTIF', + 'valeur' => '1' + ]); + Class_AdminVar::newInstanceWithId('BLUGA_API_KEY', ['valeur' => ''])->save(); $this->_belgique = $this->fixture('Class_SitothequeCategorie', @@ -188,6 +194,42 @@ class SitoViewHelperSelectItemsBySelectionOrderPaginationTest extends SitoViewHe +class SitoViewHelperWithoutCacheTest extends SitoViewHelperTestCase { + protected $_preferences = ['titre' => 'Ma sito', + 'type_aff' => 1, + 'id_items' => '12-15', + 'id_categorie' => '', + 'nb_aff' => 1, + 'display_order' => 'Selection']; + + /** @test */ + public function cacheShouldNotBeUse() { + $value = (new Storm_Cache())->getCache()->load('b0ca57808f9be79c82d794dd6ff37979'); + $this->assertFalse($value); + } +} + + + + +class SitoViewHelperCachedTest extends SitoViewHelperTestCase { + protected $_preferences = ['titre' => 'Ma sito', + 'type_aff' => 2, + 'id_items' => '12-15', + 'id_categorie' => '', + 'nb_aff' => 1, + 'display_order' => 'Selection']; + + /** @test */ + public function cacheShouldBeUse() { + $value = (new Storm_Cache())->getCache()->load('7d8b4403c83a27920e6e1767ee9132e5'); + $this->assertNotEquals(false, $value); + } +} + + + + class SitoViewHelperSelectItemsByRandomOrderTest extends SitoViewHelperTestCase { protected $_preferences = ['titre' => 'Ma sito', 'type_aff' => 1, -- GitLab