From 57973f539efd54eb53132160af0166bb6c182a90 Mon Sep 17 00:00:00 2001 From: gloas <gloas@git-test.afi-sa.fr> Date: Fri, 19 Jul 2013 09:58:22 +0000 Subject: [PATCH] correction tests cache --- library/Class/CriteresRecherche.php | 33 +++++++++++++++---- library/Class/MoteurRecherche.php | 5 +++ .../Class/WebService/SIGB/EmprunteurCache.php | 4 +-- .../View/Helper/TagCVSCriteresRecherche.php | 7 ++-- .../View/Helper/TagCriteresRecherche.php | 4 +++ .../modules/AbstractControllerTestCase.php | 1 + .../modules/opac/controllers/CalendarTest.php | 11 +++++-- .../opac/controllers/JavaControllerTest.php | 1 + .../OAIControllerListIdentifiersTest.php | 8 +---- tests/library/Class/CommSigbTest.php | 9 ++--- tests/library/Class/UsersTest.php | 6 ++-- .../WebService/SIGB/EmprunteurCacheTest.php | 20 ++++------- .../ZendAfi/View/Helper/Accueil/CacheTest.php | 8 +++++ .../View/Helper/Accueil/CalendarTest.php | 13 ++++---- .../View/Helper/Accueil/KiosqueTest.php | 8 +++-- 15 files changed, 83 insertions(+), 55 deletions(-) diff --git a/library/Class/CriteresRecherche.php b/library/Class/CriteresRecherche.php index a99a9ad069a..4566d8f7394 100644 --- a/library/Class/CriteresRecherche.php +++ b/library/Class/CriteresRecherche.php @@ -244,18 +244,37 @@ class Class_CriteresRecherche { } - public function visitByRechercheType($visitor) { - if (($catalogue = $this->getCatalogue()) && !$this->getCodeRebond()) - $this->visitCatalogue($visitor,$catalogue); + public function isRechercheCatalogueOuPanier() { + return (!$this->getCodeRebond()) + && ($this->getParam('id_catalogue') || $this->getParam('id_panier')); + } + - else if (($panier = $this->getPanier()) && !$this->getCodeRebond() && ($notices = $panier->getClesNotices())) - $visitor->visitClesNotices($notices); + public function visitPanierCatalogue($visitor) { + if (!$this->isRechercheCatalogueOuPanier()) + return $this; - else if (!$panier && !$catalogue && ( $this->getParam('id_catalogue') || $this->getParam('id_panier'))) { - $visitor->setErreur($this->_('La sélection ne contient aucune notice')); + if ($catalogue = $this->getCatalogue()) { + $this->visitCatalogue($visitor,$catalogue); return $this; } + if (($panier = $this->getPanier()) && ($notices = $panier->getClesNotices())) { + $visitor->visitClesNotices($notices); + return $this; + } + + $visitor->setErreur($this->_('La sélection ne contient aucune notice')); + return $this; + } + + + public function visitByRechercheType($visitor) { + $this->visitPanierCatalogue($visitor); + + if ($visitor->hasErreur()) + return $this; + if ($code_rebond = $this->getCodeRebond()) { $visitor->visitCodeRebond($code_rebond); return $this; diff --git a/library/Class/MoteurRecherche.php b/library/Class/MoteurRecherche.php index 998e806c4dd..6add4347a1e 100644 --- a/library/Class/MoteurRecherche.php +++ b/library/Class/MoteurRecherche.php @@ -59,6 +59,11 @@ class Class_MoteurRecherche { $this->erreur["erreur"] = $this->_($message); } + + public function hasErreur() { + return isset($this->erreur["statut"]) && ('erreur' == $this->erreur["statut"]); + } + public function visitExpression($expression,$pertinence,$tri) { // Analyse de l'expression diff --git a/library/Class/WebService/SIGB/EmprunteurCache.php b/library/Class/WebService/SIGB/EmprunteurCache.php index 14153b69469..f761b315ebc 100644 --- a/library/Class/WebService/SIGB/EmprunteurCache.php +++ b/library/Class/WebService/SIGB/EmprunteurCache.php @@ -58,7 +58,7 @@ class Class_WebService_SIGB_EmprunteurCache { * @return Class_WebService_SIGB_Emprunteur */ public function load($user) { - return unserialize($this->_cache->load($this->keyFor($user))); + return $this->_cache->load($this->keyFor($user)); } @@ -68,7 +68,7 @@ class Class_WebService_SIGB_EmprunteurCache { * @return Class_WebService_SIGB_Emprunteur */ public function save($user, $emprunteur) { - $this->_cache->save(serialize($emprunteur), $this->keyFor($user)); + $this->_cache->save($emprunteur, $this->keyFor($user)); return $emprunteur; } diff --git a/library/ZendAfi/View/Helper/TagCVSCriteresRecherche.php b/library/ZendAfi/View/Helper/TagCVSCriteresRecherche.php index 9d78840aa5b..4852314d98e 100644 --- a/library/ZendAfi/View/Helper/TagCVSCriteresRecherche.php +++ b/library/ZendAfi/View/Helper/TagCVSCriteresRecherche.php @@ -60,17 +60,16 @@ class ZendAfi_View_Helper_TagCVSCriteresRecherche extends Zend_View_Helper_HtmlE } public function visitNouveaute($nouveaute) { - - return; - - } public function visitClesNotices($cles_notices) { } public function setErreur($message) { + } + public function hasErreur() { + return false; } public function visitRubrique($rubrique,$fil) { diff --git a/library/ZendAfi/View/Helper/TagCriteresRecherche.php b/library/ZendAfi/View/Helper/TagCriteresRecherche.php index c3987b7bef0..f0fd53569cd 100644 --- a/library/ZendAfi/View/Helper/TagCriteresRecherche.php +++ b/library/ZendAfi/View/Helper/TagCriteresRecherche.php @@ -85,6 +85,10 @@ class ZendAfi_View_Helper_TagCriteresRecherche extends Zend_View_Helper_HtmlElem } + public function hasErreur() { + return false; + } + public function visitRubrique($rubrique,$fil) { } diff --git a/tests/application/modules/AbstractControllerTestCase.php b/tests/application/modules/AbstractControllerTestCase.php index 073a92c4b44..db2d282e07f 100644 --- a/tests/application/modules/AbstractControllerTestCase.php +++ b/tests/application/modules/AbstractControllerTestCase.php @@ -134,6 +134,7 @@ abstract class AbstractControllerTestCase extends Zend_Test_PHPUnit_ControllerTe Class_AdminVar::newInstanceWithId('GOOGLE_ANALYTICS', ['valeur' => '']); ZendAfi_Controller_Action_Helper_TrackEvent::setDefaultWebAnalyticsClient(null); + Storm_Cache::setDefaultZendCache(null); } diff --git a/tests/application/modules/opac/controllers/CalendarTest.php b/tests/application/modules/opac/controllers/CalendarTest.php index ea6bc7d3b4b..2ccd6167cdb 100644 --- a/tests/application/modules/opac/controllers/CalendarTest.php +++ b/tests/application/modules/opac/controllers/CalendarTest.php @@ -74,12 +74,17 @@ class CalendarTestCase extends AbstractControllerTestCase { * @test */ function calendarShouldNotBeInAnIframeEventWithCacheActive() { - Class_AdminVar::getLoader()->find('CACHE_ACTIF')->setValeur(true); - Zend_Registry::get('cache')->clean(Zend_Cache::CLEANING_MODE_ALL); + + $cache = Storm_Test_ObjectWrapper::mock(); + Storm_Cache::setDefaultZendCache($cache); + + // Class_AdminVar::getLoader()->find('CACHE_ACTIF')->setValeur(true); + + // Zend_Registry::get('cache')->clean(Zend_Cache::CLEANING_MODE_ALL); $module_cal = new ZendAfi_View_Helper_Accueil_Calendar(1, $this->cfg_accueil['modules']['1']); $module_cal->setView(new ZendAfi_Controller_Action_Helper_View()); - $cache_key = $module_cal->getCacheKey(); + $cache_key = md5(serialize($module_cal->getCacheKey())); $this->dispatch('/cms/calendar/?id_profil=3&id_module=1&cachekey='.$cache_key); // ça plantait lors de la réutilisation du cache, donc 2 dispatchs diff --git a/tests/application/modules/opac/controllers/JavaControllerTest.php b/tests/application/modules/opac/controllers/JavaControllerTest.php index 4b4625b85f7..978fc05f060 100644 --- a/tests/application/modules/opac/controllers/JavaControllerTest.php +++ b/tests/application/modules/opac/controllers/JavaControllerTest.php @@ -60,6 +60,7 @@ class JavaControllerWidthDefaultKiosqueTest extends AbstractControllerTestCase { class JavaControllerWithKiosqueMurPageTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); + $cfg_accueil = ['modules' => ['1' => ['division' => 1, 'type_module' => 'KIOSQUE', 'preferences' => ['style_liste' => 'mur', diff --git a/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php b/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php index 41fb33acb40..f7a2f10ace6 100644 --- a/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php +++ b/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php @@ -377,19 +377,13 @@ class OAIControllerListIdentifiersWithoutDataFoundTest extends AbstractControlle $this->_cache = Storm_Test_ObjectWrapper::mock() ->whenCalled('save') ->answers(true); - - Class_WebService_OAI_ResumptionToken::defaultCache($this->_cache); + Storm_Cache::setDefaultZendCache($this->_cache); $this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork'); $this->_xml = $this->_response->getBody(); } - public function tearDown() { - Class_WebService_OAI_ResumptionToken::defaultCache(null); - parent::tearDown(); - } - /** @test */ public function responseShouldCountainsErrorNoRecordMatch() { diff --git a/tests/library/Class/CommSigbTest.php b/tests/library/Class/CommSigbTest.php index 0f255b9b2e3..ab4da79c678 100644 --- a/tests/library/Class/CommSigbTest.php +++ b/tests/library/Class/CommSigbTest.php @@ -44,20 +44,15 @@ abstract class CommSigbTestCase extends Storm_Test_ModelTestCase { ->setIdSite(5) ->setIdabon('0123456789'); - $this->_old_zend_cache = Zend_Registry::get('cache'); - Zend_Registry::set('cache', $this->zend_cache = Storm_Test_ObjectWrapper::mock()); + $this->zend_cache = Storm_Test_ObjectWrapper::mock(); $this->zend_cache ->whenCalled('test')->answers(false) ->whenCalled('remove')->answers(true) ->whenCalled('save')->answers(true); + Storm_Cache::setDefaultZendCache($this->zend_cache); } - public function tearDown() { - Zend_Registry::set('cache', $this->_old_zend_cache); - parent::tearDown(); - } - /** @test */ public function getDispoExemplairesShouldReturnAnArrayWithPotterInfos() { diff --git a/tests/library/Class/UsersTest.php b/tests/library/Class/UsersTest.php index 87758ef061a..371bb9834cd 100644 --- a/tests/library/Class/UsersTest.php +++ b/tests/library/Class/UsersTest.php @@ -612,6 +612,8 @@ class UsersFicheAbonneTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); + Storm_Cache::setDefaultZendCache(null); + $this->bib_astro = Class_IntBib::getLoader() ->newInstanceWithId(5) ->setCommParams(array("url_serveur" => 'http://astrolabe.com/opsys.wsdl')) @@ -631,15 +633,15 @@ class UsersFicheAbonneTest extends Storm_Test_ModelTestCase { ->setLogin('amadou') ->setIdSite(5) ->setIdabon(123); - Class_WebService_SIGB_EmprunteurCache::newInstance()->remove($this->amadou); - $this->pret_potter = Class_WebService_SIGB_Emprunt::newInstanceWithEmptyExemplaire() ->setTitre('Harry Potter') ->setDateRetour('23/05/2022'); + $this->pret_alice = Class_WebService_SIGB_Emprunt::newInstanceWithEmptyExemplaire() ->setTitre('Alice pays merveille') ->setDateRetour('23/05/2001'); + $this->pret_alien = Class_WebService_SIGB_Emprunt::newInstanceWithEmptyExemplaire() ->setTitre('Alien') ->setDateRetour('23/05/2002'); diff --git a/tests/library/Class/WebService/SIGB/EmprunteurCacheTest.php b/tests/library/Class/WebService/SIGB/EmprunteurCacheTest.php index 707d571ace6..4dd888f8b81 100644 --- a/tests/library/Class/WebService/SIGB/EmprunteurCacheTest.php +++ b/tests/library/Class/WebService/SIGB/EmprunteurCacheTest.php @@ -20,7 +20,7 @@ */ class EmprunteurCacheTest extends Storm_Test_ModelTestCase { - protected $_old_zend_cache; + protected $_cache; public function setUp() { parent::setUp(); @@ -40,9 +40,9 @@ class EmprunteurCacheTest extends Storm_Test_ModelTestCase { ->with($this->user_steven) ->answers($this->emprunteur_steven); - $this->_old_zend_cache = Zend_Registry::get('cache'); - Zend_Registry::set('cache', $this->zend_cache = Storm_Test_ObjectWrapper::mock()); - $this->zend_cache + $this->_cache = Storm_Test_ObjectWrapper::mock(); + Storm_Cache::setDefaultZendCache($this->_cache); + $this->_cache ->whenCalled('test')->answers(false) ->whenCalled('load')->answers(false) ->whenCalled('remove')->answers(false) @@ -56,12 +56,6 @@ class EmprunteurCacheTest extends Storm_Test_ModelTestCase { } - public function tearDown() { - Zend_Registry::set('cache', $this->_old_zend_cache); - parent::tearDown(); - } - - /** @test */ public function isInCacheShouldReturnFalseForSteven() { $this->assertFalse($this->emprunteur_cache->isCached($this->user_steven)); @@ -80,7 +74,7 @@ class EmprunteurCacheTest extends Storm_Test_ModelTestCase { $this->emprunteur_cache->loadFromCacheOrSIGB($this->user_steven, $this->sigb)); $this->assertEquals(array(serialize($this->emprunteur_steven), md5('emprunteur_666')), - $this->zend_cache->getAttributesForLastCallOn('save')); + $this->_cache->getAttributesForLastCallOn('save')); } @@ -101,7 +95,7 @@ class EmprunteurCacheTest extends Storm_Test_ModelTestCase { /** @test */ public function removeJohnnyShouldCallRemoveOnCache() { $this->emprunteur_cache->remove($this->user_johnny); - $this->assertTrue($this->zend_cache->methodHasBeenCalled('remove')); + $this->assertTrue($this->_cache->methodHasBeenCalled('remove')); } @@ -111,7 +105,7 @@ class EmprunteurCacheTest extends Storm_Test_ModelTestCase { $this->assertEquals($this->emprunteur_johnny, $this->emprunteur_cache->loadFromCacheOrSIGB($this->user_johnny, $this->sigb)); - $this->assertFalse($this->zend_cache->methodHasBeenCalled('save')); + $this->assertFalse($this->_cache->methodHasBeenCalled('save')); } } diff --git a/tests/library/ZendAfi/View/Helper/Accueil/CacheTest.php b/tests/library/ZendAfi/View/Helper/Accueil/CacheTest.php index 288d9716552..ceab184eecd 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/CacheTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/CacheTest.php @@ -26,6 +26,9 @@ class CacheWithCritiquesTest extends ViewHelperTestCase { public function setUp() { parent::setUp(); + $cfg = new Zend_Config(['sgbd'=>['config'=>['dbname'=>'dbTest']]]); + setupCache($cfg); + $params = array('type_module' => 'CRITIQUES', 'division' => 2, 'preferences' => array('boite' => 'boite_vide', @@ -43,6 +46,11 @@ class CacheWithCritiquesTest extends ViewHelperTestCase { } + function teardown() { + Storm_Cache::setDefaultZendCache(null); + parent::teardown(); + } + /** @test */ function withDisableCacheTwiceCallsShouldCallLoaderTwice() { $this->_cache_actif->setValeur('0'); diff --git a/tests/library/ZendAfi/View/Helper/Accueil/CalendarTest.php b/tests/library/ZendAfi/View/Helper/Accueil/CalendarTest.php index dbc30258699..2ada922d97f 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/CalendarTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/CalendarTest.php @@ -128,13 +128,12 @@ class CalendarWithEmptyPreferencesTest extends CalendarWithEmptyPreferencesTestC /** @test */ - public function cacheKeyShouldContainsBASE_URL() { - $params = array(BASE_URL, - 2, - Class_Profil::getCurrentProfil()->getId(), - Zend_Registry::get('translate')->getLocale(), - $this->helper->getPreferences()); - $this->assertEquals(md5(serialize($params)), $this->helper->getCacheKey()); + public function cacheKeyShouldContainsParams() { + $params = [2, + Class_Profil::getCurrentProfil()->getId(), + Zend_Registry::get('translate')->getLocale(), + $this->helper->getPreferences()]; + $this->assertEquals(md5(serialize($params)), md5(serialize($this->helper->getCacheKey()))); } diff --git a/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php b/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php index 4324f06e786..7520c4b56ca 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php @@ -162,7 +162,10 @@ class ZendAfi_View_Helper_Accueil_KiosqueMurWithPanierAndTriTest extends ZendAfi class ZendAfi_View_Helper_Accueil_KiosqueRequetesTest extends ZendAfi_View_Helper_Accueil_KiosqueTestCase { public function setUp() { parent::setUp(); - + + $this->mock_cache = Storm_Test_ObjectWrapper::mock(); + Storm_Cache::setDefaultZendCache($this->mock_cache); + $this->old_sql = Zend_Registry::get('sql'); $this->mock_sql = Storm_Test_ObjectWrapper::mock(); Zend_Registry::set('sql', $this->mock_sql); @@ -181,8 +184,6 @@ class ZendAfi_View_Helper_Accueil_KiosqueRequetesTest extends ZendAfi_View_Helpe ->with(['id_notice' => [2,45], 'order' => 'FIELD(id_notice, 2,45)']) ->answers($this->_notices); - $this->mock_cache = Storm_Test_ObjectWrapper::mock(); - Storm_Cache::setDefaultZendCache($this->mock_cache); } @@ -203,6 +204,7 @@ class ZendAfi_View_Helper_Accueil_KiosqueRequetesTest extends ZendAfi_View_Helpe /** @test */ public function findAllByRequeteRechercheQueryWithOutCache() { + Storm_Cache::setDefaultZendCache(null); Class_AdminVar::newInstanceWithId('CACHE_ACTIF', ['valeur'=>0]); $this->_html = $this->_helper->getBoite(); -- GitLab