diff --git a/VERSIONS_WIP/dev_#17514_index_cart_into_domains b/VERSIONS_WIP/dev_#17514_index_cart_into_domains new file mode 100644 index 0000000000000000000000000000000000000000..ff16dbe56a36ebab68161fb7add2d682ec28c2d3 --- /dev/null +++ b/VERSIONS_WIP/dev_#17514_index_cart_into_domains @@ -0,0 +1,2 @@ + - ticket : #17514 : Indexation des paniers dans les domaines + - Les notices des paniers rattachées à un domaine sont visible dans celui-ci \ No newline at end of file diff --git a/application/modules/admin/controllers/CatalogueController.php b/application/modules/admin/controllers/CatalogueController.php index 7984f45e707f13a22fd4affc33c4fc3b925c15ba..a02187daa499c15ebe94f2f26beb8cadae728f7e 100644 --- a/application/modules/admin/controllers/CatalogueController.php +++ b/application/modules/admin/controllers/CatalogueController.php @@ -188,22 +188,26 @@ class Admin_CatalogueController extends ZendAfi_Controller_Action { function deleteAction() { $id_catalogue=(int)$this->_getParam("id_catalogue"); $user = Class_Users::getIdentity(); - if ($catalogue = Class_Catalogue::getLoader()->find($id_catalogue)) + if ($catalogue = Class_Catalogue::find($id_catalogue)) { + Class_NoticeDomain::deleteByDomain($catalogue); $catalogue->deleteWithUser($user); - + } $this->_redirect("admin/catalogue/index"); } public function paniersAction() { $id_catalogue=(int)$this->_getParam("id_catalogue"); - $catalogue = Class_Catalogue::find($id_catalogue); + if(!$catalogue = Class_Catalogue::find($id_catalogue)) + return $this->_redirect("admin/catalogue/index"); if ($this->_request->isPost()) { $panier = Class_PanierNotice::find($this->_request->getPost('id_panier')); $catalogue ->addPanierNotice($panier) ->save(); + $panier->addCatalogue($catalogue)->save(); + $panier->index(); $this->_helper->notify($this->_('Panier "%s" ajouté', $panier->getLibelle())); $this->_redirect('admin/catalogue/paniers/id_catalogue/'.$id_catalogue); return; @@ -214,6 +218,8 @@ class Admin_CatalogueController extends ZendAfi_Controller_Action { $catalogue ->removePanierNotice($panier) ->save(); + $panier->removeCatalogue($catalogue)->save(); + $this->_helper->notify($this->_('Panier "%s" retiré', $panier->getLibelle())); $this->_redirect('admin/catalogue/paniers/id_catalogue/'.$id_catalogue); return; diff --git a/application/modules/admin/controllers/IndexController.php b/application/modules/admin/controllers/IndexController.php index 36b57acc04d9a567b9db436abe4abac1bff7c637..ae254a39500df23d999bb41ea7972527d70cd19c 100644 --- a/application/modules/admin/controllers/IndexController.php +++ b/application/modules/admin/controllers/IndexController.php @@ -119,7 +119,7 @@ class Admin_IndexController extends ZendAfi_Controller_Action { public function clearcacheAction() { - Zend_Registry::get('cache')->clean(Zend_Cache::CLEANING_MODE_ALL); + (new Storm_Cache())->clean(); $this->_redirect('admin/index/adminvar'); } diff --git a/application/modules/opac/controllers/PanierController.php b/application/modules/opac/controllers/PanierController.php index eb6fe92c64f7af2fa5a5066edde390f11545f9b3..7c43319ff392ef6ac90c4fc4f1e717d5660ec186 100644 --- a/application/modules/opac/controllers/PanierController.php +++ b/application/modules/opac/controllers/PanierController.php @@ -172,6 +172,7 @@ class PanierController extends ZendAfi_Controller_Action { $panier->addNotice($notice)->save(); + $panier->index(); $this->_helper->notify($this->_('Notice "%s" ajoutée au panier "%s"', $notice->getTitrePrincipal(), $panier->getLibelle())); @@ -232,10 +233,10 @@ class PanierController extends ZendAfi_Controller_Action { $panier->addNotice($notice)->save(); $panier = $this->addDomainesTo($panier); + $panier->index(); $this->_user->setPanierCourant($panier); $this->_user->save(); - $this->_forward('ajout-ajax-success','panier','opac',['id_notice' => $notice->getId(), 'id_panier' => $panier->getId()]); } @@ -252,6 +253,7 @@ class PanierController extends ZendAfi_Controller_Action { } $panier->removeNotice($notice)->save(); + $panier->index(); $this->_helper->notify($this->_('Notice "%s" retirée du panier', $notice->getTitrePrincipal())); @@ -287,6 +289,8 @@ class PanierController extends ZendAfi_Controller_Action { ->setDomaineIds($list_cat) ->save(); + $panier->index(); + return $this->_plural($nb_cat, '', $this->_('Panier: ').$panier->getLibelle().$this->_(' ajouté au domaine sélectionné.'), diff --git a/application/modules/opac/controllers/RssController.php b/application/modules/opac/controllers/RssController.php index 662337585f0538d949d3fa55b2d96e5cb9e5f99d..eac46ef9facda098f6aa80c32bde10cd7ad3de78 100644 --- a/application/modules/opac/controllers/RssController.php +++ b/application/modules/opac/controllers/RssController.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // OPAC3 - FLUX RSS @@ -246,7 +246,8 @@ class RssController extends Zend_Controller_Action } if (count($data_rss['items']) == 0) - $data_rss["items"][]= array('titre' => $this->view->_('Aucune donnée à modérer')); + $data_rss["items"][]= ['titre' => $this->view->_('Aucune donnée à modérer'), + 'lien' => '']; $this->getHelper('ViewRenderer')->setNoRender(); $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8') ; @@ -268,7 +269,7 @@ class RssController extends Zend_Controller_Action $data_rss["description"] = $this->view->_("Critiques de la sélection: %s", $preferences['titre']); $data_rss["lien"] = $profil->urlForModule('blog', 'viewcritiques', $id_module); $data_rss["items"] = []; - + $avis_helper = $this->view->getHelper('Avis'); foreach($liste_avis as $avis) { if (!$avis->hasFirstNotice()) @@ -314,7 +315,7 @@ class RssController extends Zend_Controller_Action 'desc' => '<![CDATA[' . $this->filtreNews($desc) . ']]>', 'pubDate' => strtotime($avis->getDateAvis())]; } - + $data_rss = ['titre' => sprintf('Avis de %s', $username), 'lien' => $this->view->absoluteUrl([ 'controller' => 'blog', diff --git a/cosmogramme/php/_init.php b/cosmogramme/php/_init.php index 27e4b084edeaea524c6306bdbd1a247e1cd6e998..aa4a04dd59fd81ee155498c85cdca95ea0e9a792 100644 --- a/cosmogramme/php/_init.php +++ b/cosmogramme/php/_init.php @@ -1,7 +1,7 @@ <?php // Constantes error_reporting(E_ERROR | E_PARSE); -define("PATCH_LEVEL","231"); +define("PATCH_LEVEL","232"); define("APPLI","cosmogramme"); define("COSMOPATH", "/var/www/html/vhosts/opac2/www/htdocs"); diff --git a/cosmogramme/php/integration/domaines.php b/cosmogramme/php/integration/domaines.php index b71dff481519079effa9c7e126213117abb2e479..45dedf8405f91ae67e7142f9bcefbb2ef9509668 100644 --- a/cosmogramme/php/integration/domaines.php +++ b/cosmogramme/php/integration/domaines.php @@ -53,6 +53,9 @@ if ($phase==15) { $phase_data["pointeur"]=0; } + $log->ecrire('<h4>Indexation des paniers dans les domaines</h4>'); + Class_PanierNotice::indexAll(); + $log->ecrire("<h4>Indexation des articles dans les domaines</h4>"); Class_Article::indexAll(); diff --git a/cosmogramme/sql/patch/patch_228.sql b/cosmogramme/sql/patch/patch_228.sql deleted file mode 100644 index 78a66e27bb1b00e444d7d57fd7368265253b0e04..0000000000000000000000000000000000000000 --- a/cosmogramme/sql/patch/patch_228.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE TABLE IF NOT EXISTS notice_domain ( - id int( 11 ) NOT NULL AUTO_INCREMENT , - record_alpha_key varchar( 250 ) NOT NULL, - domain_id int( 11 ) NOT NULL default 0, - PRIMARY KEY ( id ) -) ENGINE = MYISAM DEFAULT CHARSET = utf8; diff --git a/cosmogramme/sql/patch/patch_232.php b/cosmogramme/sql/patch/patch_232.php new file mode 100644 index 0000000000000000000000000000000000000000..ca8301b5ac3b33356aeaa8bae2fb10429e6ed294 --- /dev/null +++ b/cosmogramme/sql/patch/patch_232.php @@ -0,0 +1,3 @@ +<?php + Zend_Registry::get('sql')->query('CREATE TABLE IF NOT EXISTS notice_domain (id int( 11 ) NOT NULL AUTO_INCREMENT, record_alpha_key varchar( 250 ) NOT NULL, domain_id int( 11 ) NOT NULL default 0, panier_id int( 11 ) NOT NULL DEFAULT 0, PRIMARY KEY ( id )) ENGINE = MYISAM DEFAULT CHARSET = utf8;'); +?> diff --git a/library/Class/AdminVar.php b/library/Class/AdminVar.php index 00013e3c2ad57bbd45fb1b4b76bab4b0b935e0c8..12cebe51f972065e7b75478bf93fc3ffe433ba54 100644 --- a/library/Class/AdminVar.php +++ b/library/Class/AdminVar.php @@ -298,7 +298,7 @@ 'INTERDIRE_ENREG_UTIL' => 'Supprime l\'affichage du lien d\'enregistrement dans les différents formulaires de connexion et interdit l\'enregistrement d\'utilisateurs', 'LANGUES' => 'Liste des codes langue utilisées en plus du français séparées par des ;. Exemple: en;ro;es', 'CACHE_ACTIF' => implode('<br/>', - ['Activer le cache des boîtes (meilleure performance mais mise à jour toutes les ' . ((int)Zend_Registry::get('cache')->getOption('lifetime')) / 60 . 'mn)', + ['Activer le cache des boîtes (meilleure performance mais mise à jour toutes les ' . CACHE_LIFETIME / 60 . 'mn)', '0 = inactif', '1 = actif', sprintf('<a href="%s" >Vider le cache</a>', diff --git a/library/Class/Album.php b/library/Class/Album.php index 6bc83b99070ebadcc2cb4a2738389c9f730de4d8..e797960d9427104414d1c499c105eb4ad253e011 100644 --- a/library/Class/Album.php +++ b/library/Class/Album.php @@ -65,7 +65,7 @@ class AlbumLoader extends Storm_Model_Loader { class Class_Album extends Storm_Model_Abstract { - use Trait_TimeSource; + use Trait_TimeSource, Trait_Indexable; const BASE_PATH = 'album/'; const THUMBS_PATH = 'thumbs/'; @@ -1596,5 +1596,18 @@ class Class_Album extends Storm_Model_Abstract { return $this->addZone(self::COLLECTION_FIELD,['a' => $name]); } + + + public function acceptClefAlphaVisitor($visitor) { + $authors = $this->getAuthorsNames(); + $editors = $this->getEditors(); + + $visitor->visitTitre($this->getTitre()) + ->visitComplementTitre($this->getSousTitre()) + ->visitAuteur(implode($authors)) + ->visitTypeDocId($this->getTypeDocId()) + ->visitEditeur(array_shift($editors)) + ->visitAnnee($this->getAnnee()); + } } ?> \ No newline at end of file diff --git a/library/Class/Article.php b/library/Class/Article.php index f9431cfa9f5ad8b94f59d0cbecc18a685b053b87..863f78d7a78d890ac269e8186212f7bbc506bbd5 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -415,16 +415,14 @@ class ArticleLoader extends Storm_Model_Loader { public function indexAll() { - $total = Class_Article::countBy(['indexation' => '1']); - $split = 500; - $nb_pages= ceil($total/$split); - for ($page=1;$page<=$nb_pages; $page++) { - $articles_to_index = Class_Article::findAllBy(['indexation' => '1', - 'limitPage' => [$page,$split]]); - foreach($articles_to_index as $article) { + $page = 1; + while($articles_to_index = Class_Article::findAllBy(['indexation' => '1', + 'limitPage' => [$page, 500]])) { + foreach($articles_to_index as $article) $article->index(); - } + Class_Article::clearCache(); + $page++; } } } @@ -1204,6 +1202,12 @@ class Class_Article extends Storm_Model_Abstract { return $date->toString('YYYY-MM-dd HH:mm'); } + + public function acceptClefAlphaVisitor($visitor) { + $visitor->visitTitre($this->getTitre()) + ->visitTypeDocId($this->getTypeDocId()); + } + } -?> +?> \ No newline at end of file diff --git a/library/Class/CasTicket.php b/library/Class/CasTicket.php index 74b72a12aa231d6cdebf6871e3d4742653e6d1fb..74c49a9db6e08e4046b5764444c5cedd7326ec14 100644 --- a/library/Class/CasTicket.php +++ b/library/Class/CasTicket.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_CasTicket { //see http://www.jasig.org/cas/protocol#service-ticket-properties @@ -36,8 +36,8 @@ class Class_CasTicket { public function save() { if ($user = Class_Users::getIdentity()) - Zend_Registry::get('cache')->save((string)$user->getId(), - $this->withoutPrefix($this->getTicketForCurrentUser())); + (new Storm_Cache())->save((string)$user->getId(), + $this->withoutPrefix($this->getTicketForCurrentUser())); } @@ -48,11 +48,11 @@ class Class_CasTicket { public function clear() { if ($ticket = $this->getTicketForCurrentUser()) - Zend_Registry::get('cache')->remove($this->withoutPrefix($ticket)); + (new Storm_Cache())->remove($this->withoutPrefix($ticket)); } public function userForTicket($ticket) { - if ($id = (int)Zend_Registry::get('cache')->load($this->withoutPrefix($ticket))) + if ($id = (int)(new Storm_Cache())->load($this->withoutPrefix($ticket))) return Class_Users::find($id); return null; } diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php index d8c87eeca6d6d4cf245c222832b2f034dc0535f5..259ef55e022b38d0df57ac348c844ebe4b7c6cb8 100644 --- a/library/Class/Catalogue.php +++ b/library/Class/Catalogue.php @@ -121,8 +121,10 @@ class CatalogueLoader extends Storm_Model_Loader { if(!$catalogue) return ''; - $notices_cles = Class_NoticeDomain::getClesNoticesForDomain($catalogue->getId()); - return Class_MoteurRecherche::prepareClesNoticesForOrConditions($notices_cles); + if (!Class_NoticeDomain::getClesNoticesForDomain($catalogue->getId())) + return ''; + + return Class_MoteurRecherche::prepareFacetteDomainForOrConditions($catalogue->getId()); } @@ -536,6 +538,8 @@ class CatalogueLoader extends Storm_Model_Loader { class Class_Catalogue extends Storm_Model_Abstract { use Trait_TreeNode, Trait_Translator; + const CODE_FACETTE = 'Q'; + protected $_table_name = 'catalogue', $_table_primary = 'ID_CATALOGUE', @@ -624,6 +628,10 @@ class Class_Catalogue extends Storm_Model_Abstract { } + public function getFacette() { + return self::CODE_FACETTE . $this->getId(); + } + public function getAllNoticeIdsForDomaine($nb_par_page,$numero_page) { $preferences = $this->toArray(); @@ -706,7 +714,7 @@ class Class_Catalogue extends Storm_Model_Abstract { $ret["requete"] = $requetes["req_liste"]; $temps = time(); - $ret["notices"] = Class_Notice::findAllByRequeteRecherche($ret['requete'], + $ret["notices"] = Class_Notice::findAllByRequeteRecherche($requetes['req_ids'], $preferences['nb_notices'], 1); $ret["temps_execution"] = time() - $temps; @@ -753,7 +761,7 @@ class Class_Catalogue extends Storm_Model_Abstract { } - public function buildCriteresRecherche($params) { + public function buildCriteresRecherche($params = []) { $type_doc = $this->getTypeDoc(); $filtres = ['B' => $this->getBibliotheque(), 'S' => $this->getSection(), diff --git a/library/Class/Codification.php b/library/Class/Codification.php index 2e24d2f07a445bbc428bebaf6cd859738787b332..d2863f31a4cd8090067e35841d8b90dd4bbe3571 100644 --- a/library/Class/Codification.php +++ b/library/Class/Codification.php @@ -38,7 +38,7 @@ * N: année * O: notes * P: pcdm4 - * Q: prix + * Q: domain for pseudo record * R: résumé * S: section * T: type de doc diff --git a/library/Class/CriteresRecherche.php b/library/Class/CriteresRecherche.php index 11961a0c13e960bc1858d972cf027a63649f3ac1..6461e446836c62aceda7b8fb4da987c348d2e797 100644 --- a/library/Class/CriteresRecherche.php +++ b/library/Class/CriteresRecherche.php @@ -143,8 +143,7 @@ class Class_CriteresRecherche { $facettes = explode('-', $this->getParam('facettes', '')); $facettes []= $this->getParam('facette', ''); - $profil = Class_Profil::getCurrentProfil(); - if ($selection_bib = $profil->getIdSite()) + if ($this->_profil && ($selection_bib = $this->_profil->getIdSite())) $facettes []= 'B'.$selection_bib; return array_unique(array_filter($facettes, @@ -178,17 +177,15 @@ class Class_CriteresRecherche { public function getFiltres() { - $profil = Class_Profil::getCurrentProfil(); - $filtres = [ $this->selectionToArray('G', $this->getGenre()), ]; - if (!$this->isRecherchePanier() && !$this->isRechercheCatalogueEmpty()) { + if (!$this->isRecherchePanier() && !$this->isRechercheCatalogueEmpty() && $this->_profil) { $filtres = array_merge($filtres, [ - $this->selectionToArray('T', $profil->getSelTypeDoc()), - $this->selectionToArray('Y', $profil->getSelAnnexe()), - $this->selectionToArray('S', $profil->getSelSection()), + $this->selectionToArray('T', $this->_profil->getSelTypeDoc()), + $this->selectionToArray('Y', $this->_profil->getSelAnnexe()), + $this->selectionToArray('S', $this->_profil->getSelSection()), ]); } @@ -291,8 +288,13 @@ class Class_CriteresRecherche { public function visitCatalogue($visitor, $catalogue) { $criteres = $this->getCriteres(); - $this->setParams($catalogue->buildCriteresRecherche($criteres)); + + $domain_settings = $catalogue->buildCriteresRecherche(); + $domain_critere = (new Class_CriteresRecherche())->clearProfil(); + + $visitor->visitDomain($domain_critere->setParams($domain_settings)); + if ($catalogue->getCoteDebut()||$catalogue->getCoteFin()) $visitor->visitCoteDebutFin($catalogue->getCoteDebut(),$catalogue->getCoteFin()); @@ -303,17 +305,18 @@ class Class_CriteresRecherche { $visitor->visitAnneeDebutFin($catalogue->getAnneeDebut(),$catalogue->getAnneeFin()); if($cles_notices = Class_NoticeDomain::getClesNoticesForDomain($catalogue->getId())) - $visitor->visitClesNoticesForOrConditions($cles_notices); + $visitor->visitFacetteDomainForOrConditions($catalogue->getId()); - if(isset($criteres['id_catalogue']) && !empty($criteres['id_catalogue'])) + if(isset($criteres['id_catalogue']) && !empty($criteres['id_catalogue'])) { $visitor->visitFilterOnDomain((new Class_CriteresRecherche()) - ->setParams($this->cleansCritereForFilterOnDomain($criteres))); -; + ->setParams($this->cleansCritereForFilterOnDomain($criteres, ['id_catalogue']))); + } } - protected function cleansCritereForFilterOnDomain($criteres) { - unset($criteres['id_catalogue']); + protected function cleansCritereForFilterOnDomain($criteres, $keys = []) { + foreach($keys as $key) + unset($criteres[$key]); return $criteres; } @@ -691,6 +694,12 @@ class Class_CriteresRecherche { function updateRubrique($rubrique) { return $this->_params['rubrique']=$rubrique; } + + + public function clearProfil() { + $this->_profil = null; + return $this; + } } ?> \ No newline at end of file diff --git a/library/Class/Indexation.php b/library/Class/Indexation.php index fd0b9fa68cfc448e1b0f69f0631c0e84e12d45ab..65a27098db2c272fc25a9020cbdb98a529d4c571 100644 --- a/library/Class/Indexation.php +++ b/library/Class/Indexation.php @@ -24,6 +24,7 @@ class Class_Indexation { + protected static $_instance; private $articles; // Articles rejetes private $inclu; // Mots inclus @@ -31,6 +32,13 @@ class Class_Indexation { private $pluriel; // Règles des pluriels private $tableMaj; // Table de transco pour majuscules + + public static function getInstance() { + if(!static::$_instance) + static::$_instance = new Class_Indexation(); + return static::$_instance; + } + public function __construct() { // Lire formes rejetées $this->articles=array("L'","LE ","LA ","LES ","UN ","UNE "); diff --git a/library/Class/Indexation/PseudoNotice.php b/library/Class/Indexation/PseudoNotice.php index 0ae8ead6cc3f222d0fbf9706364e0c81ce8da20a..ad5c63a1a79c6c16df735ec66c282f166370b21a 100644 --- a/library/Class/Indexation/PseudoNotice.php +++ b/library/Class/Indexation/PseudoNotice.php @@ -20,14 +20,8 @@ */ class Class_Indexation_PseudoNotice { - const TYPE_CMS = 8; - const TYPE_RSS = 9; - const TYPE_SITO=10; - - protected static $_model; - protected static $_indexation; - protected static $_datas = []; - + protected $_model; + protected $_datas = []; protected $_table; protected $_id; protected $_label; @@ -47,9 +41,9 @@ class Class_Indexation_PseudoNotice { public static function newWith($type_doc, $datas) { // types simples - $mapping = [self::TYPE_CMS => 'Cms', - self::TYPE_RSS => 'Rss', - self::TYPE_SITO=> 'Sito']; + $mapping = [Class_TypeDoc::ARTICLE => 'Cms', + Class_TypeDoc::RSS => 'Rss', + Class_TypeDoc::SITE=> 'Sito']; if (array_key_exists($type_doc, $mapping)) { $class_name = 'Class_Indexation_PseudoNotice_' . $mapping[$type_doc]; @@ -65,31 +59,11 @@ class Class_Indexation_PseudoNotice { public function __construct($type_doc, $datas) { $this->_type_doc = (int)$type_doc; - static::$_datas = array_change_key_case($datas, CASE_LOWER); - static::$_model = call_user_func_array([$this->_model_name, 'find'], - [static::$_datas[$this->_id]]); - } - - - public static function getIndexation() { - if(!static::$_indexation) - static::$_indexation = new Class_Indexation(); - return static::$_indexation; + $this->_datas = array_change_key_case($datas, CASE_LOWER); + $this->_model = call_user_func_array([$this->_model_name, 'find'], + [$this->_datas[$this->_id]]); } - - public static function getAlphaKey($model) { - return static::getIndexation() - ->getClefAlpha($model->getTypeDocId(), - $model->getTitre(), - '', - static::getAuthorsNames(), - '', - static::getEditorsNames(), - static::extractYear($model)); - } - - public function getId() { return $this->_notice->getId(); } @@ -113,16 +87,16 @@ class Class_Indexation_PseudoNotice { return false; $this->_notice = $notice; - $exemplaire = Class_Exemplaire::newInstance(['id_bib' => static::$_datas['id_bib'], + $exemplaire = Class_Exemplaire::newInstance(['id_bib' => $this->_datas['id_bib'], 'id_notice' => $this->_notice->getId(), - 'id_origine' => static::$_model->getId(), + 'id_origine' => $this->_model->getId(), 'activite' => 'A consulter sur le portail']); if (!$exemplaire->save()) return false; $this->_exemplaire = $exemplaire; - static::$_model->updateAttributes([$this->_id_notice => $this->_notice->getId()]); - static::$_model->save(); + $this->_model->updateAttributes([$this->_id_notice => $this->_notice->getId()]); + $this->_model->save(); $this->_index(); return true; @@ -130,7 +104,7 @@ class Class_Indexation_PseudoNotice { protected function _prepare() { $intBib = Class_IntBib::findFirstBy(['order' => 'id_bib']); - static::$_datas = array_merge( ['id_bib' => $intBib ? $intBib->getId() : 0, + $this->_datas = array_merge( ['id_bib' => $intBib ? $intBib->getId() : 0, 'date_maj' => '', 'auteur' => '', 'matiere' => '', @@ -149,22 +123,22 @@ class Class_Indexation_PseudoNotice { 'notes' => '', 'nature_doc' => '', 'date_maj' =>'', - 'domaine_ids' => ''],array_change_key_case(static::$_datas)); + 'domaine_ids' => ''],array_change_key_case($this->_datas)); } - public static function getAuthorsNames() { + public function getAuthorsNames() { $names = []; - foreach($authors = static::extractAuthors() as $author) + foreach($authors = $this->extractAuthors() as $author) $names[] = $author->getName(); return implode('-', $names); } - public static function getEditorsNames() { - return implode('-', static::extractEditors()); + public function getEditorsNames() { + return implode('-', $this->extractEditors()); } @@ -175,53 +149,54 @@ class Class_Indexation_PseudoNotice { $data = $this->indexDeweyAndPCDM4($data); $this->_notice->updateAttributes($data); - $authors = static::getAuthorsNames(); + $authors = $this->getAuthorsNames(); + $indexation = Class_Indexation::getInstance(); $this->_notice ->setMatieres($this->extractFullTextFromCodif($data, 'matiere', 'Class_CodifMatiere')) - ->setAlphaTitre(static::getIndexation()->codeAlphaTitre(static::$_datas["titre"])) - ->setClefAlpha(static::getAlphaKey(static::$_model)) - ->setClefOeuvre(static::getIndexation()->getClefOeuvre(static::$_datas["titre"], + ->setAlphaTitre($indexation->codeAlphaTitre($this->_datas["titre"])) + ->setClefAlpha($this->_model->getAlphaKey()) + ->setClefOeuvre($indexation->getClefOeuvre($this->_datas["titre"], '', - static::$_datas["auteur"], + $this->_datas["auteur"], '')) - ->setTitres(static::getIndexation()->getfullText($this->extractTitles())) - ->setAuteurs(static::getIndexation()->getfullText($authors)) - ->setAlphaAuteur(static::getIndexation()->alphaMaj(implode(' ', static::extractAuthors()))) + ->setTitres($indexation->getfullText($this->extractTitles())) + ->setAuteurs($indexation->getfullText($authors)) + ->setAlphaAuteur($indexation->alphaMaj(implode(' ', $this->extractAuthors()))) ->setFacettes(implode(' ',$this->_getFacettes())) - ->setAnnee(static::$_datas["annee"]) + ->setAnnee($this->_datas["annee"]) ->setQualite(3) // Qualite = pseudo_notice ->setExportable("1") ->setUnimarc($unimarc) ->setDateMaj(date('Y-m-d H:i:s')); - if (static::dataExist('editeur' , static::$_datas)) - $this->_notice->setEditeur(static::getIndexation()->getfullText(static::$_datas["editeur"])); + if ($this->dataExist('editeur' , $this->_datas)) + $this->_notice->setEditeur($indexation->getfullText($this->_datas["editeur"])); - if (static::dataExist('fichier', static::$_datas)) { - $url_vignette = static::$_model->getThumbnailUrl(); + if ($this->dataExist('fichier', $this->_datas)) { + $url_vignette = $this->_model->getThumbnailUrl(); $this->_notice->setUrlVignette($url_vignette); $this->_notice->setUrlImage($url_vignette); } - if (static::dataExist('url_image', static::$_datas)) - $this->_notice->setUrlImage(static::$_datas["url_image"]); + if ($this->dataExist('url_image', $this->_datas)) + $this->_notice->setUrlImage($this->_datas["url_image"]); $this->_notice->save(); // exemplaire $genre = ''; - if (static::dataExist('genre', static::$_datas)) { - $genres = explode(';', static::$_datas['genre']); + if ($this->dataExist('genre', $this->_datas)) { + $genres = explode(';', $this->_datas['genre']); $genre = $genres[0]; } $cote = ''; - if (static::dataExist('cote', static::$_datas)) - $cote = static::$_datas['cote']; + if ($this->dataExist('cote', $this->_datas)) + $cote = $this->_datas['cote']; $this->_exemplaire ->setGenre($genre) @@ -230,54 +205,54 @@ class Class_Indexation_PseudoNotice { } - public static function extractYear($model) { - if (!static::dataExist('annee', $model->toArray())) + public function extractYear($model) { + if (!$this->dataExist('annee', $model->toArray())) return ''; return $model->getAnnee(); } - public static function extractAuthors() { + public function extractAuthors() { $authors = []; - if (static::dataExist('auteur', static::$_datas)) - $authors[] = new Class_Notice_Author(static::$_datas['auteur']); + if ($this->dataExist('auteur', $this->_datas)) + $authors[] = new Class_Notice_Author($this->_datas['auteur']); return array_filter($authors); } - public static function extractEditors() { - if (!static::dataExist('editeur', static::$_datas)) + public function extractEditors() { + if (!$this->dataExist('editeur', $this->_datas)) return []; - return array_filter(static::$_datas['editeur']); + return array_filter($this->_datas['editeur']); } protected function extractCollections() { $collections = []; - if (static::dataExist('collection', static::$_datas)) - $collections[] = static::$_datas['collection']; + if ($this->dataExist('collection', $this->_datas)) + $collections[] = $this->_datas['collection']; return array_filter($collections); } protected function extractTitles() { - return static::$_datas['titre']; + return $this->_datas['titre']; } protected function extractFullTextFromCodif($data, $field, $codif_class) { - if (!static::dataExist($field, static::$_datas)) + if (!$this->dataExist($field, $this->_datas)) return ''; - $ids = array_filter(array_map('trim', explode(';', static::$_datas[$field]))); + $ids = array_filter(array_map('trim', explode(';', $this->_datas[$field]))); $fulltext = []; foreach($ids as $id) { if ($model = $codif_class::find($id)) $fulltext[] = $model->getLibelle(); } - return static::getIndexation()->getfullText(implode(' ', $fulltext)); + return Class_Indexation::getInstance()->getfullText(implode(' ', $fulltext)); } @@ -311,32 +286,32 @@ class Class_Indexation_PseudoNotice { $visitor ->visitTypeDoc($this->_type_doc) ->visitAuteur($this->extractAuthors()) - ->visitMatiere(static::$_datas['matiere']) - ->visitDewey(static::$_datas['dewey']) - ->visitLangue(static::$_datas['id_langue']) - ->visitTagFacettes(static::$_datas["tags"]) - ->visitDomaine(static::$_datas['domaine_ids']) + ->visitMatiere($this->_datas['matiere']) + ->visitDewey($this->_datas['dewey']) + ->visitLangue($this->_datas['id_langue']) + ->visitTagFacettes($this->_datas["tags"]) + ->visitDomaine($this->_datas['domaine_ids']) ->visitLabel($this->_label) ->visitIdNotice($this->_notice->getId()) - ->visitDateMaj(static::$_datas['date_maj']) - ->visitSubTitle(static::$_datas['sous_titre']) - ->visitTitle(static::$_datas['titre']) + ->visitDateMaj($this->_datas['date_maj']) + ->visitSubTitle($this->_datas['sous_titre']) + ->visitTitle($this->_datas['titre']) ->visitEditors($this->extractEditors()) ->visitCollection($this->extractCollections()) - ->visitYear(static::$_datas['annee']) - ->visitLanguageId(static::$_datas['id_langue']) - ->visitDescription(static::$_datas['description']) - ->visitOrigin(static::$_datas['provenance']) - ->visitUrl(static::$_datas['url']) - ->visitNotes(static::$_datas['notes']) - ->visitNatures(static::$_datas['nature_doc']); + ->visitYear($this->_datas['annee']) + ->visitLanguageId($this->_datas['id_langue']) + ->visitDescription($this->_datas['description']) + ->visitOrigin($this->_datas['provenance']) + ->visitUrl($this->_datas['url']) + ->visitNotes($this->_datas['notes']) + ->visitNatures($this->_datas['nature_doc']); $this->_modelIdAcceptVisitor($visitor); } protected function _modelIdAcceptVisitor($visitor) { - $visitor->visitModelId(static::$_model->getId()); + $visitor->visitModelId($this->_model->getId()); } @@ -354,16 +329,16 @@ class Class_Indexation_PseudoNotice { } protected function _getCodeBarres() { - return str_repeat('0', (4 - strlen(static::$_datas['id_bib']))) - . static::$_datas['id_bib'] . '-' . $this->_notice->getId(); + return str_repeat('0', (4 - strlen($this->_datas['id_bib']))) + . $this->_datas['id_bib'] . '-' . $this->_notice->getId(); } public function isValid() { - return null != static::$_model; + return null != $this->_model; } - public static function dataExist($name ,$datas = []) { + public function dataExist($name ,$datas = []) { return array_key_exists($name, $datas) && ($datas[$name] != ''); } } @@ -382,15 +357,15 @@ class Class_Indexation_PseudoNotice_Album extends Class_Indexation_PseudoNotice{ protected function _prepare() { parent::_prepare(); - if (static::$_datas['id_origine']) - static::$_datas['url'] = $this->getUrlSite() . 'bib-numerique/notice/ido/' - . static::$_datas['id_origine']; + if ($this->_datas['id_origine']) + $this->_datas['url'] = $this->getUrlSite() . 'bib-numerique/notice/ido/' + . $this->_datas['id_origine']; - if ($poster = static::$_model->getPoster()) - static::$_datas['url_image'] = $poster; + if ($poster = $this->_model->getPoster()) + $this->_datas['url_image'] = $poster; - $model = static::$_model; - static::$_datas['notes'] = $model->getNotesForPseudoNotice(); + $model = $this->_model; + $this->_datas['notes'] = $model->getNotesForPseudoNotice(); } @@ -398,44 +373,45 @@ class Class_Indexation_PseudoNotice_Album extends Class_Indexation_PseudoNotice{ /** @return array */ - public static function extractAuthors() { + public function extractAuthors() { $authors = parent::extractAuthors(); - static::_addAuthorArrayAsNoticeAuthor(static::$_model->getAuthors(), $authors); + $this->_addAuthorArrayAsNoticeAuthor($this->_model->getAuthors(), $authors); - foreach (static::$_model->getRessources() as $ressource) - static::_addAuthorArrayAsNoticeAuthor($ressource->getAuthors(), $authors); + foreach ($this->_model->getRessources() as $ressource) + $this->_addAuthorArrayAsNoticeAuthor($ressource->getAuthors(), $authors); return array_unique($authors); } - protected static function _addAuthorArrayAsNoticeAuthor($datas, &$authors) { + protected function _addAuthorArrayAsNoticeAuthor($datas, &$authors) { foreach($datas as $data) $authors []= new Class_Notice_Author($data['a'], isset($data['4']) ? $data['4'] : ''); } - public static function extractEditors() { - if(empty(($editors = parent::extractEditors()))) + public function extractEditors() { + $editors = parent::extractEditors(); + if(empty($editors)) $editors = []; return array_unique(array_merge($editors, - static::$_model->getEditors())); + $this->_model->getEditors())); } /** @return array */ protected function extractCollections() { return array_unique(array_merge(parent::extractCollections(), - static::$_model->getCollections())); + $this->_model->getCollections())); } protected function extractTitles() { $titles = [parent::extractTitles()]; - foreach(static::$_model->getRessources() as $ressource) { + foreach($this->_model->getRessources() as $ressource) { $titles[] = $ressource->findTitle(); } return implode(' ', $titles); @@ -443,7 +419,7 @@ class Class_Indexation_PseudoNotice_Album extends Class_Indexation_PseudoNotice{ protected function getValuesFromModel($name) { - $values=static::$_model->callGetterByAttributeName($name); + $values=$this->_model->callGetterByAttributeName($name); return (string)$values; } @@ -456,12 +432,12 @@ class Class_Indexation_PseudoNotice_Album extends Class_Indexation_PseudoNotice{ ->visitGenre($this->getValuesFromModel('genre')) ->visitPcdm4($this->getValuesFromModel('pcdm4')); - foreach (static::$_model->getRessources() as $ressource) + foreach ($this->_model->getRessources() as $ressource) $visitor->visitRessource($ressource); } public function isValid() { - return null != static::$_model && static::$_model->isVisible(); + return null != $this->_model && $this->_model->isVisible(); } } @@ -475,7 +451,7 @@ class Class_Indexation_PseudoNotice_Cms extends Class_Indexation_PseudoNotice{ protected function _prepare() { parent::_prepare(); - static::$_datas['description'] = strip_tags(static::$_datas['contenu']); + $this->_datas['description'] = strip_tags($this->_datas['contenu']); } } diff --git a/library/Class/MoteurRecherche.php b/library/Class/MoteurRecherche.php index 7d11fdede88efb594a436cc28c3d91bb75d1ee17..c4ae068c61c482c35f43f1dfd38d320f35c5607d 100644 --- a/library/Class/MoteurRecherche.php +++ b/library/Class/MoteurRecherche.php @@ -27,6 +27,7 @@ class Class_MoteurRecherche { $_notices_not_shown = false, $fil_ariane, $rubriques, + $_domain_conditions = null, $conditions = '', $_or_conditions = '', $_filter_domain_conditions = ''; @@ -125,9 +126,14 @@ class Class_MoteurRecherche { public function setCondition($condition) { + if(!$condition) + return $this; + if ($this->conditions != '') $this->conditions .= ' and '; + $this->conditions .= $condition; + return $this; } @@ -192,21 +198,19 @@ class Class_MoteurRecherche { } - public function visitClesNoticesForOrConditions($cles_notices) { - $this->setOrConditions(self::prepareClesNoticesForOrConditions($cles_notices)); + public function visitFacetteDomainForOrConditions($domain_id) { + $this->setOrConditions(self::prepareFacetteDomainForOrConditions($domain_id)); } - public static function prepareClesNoticesForOrConditions($cles_notices) { - if(! $cles_notices = array_filter($cles_notices)) + public function prepareFacetteDomainForOrConditions($domain_id) { + if(!$domain_id) return ''; - $keys = self::getInstance()->prepareRecordsKeys($cles_notices); - - if(! $keys = array_filter($keys)) + if(!$facette = Class_Catalogue::find($domain_id)->getFacette()) return ''; - return 'notices.clef_alpha in(' . implode(', ', $keys) . ')'; + return 'MATCH(facettes) AGAINST(\'' . trim($facette) . '\' IN BOOLEAN MODE)'; } @@ -278,12 +282,18 @@ class Class_MoteurRecherche { if(!$ands && !$ors) return ''; - if(!$ors) + if(!$ors && !$filter) return ' Where ' . $ands; - if(!$ands) + if(!$ors && $filter) + return ' Where (' . $ands . ')' . $filter; + + if(!$ands && !$filter) return ' Where ' . $ors; + if(!$ands && $filter) + return ' Where (' . $ors . ')' . $filter; + if(!$filter) return ' Where (' . $ands . ')'.' or '. $ors; @@ -291,10 +301,21 @@ class Class_MoteurRecherche { } + public function visitDomain($search_settings) { + $search_engine = (new Class_MoteurRecherche()); + $search_engine + ->visitSearchSettings($search_settings); + + if(is_array($search_engine->buildWherePartQuery())) + return; + + $this->_domain_conditions = $search_engine->getConditions(); + } + + public function visitFilterOnDomain($search_settings) { $search_engine = (new Class_MoteurRecherche()) - ->prepareSearchLauncher($search_settings); - $search_settings->acceptVisitor($search_engine); + ->visitSearchSettings($search_settings); if(is_array($search_engine->buildWherePartQuery())) return; @@ -314,7 +335,7 @@ class Class_MoteurRecherche { } - public function prepareSearchLauncher($criteres_recherche) { + public function visitSearchSettings($criteres_recherche) { $this->criteres_recherche = $criteres_recherche; $this->conditions = ''; $this->all_facettes = ''; @@ -322,15 +343,22 @@ class Class_MoteurRecherche { $this->nb_mots = 0; $tri = $criteres_recherche->getTri(); $this->order_by = ($tri > '' && $tri !== '*') ? ' order by ' . $tri : ''; + + $criteres_recherche->acceptVisitor($this); + return $this; } public function buildWherePartQuery() { - if ($this->all_facettes) { - $this->setCondition("MATCH(facettes) AGAINST('" . trim($this->all_facettes)."' IN BOOLEAN MODE)"); + if(!is_null($this->_domain_conditions)) { + $this->setCondition($this->_domain_conditions); + return self::getConditionsForRequest($this->conditions, $this->_or_conditions, $this->_filter_domain_conditions); } + if ($this->all_facettes) + $this->setCondition("MATCH(facettes) AGAINST('" . trim($this->all_facettes)."' IN BOOLEAN MODE)"); + if($this->criteres_recherche->hasEmptyDomain() && !$this->criteres_recherche->isSearchInBasket()){ return ['statut' => 'erreur', 'erreur' => $this->_('Domaine non paramétré')]; @@ -345,9 +373,7 @@ class Class_MoteurRecherche { 'statut' => '', 'nombre' => 0]; - $this->prepareSearchLauncher($criteres_recherche); - - $criteres_recherche->acceptVisitor($this); + $this->visitSearchSettings($criteres_recherche); if (!empty($this->fil_ariane)) $ret['fil_ariane'] = $this->fil_ariane; @@ -400,6 +426,7 @@ class Class_MoteurRecherche { $ret['req_liste'] = $req_notices; $ret['req_facettes'] = $req_facettes; $ret['nb_mots'] = $this->nb_mots; + return $ret; } @@ -419,7 +446,9 @@ class Class_MoteurRecherche { else $rubriques_tmp = $this->getRubriquesGuidees($indice); + $this->all_facettes .= ' +'.$indice.'*'; + $this->fil_ariane = $this->getFilAriane($fil,$indice); // Tableau des rubriques diff --git a/library/Class/Notice.php b/library/Class/Notice.php index 8630f3f27ee3eefc24d1de0ce99df1ed1b2e5d3e..4cb9f0627a4a6fdcce529a51b47487997ecaadef 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -481,6 +481,22 @@ class Class_Notice extends Storm_Model_Abstract { } + public function getAlphaKey() { + return $this->getClefAlpha(); + } + + + public function updateFacette($facettes) { + $this->setFacettes(Class_Notice_Facettes::mergeFacettes($this->getFacettes(), $facettes)); + return $this; + } + + + public function deleteFacettes($facettes) { + $this->setFacettes(Class_Notice_Facettes::removeFacettes($this->getFacettes(), $facettes)); + return $this; + } + /** * Rend la structure notice pour affichage liste diff --git a/library/Class/Notice/ClefAlpha.php b/library/Class/Notice/ClefAlpha.php index 4f8669665be09d448849ecd1fedf979a1f047f08..995f63bd33a8230a2d5a4801dc6969c9394985c7 100644 --- a/library/Class/Notice/ClefAlpha.php +++ b/library/Class/Notice/ClefAlpha.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_Notice_ClefAlpha { @@ -31,8 +31,63 @@ class Class_Notice_ClefAlpha { protected $_clef; - public function __construct($clef) { - $this->_clef = explode(self::SEPARATOR, $clef); + public function __construct($model_or_clef) { + if (is_string($model_or_clef)) + $this->_clef = explode(self::SEPARATOR, $model_or_clef); + else + $this->extractDatasFromModel($model_or_clef); + } + + public function extractDatasFromModel($model) { + $model->acceptClefAlphaVisitor($this); + $this->_clef = explode(self::SEPARATOR, (new Class_Indexation())->getClefAlpha($this->getTypeDoc(), + $this->getClefTitre(), + $this->getClefComplementTitre(), + $this->getClefAuteur(), + $this->getTome(), + $this->getClefEditeur(), + $this->getClefAnnee())); + } + + + public function visitTypeDocId($type_doc_id) { + $this->_clef[self::POS_TYPE_DOC] = $type_doc_id; + return $this; + } + + + public function visitTitre($titre) { + $this->_clef[self::POS_TITRE] = $titre; + return $this; + } + + + public function visitComplementTitre($titre) { + $this->_clef[self::POS_COMPLEMENT_TITRE] = $titre; + return $this; + } + + + public function visitAuteur($auteur) { + $this->_clef[self::POS_AUTEUR] = $auteur; + return $this; + } + + + public function visitEditeur($editeur) { + $this->_clef[self::POS_EDITEUR] = $editeur; + return $this; + } + + + public function visitAnnee($annee) { + $this->_clef[self::POS_ANNEE] = $annee; + return $this; + } + + + public function keyString() { + return implode(self::SEPARATOR, $this->_clef); } @@ -42,32 +97,32 @@ class Class_Notice_ClefAlpha { public function getClefComplementTitre() { - return $this->_clef[self::POS_COMPLEMENT_TITRE]; + return isset($this->_clef[self::POS_COMPLEMENT_TITRE]) ? $this->_clef[self::POS_COMPLEMENT_TITRE] : ''; } public function getClefEditeur() { - return $this->_clef[self::POS_EDITEUR]; + return isset($this->_clef[self::POS_EDITEUR]) ? $this->_clef[self::POS_EDITEUR] : ''; } - public function getTypeDoc() { - return isset($this->_clef[self::POS_TYPE_DOC]) ? $this->_clef[self::POS_TYPE_DOC] : ''; + public function getClefAnnee() { + return isset($this->_clef[self::POS_ANNEE]) ? $this->_clef[self::POS_ANNEE] : ''; } - public function getTome() { - return isset($this->_clef[self::POS_TOME]) ? $this->_clef[self::POS_TOME] : ''; + public function getClefAuteur() { + return isset($this->_clef[self::POS_AUTEUR]) ? $this->_clef[self::POS_AUTEUR] : ''; } - public function likeKeyWith($positions) { - $cle = []; - for($i=0; $i <=6; $i++) { - $cle []= in_array($i, $positions) ? $this->_clef[$i] : '%'; - } + public function getTypeDoc() { + return isset($this->_clef[self::POS_TYPE_DOC]) ? $this->_clef[self::POS_TYPE_DOC] : ''; + } - return implode(self::SEPARATOR, $cle); + + public function getTome() { + return isset($this->_clef[self::POS_TOME]) ? $this->_clef[self::POS_TOME] : ''; } @@ -87,27 +142,9 @@ class Class_Notice_ClefAlpha { if ($score > $max_score) $current_notice = $notice; } - - return $current_notice; - } - - - public function getUniqueNoticeWithParams($search_params) { - $current_params = []; - foreach($search_params as $key => $value) { - $current_params[$key] = $value; - $notices = Class_Notice::findAllBy($current_params); - - if (!$notices) - return null; - - if (count($notices) === 1) - return $notices[0]; - } - return null; + return $current_notice; } - } ?> \ No newline at end of file diff --git a/library/Class/Notice/Facettes.php b/library/Class/Notice/Facettes.php new file mode 100644 index 0000000000000000000000000000000000000000..26ffded8d73d7ce4b4b8f3fe8e2c3e963d9bb168 --- /dev/null +++ b/library/Class/Notice/Facettes.php @@ -0,0 +1,33 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Notice_Facettes { + public static function mergeFacettes($old_facettes, $facettes) { + return implode(' ', array_filter(array_unique(array_merge(explode(' ', $old_facettes), explode(' ', $facettes))))); + } + + + public static function removeFacettes($old_facettes, $facettes) { + return implode(' ', array_filter(array_diff(explode(' ', $old_facettes), explode(' ', $facettes)))); + } +} +?> \ No newline at end of file diff --git a/library/Class/NoticeDomain.php b/library/Class/NoticeDomain.php index 7d8fd308bb00d0e96a9cc8e231a7d1bba803b4ce..574bd23e57d62c1ba07beb945087eca5d69da93b 100644 --- a/library/Class/NoticeDomain.php +++ b/library/Class/NoticeDomain.php @@ -20,19 +20,128 @@ */ class NoticeDomainLoader extends Storm_Model_Loader { + public function getDomainsForRecordAlphaKey($alpha_key) { + $notice_domains = Class_NoticeDomain::findAllBy(['record_alpha_key' => $alpha_key, + 'domain_id not' => 0 ]); + $all_domain_ids = []; + foreach($notice_domains as $notice_domain) { + $all_domain_ids[] = $notice_domain->getDomainId(); + } + + $all_domain_ids = array_filter(array_unique($all_domain_ids)); + + $domains = []; + foreach ($all_domain_ids as $id) { + $domains[] = Class_Catalogue::find($id); + } + return $domains; + + } + public function getClesNoticesForDomain($domain_id) { - $notice_domains = Class_NoticeDomain::findAllBy(['domain_id' => $domain_id]); + $alpha_keys = []; + foreach(Class_noticeDomain::getRecordsForDomain($domain_id) as $record) { + $alpha_keys[] = $record->getAlphaKey(); + } + + return array_filter($alpha_keys); + } + + + public function getRecordsFromCart($id_cart) { + $notice_domains = Class_NoticeDomain::findAllBy(['panier_id' => $id_cart]); $notices = []; foreach($notice_domains as $notice_domain) { - if ($notice = Class_Notice::findFirstBy(['clef_alpha' => $notice_domain->getRecordAlphaKey()])) - $notices[] = $notice->getClefAlpha(); + $notices[] = Class_Notice::findFirstBy(['clef_alpha' => $notice_domain->getRecordAlphaKey()]); + } + + return array_filter($notices); + } + + + public function getDomainsFromCart($id_cart) { + $notice_domains = Class_NoticeDomain::findAllBy(['panier_id' => $id_cart]); + $domains = []; + foreach($notice_domains as $notice_domain) { + $domains[] = $notice_domain->getDomain(); + } + + return array_filter($domains); + } + + + public function getRecordsForDomain($domain_id) { + $records_domains = Class_NoticeDomain::findAllBy(['domain_id' => $domain_id]); + $records = []; + foreach($records_domains as $record_domain) + $records[] = Class_Notice::findFirstBy(['clef_alpha' => $record_domain->getRecordAlphaKey()]); + + return array_filter($records); + } + + + public function getRecordsForCart($cart_id) { + $records_domains = Class_NoticeDomain::findAllBy(['panier_id' => $cart_id]); + $records = []; + foreach($records_domains as $record_domain) + $records[] = Class_Notice::findFirstBy(['clef_alpha' => $record_domain->getRecordAlphaKey()]); + + return array_filter($records); + } + + + public function updateRecordsFacette($domain_id) { + foreach(Class_NoticeDomain::getRecordsForDomain($domain_id) as $record) { + $record->updateFacette(Class_Catalogue::find($domain_id)->getFacette())->save(); } + } + + + /* public function deleteRecordsFacetteForDomain($domain_id) { */ + /* if (!Class_Catalogue::find($domain_id)) */ + /* return; */ + + /* if (!$records = Class_NoticeDomain::getRecordsForDomain($domain_id)) */ + /* return; */ + + /* foreach($records as $record) { */ + /* $record->deleteFacettes(Class_Catalogue::find($domain_id)->getFacette())->save(); */ + /* } */ + /* } */ + + + /* public function deleteRecordsFacetteForCart($domain_id, $cart_id) { */ + /* if (!Class_PanierNotice::find($cart_id)) */ + /* return; */ + + /* if (!$records = Class_NoticeDomain::getRecordsForCart($cart_id)) */ + /* return; */ + + /* foreach($records as $record) { */ + /* $record->deleteFacettes(Class_Catalogue::find($domain_id)->getFacette())->save(); */ + /* Class_NoticeDomain::updateRecordsFacette($domain_id); */ + /* } */ + /* } */ - return $notices; + + public function deleteByCart($id_cart, $attributs = []) { + $notices_domains = Class_NoticeDomain::findAllBy(array_merge(['panier_id' => $id_cart], + $attributs)); + + foreach ($notices_domains as $notice_domain) { + //Class_NoticeDomain::deleteRecordsFacetteForCart($notice_domain->getDomainId(), $notice_domain->getPanierId()); + $notice_domain->delete(); + } } - public function deleteAll() { - Zend_Registry::get('sql')->execute("delete from notice_domain"); + + public function deleteByDomain($domain) { + $notices_domains = Class_NoticeDomain::findAllBy(['domain_id' => $domain->getId()]); + + foreach ($notices_domains as $notice_domain) { + //Class_NoticeDomain::deleteRecordsFacetteForDomain($notice_domain->getDomainId()); + $notice_domain->delete(); + } } } @@ -43,19 +152,36 @@ class Class_NoticeDomain extends Storm_Model_Abstract { $_table_primary = 'ID', $_loader_class = 'NoticeDomainLoader', $_belongs_to = ['domain' => ['model' => 'Class_Catalogue', - 'referenced_in' => 'domain_id']], - $_default_attribute_values = ['record_alpha_key' => '']; + 'referenced_in' => 'domain_id'], + 'panier_notice' => ['model' => 'Class_PanierNotice', + 'referenced_in' => 'panier_id']], + + $_default_attribute_values = ['panier_id' => 0, + 'record_alpha_key' => '']; public function save() { if(Class_NoticeDomain::getLoader()->findFirstBy(['domain_id' => $this->getDomainId(), - 'record_alpha_key' => $this->getRecordAlphaKey()])) + 'record_alpha_key' => $this->getRecordAlphaKey(), + 'panier_id' => $this->getPanierId()])) return true; return parent::save(); } + public function beforeDelete() { + if(!$record = $this->getNotice()) + return; + $record->deleteFacettes($this->getDomain()->getFacette())->save(); + } + + + public function afterDelete() { + Class_NoticeDomain::getLoader()->updateRecordsFacette($this->getDomainId()); + } + + public function getNotice() { return Class_Notice::findFirstBy(['clef_alpha' => $this->getRecordAlphaKey()]); } diff --git a/library/Class/PanierNotice.php b/library/Class/PanierNotice.php index e5732d15fc15ac3e245c457cecff3ed9963896c7..13dfa076395a18777006ab188189e51323dcffe0 100644 --- a/library/Class/PanierNotice.php +++ b/library/Class/PanierNotice.php @@ -50,17 +50,27 @@ class PanierNoticeLoader extends Storm_Model_Loader { public function findAllWithCatalogue() { $this->user = Class_Users::getIdentity(); - return array_unique(array_map( - function($association) {return $association->getPanierNotice();}, - Class_PanierNoticeCatalogue::findAll())); + return array_filter( + array_unique( + array_map( + function($association) {return $association->getPanierNotice();}, + Class_PanierNoticeCatalogue::findAll()))); + } + + public function indexAll() { + Class_NoticeDomain::deleteBy(['panier_id not' => 0]); + $cart_to_index = Class_PanierNotice::findAllWithCatalogue(); + foreach($cart_to_index as $cart) { + $cart->index(); + } } } class Class_PanierNotice extends Storm_Model_Abstract { - use Trait_Translator; + use Trait_Translator, Trait_Indexable; const NOTICES_SEPARATOR = ';'; @@ -88,10 +98,38 @@ class Class_PanierNotice extends Storm_Model_Abstract { } + public function index() { + foreach($this->getNoticesAsArray() as $notice) { + $this->indexIntoDomain($notice); + } + + return $this; + } + + + protected function indexIntoDomain( $notice ) { + if(!$catalogues = $this->getCatalogues()) + return Class_NoticeDomain::deleteByCart($this->getId()); + + foreach($catalogues as $domain) { + $params = ['domain_id' => $domain->getId(), + 'panier_id' => $this->getId(), + 'record_alpha_key' => $notice->getClefAlpha()]; + + if($delete = Class_NoticeDomain::findFirstBy($params)) + $delete->delete(); + + Class_NoticeDomain::newInstance($params)->save(); + Class_NoticeDomain::updateRecordsFacette($domain->getId()); + } + } + + public static function newPanierForUser($user) { return (new Class_PanierNotice())->initializeForUser($user); } + public function initializeForUser($user){ $panier = (new Class_PanierNotice()) ->setLibelle('Nouveau panier') @@ -124,14 +162,16 @@ class Class_PanierNotice extends Storm_Model_Abstract { public function getClesNotices() { - $cles = array(); + $cles = []; $notices_field = $this->_get('notices'); - if (empty($notices_field)) return $cles; + if(empty($notices_field)) + return $cles; + $exploded_cles = explode(self::NOTICES_SEPARATOR, $notices_field); - foreach($exploded_cles as $cle) { - if (empty($cle) || !trim($cle)) continue; + foreach($exploded_cles as $cle) { + if(empty($cle) || !trim($cle)) continue; $cles []= $cle; } @@ -165,7 +205,7 @@ class Class_PanierNotice extends Storm_Model_Abstract { $notices = $this->getNoticesAsArray(); if (!$only_vignettes) return $notices; - return array_filter($notices, function($notice) {return $notice->hasVignette();}); + return array_values(array_filter($notices, function($notice) {return $notice->hasVignette();})); } @@ -211,9 +251,41 @@ class Class_PanierNotice extends Storm_Model_Abstract { public function beforeSave() { - $user=Class_Users::getIdentity(); + $user = Class_Users::getIdentity(); + if ($user && $user->getIdabon()) $this->setIdabon($user->getIdabon()); + + if($this->hasChange()) + $this->setDateMaj(date('Y-m-d')); + + $this->unindex(); + } + + + public function beforeDelete() { + return Class_NoticeDomain::deleteByCart($this->getId()); + } + + + public function unindex() { + if(!$records_from_cart = $this->getNoticesAsArray()) { + return Class_NoticeDomain::deleteByCart($this->getId()); + } + + if(!$domains_from_cart = $this->getCatalogues()) + return Class_NoticeDomain::deleteByCart($this->getId()); + + $records_from_db = Class_NoticeDomain::getRecordsFromCart($this->getId()); + + foreach(array_diff($records_from_db, $records_from_cart) as $record) + Class_NoticeDomain::deleteByCart($this->getId(), ['record_alpha_key' => $record->getAlphaKey()]); + + $domains_from_db = Class_NoticeDomain::getDomainsFromCart($this->getId()); + foreach(array_diff($domains_from_db, $domains_from_cart) as $domain) + Class_NoticeDomain::deleteByCart($this->getId(), ['domain_id' => $domain->getId()]); + + return $this; } @@ -354,7 +426,7 @@ class Class_PanierNotice extends Storm_Model_Abstract { $owner_id = $owner->getId(); if (!isset($users_paniers[$owner_id])) - $users_paniers[$owner_id] = ['id' => $owner_id, + $users_paniers[$owner_id] = ['id' => 'cart-owner-id-' . $owner_id, 'label' => $owner->getNomComplet(), 'categories' => [], 'items' => [], diff --git a/library/Class/Rss.php b/library/Class/Rss.php index f1fa19c40d52a8bd7e1bc04b9635985e29195537..486cb609f01b991c909d249990987ffc4ebc98c0 100644 --- a/library/Class/Rss.php +++ b/library/Class/Rss.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once dirname(__FILE__)."/CompositeBuilder.php"; @@ -41,6 +41,7 @@ class Class_RssModelFlux extends BaseItem { } class RssLoader extends Storm_Model_Loader { + use Trait_Indexable; /** * @param array $id_feeds * @param array $id_categories @@ -586,6 +587,12 @@ class Class_Rss extends Storm_Model_Abstract { return ($html); } } + + + public function acceptClefAlphaVisitor($visitor) { + $visitor->visitTitre($this->getTitre()) + ->visitTypeDocId(Class_TypeDoc::RSS); + } } ?> diff --git a/library/Class/Sitotheque.php b/library/Class/Sitotheque.php index 684ea897578bc0f0dacc57f0eab2cc86a3be2fd9..922200d3e47735a3df60f341f77934b338b32dd2 100644 --- a/library/Class/Sitotheque.php +++ b/library/Class/Sitotheque.php @@ -100,21 +100,18 @@ class SitothequeLoader extends Storm_Model_Loader { public function indexAll() { - $total = Class_Sitotheque::countBy([]); - $split = 500; - $nb_pages= ceil($total/$split); - for ($page=1;$page<=$nb_pages; $page++) { - $sito_to_index = Class_Sitotheque::findAllBy(['limitPage' => [$page,$split]]); - foreach($sito_to_index as $sito) { + $page= 1; + while($sito_to_index = Class_Sitotheque::findAllBy(['limitPage' => [$page, 500]])) { + foreach($sito_to_index as $sito) $sito->index(); - } + Class_Sitotheque::clearCache(); + $page++; } } } - class Class_Sitotheque extends Storm_Model_Abstract { use Trait_Translator, Trait_TreeViewableItem, Trait_HasManyDomaines, Trait_Indexable; @@ -263,5 +260,9 @@ class Class_Sitotheque extends Storm_Model_Abstract { } + public function acceptClefAlphaVisitor($visitor) { + $visitor->visitTitre($this->getTitre()) + ->visitTypeDocId($this->getTypeDocId()); + } } ?> \ No newline at end of file diff --git a/library/Class/Users.php b/library/Class/Users.php index 07a920ba9a9a1506a4ca7935e3159a795d86e462..94306560d3fddd535bd7abd6734aef2c67b47205 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -1288,10 +1288,9 @@ class Class_Users extends Storm_Model_Abstract { public function getEditablePaniers() { $user_paniers = $this->getPaniers(); if ($this->canAccessBackend()) - $user_paniers = array_unique(array_merge($user_paniers, - array_filter(Class_PanierNotice::findAllWithCatalogue()))); + $user_paniers = array_filter(array_unique(array_merge($user_paniers, + Class_PanierNotice::findAllWithCatalogue()))); Class_PanierNotice::sortPaniersByLibelle($user_paniers); - return $user_paniers; } diff --git a/library/Class/WebService/BibNumerique/Cyberlibris.php b/library/Class/WebService/BibNumerique/Cyberlibris.php index 09b868e7568b280db5589a7e65894cd429c13478..4fdbd26eeb792bcae576a25a602ca68094970ddd 100644 --- a/library/Class/WebService/BibNumerique/Cyberlibris.php +++ b/library/Class/WebService/BibNumerique/Cyberlibris.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -32,7 +32,7 @@ class Class_WebService_BibNumerique_Cyberlibris extends Class_WebService_BibNume ->deleteBy(['where' => 'url_origine="'.self::BASE_URL.'" and id_origine not in (\'' . implode("', '", $this->getHarvestedIds()) . '\')']); } - + protected function _importRessources($ressources) { $harvestedIds = []; $this->_albums = []; @@ -49,7 +49,7 @@ class Class_WebService_BibNumerique_Cyberlibris extends Class_WebService_BibNume protected function loadPage($page_number = 1) { $reader = (new Class_WebService_BibNumerique_Cyberlibris_LivresNumeriquesReader()); - $reader->parse(); + $reader->parse(''); return $reader; } diff --git a/library/Class/WebService/BibNumerique/Cyberlibris/LivresNumeriquesReader.php b/library/Class/WebService/BibNumerique/Cyberlibris/LivresNumeriquesReader.php index 1b0cbd4da0083965b9758520215e74d147d7f20b..ff989966eb93f804fc92722c9f23d7be4bfcf85c 100644 --- a/library/Class/WebService/BibNumerique/Cyberlibris/LivresNumeriquesReader.php +++ b/library/Class/WebService/BibNumerique/Cyberlibris/LivresNumeriquesReader.php @@ -36,7 +36,7 @@ class Class_WebService_BibNumerique_Cyberlibris_LivresNumeriquesReader extends C } - public function parse() { + public function parse($xml) { $this->_total_count = $this->_page_number = 0; $this->_page_size = 1; $this->livres = []; diff --git a/library/Trait/Indexable.php b/library/Trait/Indexable.php index 2062f1df2a59b255b4461897252ed0da2372a301..f2334fb54e4db926c2a6255dd65ab64d13891eea 100644 --- a/library/Trait/Indexable.php +++ b/library/Trait/Indexable.php @@ -39,10 +39,12 @@ trait Trait_Indexable { Class_NoticeDomain::deleteBy(['record_alpha_key' => $alpha_key]); - foreach($domains_ids as $domain) { - Class_NoticeDomain::newInstance(['domain_id' => $domain, + foreach($domains_ids as $domain_id) { + Class_NoticeDomain::newInstance(['domain_id' => $domain_id, 'record_alpha_key' => $alpha_key]) ->save(); + + Class_NoticeDomain::updateRecordsFacette($domain_id); } return $this; @@ -55,14 +57,22 @@ trait Trait_Indexable { public function unindex() { - if (empty($this->getDomaineIds())) { - Class_NoticeDomain::deleteBy(['record_alpha_key' => Class_Indexation_PseudoNotice::getAlphaKey($this) ]); + $alpha_key = $this->getAlphaKey(); + + if (empty($domains = $this->getDomaines())) { + Class_NoticeDomain::deleteBy(['record_alpha_key' => $alpha_key, + 'panier_id' => 0]); } + + $domains_in_db = Class_NoticeDomain::getDomainsForRecordAlphaKey($alpha_key); + + foreach(array_diff($domains_in_db, $domains) as $domain) + Class_NoticeDomain::deleteBy(['domain_id' => $domain->getId()]); } public function getAlphaKey() { - return Class_Indexation_PseudoNotice::getAlphaKey($this); + return (new Class_Notice_ClefAlpha($this))->keyString(); } } ?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Notice/Unimarc.php b/library/ZendAfi/View/Helper/Notice/Unimarc.php index 8fda09b962f478d27a34a19004a6121480fe7795..7f32dee82e99bbf72d31b200878e16e6cda643db 100644 --- a/library/ZendAfi/View/Helper/Notice/Unimarc.php +++ b/library/ZendAfi/View/Helper/Notice/Unimarc.php @@ -32,7 +32,25 @@ class ZendAfi_View_Helper_Notice_Unimarc extends Zend_View_Helper_HtmlElement { $reader->setNotice($notice->getUnimarc(), 0); $reader->acceptVisitor($this); - return $this->renderHeader($notice) . '<hr>' . $this->renderZones(); + return + $this->renderHeader($notice) + . '<hr>' + . $this->renderNotice($notice) + . '<hr>' + . $this->renderZones(); + } + + + protected function renderNotice($notice) { + $fields = ['facettes' => $this->_('Facettes'), + 'date_creation' => $this->_('Création / nouveauté'), + 'date_maj' => $this->_('Mis à jour le'), + 'clef_alpha' => $this->_('Clé alpha'), + 'clef_oeuvre' => $this->_('Clé oeuvre')]; + $html = ''; + foreach ($fields as $field => $label) + $html .= $label . ': ' . $notice->callGetterByAttributeName($field) . '<br>'; + return $html; } diff --git a/library/ZendAfi/View/Helper/TagCriteresRecherche.php b/library/ZendAfi/View/Helper/TagCriteresRecherche.php index ab1e382f282c4632ecab805c5a450d5bf8273c02..e78627e92c6a75c0057031dcd51c74239f4859f3 100644 --- a/library/ZendAfi/View/Helper/TagCriteresRecherche.php +++ b/library/ZendAfi/View/Helper/TagCriteresRecherche.php @@ -194,15 +194,19 @@ class ZendAfi_View_Helper_TagCriteresRecherche extends Zend_View_Helper_HtmlElem } - public function visitPage($page) { - } + public function visitPage($page) {} - public function visitTri($tri, $libelle) { - } + public function visitDomain($criteres) {} + + + public function visitTri($tri, $libelle) {} + + + public function visitFilterOnDomain($criteres) {} - public function visitFilterOnDomain() {} + public function visitFacetteDomainForOrConditions($facette) {} } ?> \ No newline at end of file diff --git a/library/startup.php b/library/startup.php index c19f7a9056f7fd712eee54ca1210034d3cb3ce6d..b8c2dbe29ba6d5cd4af5acf412b03f4a9d3e6c06 100644 --- a/library/startup.php +++ b/library/startup.php @@ -48,14 +48,12 @@ function setupOpac() { } - function defineConstant($name, $value) { if (!defined($name)) define($name, $value); } - function setupConstants() { defineConstant('BOKEH_MAJOR_VERSION','7.1'); defineConstant('BOKEH_RELEASE_NUMBER', BOKEH_MAJOR_VERSION . '.4'); @@ -102,6 +100,7 @@ function setupConstants() { defineConstant('PATH_FONTS', ROOT_PATH . 'public/opac/fonts/'); defineConstant('URL_CAPTCHA', BASE_URL . '/public/captcha/'); defineConstant('PATH_CAPTCHA', ROOT_PATH . 'public/captcha/'); + defineConstant('CACHE_LIFETIME', 3600); defineConstant('MEMCACHED_ENABLE', false); defineConstant('MEMCACHED_HOST', 'localhost'); defineConstant('MEMCACHED_PORT', '11211'); @@ -129,11 +128,11 @@ function loadConfig($config_init_file_path = './config.ini') { } - - function setupCache($cfg) { - $frontendOptions = [ - 'lifetime' => 3600, // durée du cache: 1h + if (Class_Users::isCurrentUserCanAccesBackend()) + return; + + $frontendOptions = ['lifetime' => CACHE_LIFETIME, // durée du cache: 1h 'automatic_serialization' => false, 'caching' => true]; @@ -149,14 +148,12 @@ function setupCache($cfg) { $frontendOptions, $backendOptions); // $cache->clean(Zend_Cache::CLEANING_MODE_ALL); - Zend_Registry::set('cache', $cache); + Storm_Cache::setDefaultZendCache($cache); Storm_Cache::setSeed($cfg->sgbd->config->dbname); } - - function setupSession($cfg) { // Start Session $session = new Zend_Session_Namespace(md5(BASE_URL)); @@ -170,7 +167,6 @@ function setupSession($cfg) { } - function setupLanguage() { Zend_Locale::setDefault(Class_AdminVar::getDefaultLanguage()); Zend_Registry::set('locale', new Zend_Locale()); @@ -187,8 +183,6 @@ function setupLanguage() { } - - function setupDatabase($cfg) { // setup database $sql = Zend_Db::factory($cfg->sgbd->adapter, $cfg->sgbd->config->toArray()); @@ -202,7 +196,6 @@ function setupDatabase($cfg) { } - function setupDevOptions($cfg) { //permet d'activer les fonctions en développement if (null !== $experimental_dev = $cfg->get('experimental_dev')) @@ -210,8 +203,6 @@ function setupDevOptions($cfg) { } - - function setupControllerActionHelper() { Zend_Controller_Action_HelperBroker::resetHelpers(); Zend_Controller_Action_HelperBroker::addHelper(new ZendAfi_Controller_Action_Helper_ViewRenderer()); @@ -219,8 +210,6 @@ function setupControllerActionHelper() { } - - function setupHTTPClient($cfg) { //set up HTTP Client to use proxy settings $httpClient = new Zend_Http_Client(); diff --git a/library/storm b/library/storm index 63c9c4af2a478b6eceafddcc259f49316c7f88cb..25ca343bac14e3227379c588cdccedd3df5b5a31 160000 --- a/library/storm +++ b/library/storm @@ -1 +1 @@ -Subproject commit 63c9c4af2a478b6eceafddcc259f49316c7f88cb +Subproject commit 25ca343bac14e3227379c588cdccedd3df5b5a31 diff --git a/tests/application/modules/admin/controllers/AccueilControllerTest.php b/tests/application/modules/admin/controllers/AccueilControllerTest.php index 9619879583b39cc35acb62c15d4545f0569596b9..65318879f5974e8bc9a87391c57969a262d4ce11 100644 --- a/tests/application/modules/admin/controllers/AccueilControllerTest.php +++ b/tests/application/modules/admin/controllers/AccueilControllerTest.php @@ -544,7 +544,7 @@ class AccueilControllerWithParentProfileConfigBoiteLoginPostTest -class AccueilControllerPostConfigBoiteKiosqueProfilLognesTestCase extends Admin_AbstractControllerTestCase { +class AccueilControllerPostConfigBoiteKiosqueProfilLognesTest extends Admin_AbstractControllerTestCase { public function setUp() { parent::setUp(); diff --git a/tests/application/modules/admin/controllers/AlbumControllerPharoVideosTest.php b/tests/application/modules/admin/controllers/AlbumControllerPharoVideosTest.php index a0f8d1b216cf52135c7969e59f32600dd749ac28..b644964ebb1336eeff6add240e324d1126dcc4a2 100644 --- a/tests/application/modules/admin/controllers/AlbumControllerPharoVideosTest.php +++ b/tests/application/modules/admin/controllers/AlbumControllerPharoVideosTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'AdminAbstractControllerTestCase.php'; @@ -29,7 +29,7 @@ abstract class Admin_AlbumControllerPharoVideosTestCase extends Admin_AbstractCo 'libelle' => 'Languages de prog.']) ]); Class_AlbumRessource::beVolatile(); - + } } @@ -75,6 +75,7 @@ class Admin_AlbumControllerPharoVideosPostAddTest extends Admin_AlbumControllerP public function setUp() { parent::setUp(); + Class_Exemplaire::beVolatile(); $this->postDispatch('/admin/album/add-ressource/id/777', ['url' => 'http://www.pharocast.org', 'media_type' => 3, 'duration' => '00:20:00', diff --git a/tests/application/modules/admin/controllers/AlbumControllerTest.php b/tests/application/modules/admin/controllers/AlbumControllerTest.php index 0ce93bc9581dd47237a30a2ade84b5c40b777fc5..3097862887d8574370f20b19e5cf04129093fd45 100644 --- a/tests/application/modules/admin/controllers/AlbumControllerTest.php +++ b/tests/application/modules/admin/controllers/AlbumControllerTest.php @@ -1554,8 +1554,11 @@ class Admin_AlbumControllerPostEditAlbumMesBDTest extends Admin_AlbumControllerT ->save(); $this->cache_mock = $this->mock() - ->whenCalled('clean') - ->answers(true); + ->whenCalled('save') + ->answers(true) + + ->whenCalled('clean') + ->answers(true); Storm_Cache::setDefaultZendCache($this->cache_mock); $this->postDispatch('/admin/album/edit_album/id/43', diff --git a/tests/application/modules/admin/controllers/CatalogueControllerTest.php b/tests/application/modules/admin/controllers/CatalogueControllerTest.php index 381c6dd6b116b8ee7390ea13fda263f6d4eb8f98..c59af9b2f539a5a20df1d199ff26aaa128da2998 100644 --- a/tests/application/modules/admin/controllers/CatalogueControllerTest.php +++ b/tests/application/modules/admin/controllers/CatalogueControllerTest.php @@ -1325,13 +1325,22 @@ class CatalogueControllerDomaintePaniersJsonActionTest extends AbstractControlle public function setup() { parent::setup(); - - Class_Users::beVolatile(); Class_Catalogue::beVolatile(); - Class_PanierNotice::beVolatile(); + + $this->fixture('Class_PanierNotice', + ['id' => 22, + 'libelle' => 'Top 5 CDs']); + + $this->fixture('Class_Users', + ['id' => 22, + 'login' => 'Marie-Laure', + 'password' => 'only1Password'])->addPanier(Class_PanierNotice::find(22)) + ->setRoleLevel(ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL) + ->save(); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_PanierNotice') ->whenCalled('findAllBelongsToAdmin') - ->answers([]); + ->answers([Class_PanierNotice::find(22)]); } @@ -1356,14 +1365,19 @@ class CatalogueControllerDomaintePaniersJsonActionTest extends AbstractControlle ['id' => 'paniers_by_users', 'label' => 'Paniers sans domaine, rattachés à leur créateur', - 'categories' => [], + 'categories' => [22 => ['id' => 'cart-owner-id-22', + 'label' => 'Marie-Laure', + 'categories' => [], + 'items' => [['id' => 22, + 'label' => 'Top 5 CDs', + 'options' => ['ico' => URL_ADMIN_IMG.'picto/paniers_16.png']]], + 'options' => ['ico' => URL_ADMIN_IMG.'picto/abonnes.gif', + 'removeCheckbox' => true]]], 'items' => [], 'options' => ['multipleSelection' => false]]]; - - $this->assertJsonStringEqualsJsonString(json_encode($expectedJSON), - $this->_response->getBody(),json_encode($this->_response->getBody())); + $this->_response->getBody(), $this->_response->getBody()); } } @@ -1390,4 +1404,119 @@ class AdminCatalogueControllerEditCatalogueWithWrongGenre extends AbstractContro $this->assertXPath('//input[@name="genre"][@value=""]', $this->_response->getBody()); } } -?> + + + +class AdminCatalogueControllerUnindexOnDeleteTest extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + $this->fixture('Class_Notice', + ['id' => 1456, + 'clef_alpha' => 'POMME', + 'facettes' => 'Q1']); + + $this->fixture('Class_Catalogue', + ['id' => 1, + 'libelle' => 'new books']); + + $this->fixture('Class_NoticeDomain', + ['id' => 456, + 'domain_id' => 1, + 'panier_id' => 0, + 'record_alpha_key' => 'POMME']); + + $this->dispatch('/admin/catalogue/delete/id_catalogue/1', true); + } + + + /** @test */ + public function noRecordShouldContainsFacetH1() { + $this->assertNotContains('Q1', Class_Notice::find(1456)->getFacettes()); + } + + + /** @test */ + public function noticeDomainShouldBeEmpty() { + $this->assertEmpty(Class_NoticeDomain::findAll()); + } +} + + + +class CatalogueControllerPaniersRemovePanierAndUnindexTest extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + Class_PanierNoticeCatalogue::beVolatile(); + Class_PanierNotice::beVolatile(); + + $pomme = $this->fixture('Class_Notice', + ['id' => 1456, + 'clef_alpha' => 'POMME', + 'facettes' => '']); + + $poire = $this->fixture('Class_Notice', + ['id' => 897, + 'clef_alpha' => 'POIRE', + 'facettes' => 'Q98']); + + $this->fixture('Class_Catalogue', + ['id' => 98, + 'libelle' => 'new books']); + + $this->fixture('Class_NoticeDomain', + ['id' => 654, + 'domain_id' => 98, + 'panier_id' => 0, + 'record_alpha_key' => 'POIRE']); + + $this->fixture('Class_PanierNotice', + ['id' => 951, + 'notices' => '', + 'domaine_ids' => '98']) + ->addNotice($poire) + ->addNotice($pomme) + ->save(); + + Class_PanierNotice::indexAll(); + + $this->dispatch('admin/catalogue/paniers/id_catalogue/98/remove/951', true); + } + + + /** @test */ + public function poireShouldHaveQ1Facet() { + $this->assertContains('Q98', Class_Notice::find(897)->getFacettes()); + } + + + /** @test */ + public function noticeDomainForPoireAndBooksShouldExist() { + $this->assertNotNull(Class_NoticeDomain::findFirstBy(['record_alpha_key' => 'POIRE', + 'domain_id' => 98, + 'panier_id' => 0])); + } + + + /** @test */ + public function noticeDomainForPoireAndBooksAndCartShouldNotExist() { + $this->assertNull(Class_NoticeDomain::findFirstBy(['record_alpha_key' => 'POIRE', + 'domain_id' => 98, + 'panier_id' => 951])); + } + + + /** @test */ + public function linkBetweenPommeAndDomainShouldBeDeleted() { + $this->assertNull(Class_NoticeDomain::findFirstBy(['domain_id' => 98, + 'panier_id' => 951, + 'record_alpha_key' => 'POMME'])); + } + + + /** @test */ + public function pommeShouldNotContainsFacetH1() { + $this->assertNotContains('Q98', Class_Notice::find(1456)->getFacettes()); + } +} \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php index 86624b10c8cf2ca0ad80899d70bc5803c08887fd..164c315aca1935766377030079cf8db377d5423e 100644 --- a/tests/application/modules/admin/controllers/CmsControllerTest.php +++ b/tests/application/modules/admin/controllers/CmsControllerTest.php @@ -29,6 +29,7 @@ abstract class CmsControllerTestCase extends Admin_AbstractControllerTestCase { public function setUp() { parent::setUp(); $this->setupBib(); + Class_Exemplaire::beVolatile(); Class_CustomField::beVolatile(); Class_CustomField_Meta::beVolatile(); $this->_laurent = $this->fixture('Class_Users', ['id'=>20, @@ -224,7 +225,7 @@ abstract class CmsControllerTestCase extends Admin_AbstractControllerTestCase { class CmsControllerArticleEditWithoutLanguesTest extends CmsControllerTestCase { public function setUp() { parent::setUp(); - + Class_Exemplaire::beVolatile(); Class_AdminVar::getLoader() ->newInstanceWithId('LANGUES') ->setValeur(''); @@ -241,7 +242,6 @@ class CmsControllerArticleEditWithoutLanguesTest extends CmsControllerTestCase { - class CmsControllerArticleConcertAsAdminPortailEditActionTest extends CmsControllerTestCase { protected function _loginHook($account) { $account->ROLE = "admin_portail"; @@ -253,7 +253,7 @@ class CmsControllerArticleConcertAsAdminPortailEditActionTest extends CmsControl Class_Users::getLoader() ->getIdentity() ->setRoleLevel(ZendAfi_Acl_AdminControllerRoles::ADMIN_PORTAIL); - + Class_Exemplaire::beVolatile(); $this->dispatch('/admin/cms/edit/id/4', true); } @@ -804,6 +804,7 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerTestCas Class_Notice::beVolatile(); Class_NoticeDomain::beVolatile(); Class_IntBib::beVolatile(); + Class_Exemplaire::beVolatile(); $this->fixture('Class_Article', ['id' => 4, @@ -847,7 +848,8 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerTestCas /** @test */ public function clefAlphaShouldBeAsExpected() { - $this->assertEquals('ERIKTRUFFAZLADYLANDQUARTETENCONCERT------8', Class_Indexation_PseudoNotice::getAlphaKey(Class_Article::find(4))); + $this->assertEquals('ERIKTRUFFAZLADYLANDQUARTETENCONCERT------8', + Class_Article::find(4)->getAlphaKey()); } @@ -2347,7 +2349,7 @@ class CmsControllerCategoriesActionTest extends AbstractControllerTestCase { class CmsControllerEditActionWithCustomFieldsTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); - + Class_Exemplaire::beVolatile(); Class_CustomField_Meta::beVolatile(); $this->fixture('Class_CustomField', ['id' => 5, diff --git a/tests/application/modules/admin/controllers/HarvestControllerTest.php b/tests/application/modules/admin/controllers/HarvestControllerTest.php index 9408ce5adba3b9283a2af8a5758d323e5afb19da..f74a94ef0eb32848589a5ced35e4fc4e4fb53a84 100644 --- a/tests/application/modules/admin/controllers/HarvestControllerTest.php +++ b/tests/application/modules/admin/controllers/HarvestControllerTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'AdminAbstractControllerTestCase.php'; @@ -122,7 +122,7 @@ class HarvestControllerArteVodActionNotActivatedTest extends HarvestControllerAr class HarvestControllerArteVodActivatedWithErrorTest extends HarvestControllerArteVodActivatedTestCase { public function setUp() { parent::setUp(); - $this->dispatch('/admin/harvest/arte-vod', true); + $this->dispatch('/admin/harvest/arte-vod', true); } @@ -146,10 +146,13 @@ class HarvestControllerArteVodActivatedWithFilmsTest extends HarvestControllerAr parent::setUp(); $this->cache_mock = $this->mock() - ->whenCalled('clean') - ->answers(true); + ->whenCalled('save') + ->answers(true) + + ->whenCalled('clean') + ->answers(true); (new Storm_Cache())->setDefaultZendCache($this->cache_mock); - $this->dispatch('/admin/harvest/arte-vod', true); + $this->dispatch('/admin/harvest/arte-vod', true); } diff --git a/tests/application/modules/admin/controllers/IndexControllerTest.php b/tests/application/modules/admin/controllers/IndexControllerTest.php index e150d634fba89cd7f8a35786e4648f38fc1bdb3b..8ab74d02ab33189cccf23e9daa4ee6f2d23f290c 100644 --- a/tests/application/modules/admin/controllers/IndexControllerTest.php +++ b/tests/application/modules/admin/controllers/IndexControllerTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'AdminAbstractControllerTestCase.php'; @@ -59,4 +59,17 @@ class IndexControllerHeartBeatTest extends Admin_AbstractControllerTestCase { } -?> \ No newline at end of file + +class IndexControllerClearCacheActionTest extends Admin_AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + Storm_Cache::beVolatile(); + $this->dispatch('/admin/index/clearcache', true); + } + + + /** @test */ + public function clearCacheShouldRedirectToAdminVar() { + $this->assertRedirectTo('/admin/index/adminvar'); + } +} \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/ModulesControllerTest.php b/tests/application/modules/admin/controllers/ModulesControllerTest.php index a7f93d5d8042af25c9091068a9934c2e27213549..ba59622c2aab83d006d3f0a210d4577ad228a5f5 100644 --- a/tests/application/modules/admin/controllers/ModulesControllerTest.php +++ b/tests/application/modules/admin/controllers/ModulesControllerTest.php @@ -613,16 +613,23 @@ abstract class ModulesControllerChangeKiosqueSelectionTestCase extends Admin_Abs $_SERVER['HTTP_REFERER'] = 'opac/index'; - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Profil') - ->whenCalled('save') - ->answers(true); + Class_Profil::beVolatile(); + + $this->fixture('Class_Catalogue', + ['id' => 22, + 'libelle' => 'Books']); + + $this->fixture('Class_PanierNotice', + ['id' => 555, + 'libelle' => 'Top 5 Books']); Class_Profil::getCurrentProfil() ->updateModuleConfigAccueil(3, ['type_module' => 'KIOSQUE', 'division' => 4, 'id_module' => 3, - 'preferences' => ['id_panier' => 555]]); + 'preferences' => ['id_panier' => 555, + 'id_catalogue' => 22]]); } } @@ -652,7 +659,7 @@ class ModulesControllerChangeKiosqueSelectionPostSaveIdCatalogueTest extends Mod $this->postDispatch('/admin/modules/kiosque-change-data/id_module/3', ['id_catalogue' => 5, 'id_panier' => 0]); - $this->saved_preferences = Class_Profil::getFirstAttributeForLastCallOn('save') + $this->saved_preferences = Class_Profil::getCurrentProfil() ->getModuleAccueilPreferences(3, 'KIOSQUE'); } @@ -680,7 +687,7 @@ class ModulesControllerChangeKiosqueSelectionPostSaveNullPanierTest extends Modu $this->postDispatch('/admin/modules/kiosque-change-data/id_module/3', ['id_panier' => 0, 'id_catalogue' => 0]); - $this->saved_preferences = Class_Profil::getFirstAttributeForLastCallOn('save') + $this->saved_preferences = Class_Profil::getCurrentProfil() ->getModuleAccueilPreferences(3, 'KIOSQUE'); } diff --git a/tests/application/modules/admin/controllers/SitothequeControllerTest.php b/tests/application/modules/admin/controllers/SitothequeControllerTest.php index f49268a6a2fedeae593ccc777e599e6678477f13..b07d08fc6ce1c9ac62a25bb9487bffc8714f5ed0 100644 --- a/tests/application/modules/admin/controllers/SitothequeControllerTest.php +++ b/tests/application/modules/admin/controllers/SitothequeControllerTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'AdminAbstractControllerTestCase.php'; @@ -25,34 +25,34 @@ abstract class SitothequeControllerTestCase extends Admin_AbstractControllerTest public function setUp() { parent::setUp(); - - $this->setupDomaines(); + $this->setupDomaines(); + Class_Exemplaire::beVolatile(); Class_Notice::beVolatile(); Class_CodifThesaurus::beVolatile(); $categorie_informations = $this->fixture('Class_SitothequeCategorie', - ['id' => 2, + ['id' => 2, 'libelle' => 'Informations', 'id_site' => 3, 'sous_categories' => [], 'sitotheques' => [ $this->fixture('Class_Sitotheque', - ['id' => 22, + ['id' => 22, 'titre' => 'Le Canard', 'url' => 'http://www.canard.fr', 'description' => 'indépendant', 'domaine_ids' => [10]]), $this->_le_monde = $this->fixture('Class_Sitotheque', - ['id' => 23, + ['id' => 23, 'titre' => 'Le Monde', 'url' => 'http://www.monde.fr'])] ]); - + $bib_annecy = $this->fixture('Class_Bib', - ['id' => 3, + ['id' => 3, 'libelle' => 'Annecy', 'sitotheque_categories' => [$categorie_informations]]); @@ -94,7 +94,7 @@ class SitothequeControllerIndexTest extends SitothequeControllerTestCase { $this->dispatch('/admin/sito/index/id/5/id_cat/34', true); } - + /** @test */ public function pageShouldContainsDivTreeView() { $this->assertXPath('//div[@class="treeView"]'); @@ -107,7 +107,7 @@ class SitothequeControllerIndexTest extends SitothequeControllerTestCase { 'Ajouter une catégorie'); } - + /** @test */ public function liWithSiteLeCanardShouldBePresent() { $this->assertXPathContentContains('//ul/li[1]//div', 'Le Canard'); @@ -154,9 +154,9 @@ class SitothequeControllerSitoEditTest extends SitothequeControllerTestCase { } - /** + /** * @group integration - * @test + * @test */ public function pageShouldBeHtml5Valid() { $this->assertHTML5(); @@ -168,7 +168,7 @@ class SitothequeControllerSitoEditTest extends SitothequeControllerTestCase { $this->assertXPathContentContains('//textarea[@name="description"]', 'indépendant'); } - + /** @test */ public function formShouldActionShouldBeSitoEditId22() { $this->assertXPath('//form[contains(@action, "admin/sito/sitoedit/id/22")]', @@ -198,7 +198,7 @@ class SitothequeControllerSitoViewTest extends SitothequeControllerTestCase { $this->dispatch('/admin/sito/sitoview/id/22', true); } - + /** @test */ public function responseShouldRedirectToCanardFr() { $this->assertRedirectTo('http://www.canard.fr'); @@ -233,14 +233,19 @@ class SitothequeControllerPostAddActionTest extends SitothequeControllerTestCase public function setUp() { parent::setUp(); - $this->cache = Storm_Test_ObjectWrapper::mock()->whenCalled('clean')->answers(true); + $this->cache = Storm_Test_ObjectWrapper::mock() + ->whenCalled('save') + ->answers(true) + + ->whenCalled('clean') + ->answers(true); Storm_Cache::setDefaultZendCache($this->cache); - $this->postDispatch('/admin/sito/sitoadd/id_cat/2', + $this->postDispatch('/admin/sito/sitoadd/id_cat/2', ['titre' => 'google', 'url' => 'http://www.google.fr', 'id_items' => '23-23', - 'domaine_ids' => 10], + 'domaine_ids' => 10], true); } @@ -272,7 +277,7 @@ class SitothequeControllerPostAddActionTest extends SitothequeControllerTestCase /** @test */ public function pseudoNoticeShouldHaveIndexForTypeDocAndDomaineHistoire() { - $this->assertEquals('T10 HC0001', Class_Notice::find(1)->getFacettes()); + $this->assertContains('T10 HC0001', Class_Notice::find(1)->getFacettes()); } /** @test */ @@ -302,7 +307,7 @@ class SitothequeControllerInvalidPostActionTest extends SitothequeControllerTest class SitothequeControllerSitoPostEditLeMondeTest extends SitothequeControllerTestCase { public function setUp() { parent::setUp(); - $this->postDispatch('/admin/sito/sitoedit/id/23', + $this->postDispatch('/admin/sito/sitoedit/id/23', ['titre' => 'Times'], true); Class_Sitotheque::clearCache(); @@ -364,7 +369,7 @@ class SitothequeControllerActionErrorsTest extends SitothequeControllerTestCase */ public function responseShouldRedirectToIndex($url) { $this->dispatch($url, true); - $this->assertRedirectTo('/admin/sito'); + $this->assertRedirectTo('/admin/sito'); } } @@ -396,7 +401,7 @@ class SitothequeControllerEditCategorieInformationsTest extends SitothequeContro class SitothequeControllerPostEditCategorieInformationsTest extends SitothequeControllerTestCase { public function setUp() { parent::setUp(); - $this->postDispatch('/admin/sito/catedit/id/2', + $this->postDispatch('/admin/sito/catedit/id/2', ['libelle' => 'News'], true); Class_SitothequeCategorie::clearCache(); @@ -438,7 +443,7 @@ class SitothequeControllerAddCategorieTest extends SitothequeControllerTestCase class SitothequeControllerPostAddEmptyCategorieTest extends SitothequeControllerTestCase { public function setUp() { parent::setUp(); - $this->postDispatch('/admin/sito/catadd/id/2', + $this->postDispatch('/admin/sito/catadd/id/2', ['libelle' => ''], true); } @@ -459,7 +464,7 @@ class SitothequeControllerPostAddCategorieNationalesTest extends SitothequeContr public function setUp() { parent::setUp(); - $this->postDispatch('/admin/sito/catadd/id/2', + $this->postDispatch('/admin/sito/catadd/id/2', ['libelle' => 'Nationales'], true); @@ -482,7 +487,7 @@ class SitothequeControllerPostAddCategorieInBibTest extends SitothequeController public function setUp() { parent::setUp(); - $this->postDispatch('/admin/sito/catadd/id_bib/5', + $this->postDispatch('/admin/sito/catadd/id_bib/5', ['libelle' => 'Dans la bib'], true); diff --git a/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php b/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php index d6c27d9b87bfa574ab6aec779d946c89f90540b7..c18f4296cf90cf42cc776627447823a29f611cd1 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerPretsTest.php @@ -41,6 +41,8 @@ abstract class AbstractAbonneControllerPretsTestCase extends AbstractControllerT $this->zend_cache = Storm_Test_ObjectWrapper::mock(); Storm_Cache::setDefaultZendCache($this->zend_cache); $this->zend_cache + ->whenCalled('save') + ->answers(true) ->whenCalled('remove') ->answers(true); } diff --git a/tests/application/modules/opac/controllers/CasServerControllerTest.php b/tests/application/modules/opac/controllers/CasServerControllerTest.php index df8fb1012514480e396f61dbab91a20946bb23b7..c67cef6acd870bf98c52ff74ae6bc2bed38d6cae 100644 --- a/tests/application/modules/opac/controllers/CasServerControllerTest.php +++ b/tests/application/modules/opac/controllers/CasServerControllerTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -26,46 +26,47 @@ class CasServerControllerValidateActionTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); + Storm_Cache::beVolatile(); $user = new StdClass(); $user->ID_USER=300; - Class_Users::newInstanceWithId(300, + Class_Users::newInstanceWithId(300, ['login' => '87364', 'pseudo' => 'georges']); - Zend_Registry::get('cache')->save('300', - md5(Zend_Session::getId().'300')); + (new Storm_Cache())->save('300', + md5(Zend_Session::getId().'300')); } - + /** @test */ - public function requestWithNoTicketShouldRespondinvalidRequestFailureXML() { + public function requestWithNoTicketShouldRespondinvalidRequestFailureXML() { $this->dispatch('/opac/cas-server/validate?service=http://test.com'); $this->assertContains('<cas:authenticationFailure code="INVALID_REQUEST">',$this->_response->getBody()); } /** @test */ - public function requestWithInvalidTicketShouldRespondInvalidTicketFailureXML() { + public function requestWithInvalidTicketShouldRespondInvalidTicketFailureXML() { $this->dispatch('/opac/cas-server/validate?ticket=STmarchepo&service=http://test.com',true); $this->assertContains('<cas:authenticationFailure code="INVALID_TICKET"> Ticket STmarchepo not recognized</cas:authenticationFailure>',$this->_response->getBody()); } /** @test */ - public function requestWithInvalidTicketOnAuthShouldRespondInvalidTicketFailureXML() { + public function requestWithInvalidTicketOnAuthShouldRespondInvalidTicketFailureXML() { $this->dispatch('/opac/auth/validate?ticket=STmarchepo&service=http://test.com',true); $this->assertContains('<cas:authenticationFailure code="INVALID_TICKET"> Ticket STmarchepo not recognized</cas:authenticationFailure>',$this->_response->getBody()); } /** @test */ - public function requestWithValidTicketShouldRespondValidXML() { + public function requestWithValidTicketShouldRespondValidXML() { $this->dispatch('/opac/cas-server/validate?ticket='.md5(Zend_Session::getId().'300').'&service=http://test.com'); $this->assertContains('<cas:user>300</cas:user>',$this->_response->getBody()); $this->assertContains('<cas:proxyGrantingTicket>',$this->_response->getBody()); } /** @test */ - public function requestWithValidTicketPrefixedBySTShouldRespondValidXML() { + public function requestWithValidTicketPrefixedBySTShouldRespondValidXML() { $this->dispatch('/opac/cas-server/validate?ticket=ST-'.md5(Zend_Session::getId().'300').'&service=http://test.com'); $this->assertContains('<cas:user>300</cas:user>',$this->_response->getBody()); $this->assertContains('<cas:proxyGrantingTicket>',$this->_response->getBody()); @@ -73,20 +74,20 @@ class CasServerControllerValidateActionTest extends AbstractControllerTestCase { /** @test */ - public function requestWithValidTicketPrefixedBySTOnAuthenticateControllerShouldRespondValidXML() { + public function requestWithValidTicketPrefixedBySTOnAuthenticateControllerShouldRespondValidXML() { $this->dispatch('/opac/auth/validate?ticket=ST-'.md5(Zend_Session::getId().'300').'&service=http://test.com'); $this->assertContains('<cas:user>300</cas:user>',$this->_response->getBody()); $this->assertContains('<cas:proxyGrantingTicket>',$this->_response->getBody()); } - /** + /** * see http://www.jasig.org/cas/protocol#validate-cas-1.0 - * @test + * @test */ public function validateOnCasOneZeroWithValidTicketShouldAnswerYesLFUsernameLogin() { $this->dispatch( - '/opac/cas-server-v10/validate?ticket=ST-'.md5(Zend_Session::getId().'300').'&service=http://test.com', + '/opac/cas-server-v10/validate?ticket=ST-'.md5(Zend_Session::getId().'300').'&service=http://test.com', true); $this->assertEquals('yes'.chr(10).'georges|87364'.chr(10), $this->_response->getBody()); } @@ -95,7 +96,7 @@ class CasServerControllerValidateActionTest extends AbstractControllerTestCase { /** @test */ public function validateOnCasOneZeroWithInValidTicketShouldAnswerNoLF() { $this->dispatch( - '/opac/cas-server-v10/validate?ticket=zork&service=http://test.com', + '/opac/cas-server-v10/validate?ticket=zork&service=http://test.com', true); $this->assertEquals('no'.chr(10), $this->_response->getBody()); } @@ -142,22 +143,23 @@ class CasServerControllerMusicMeValidateActionTest extends AbstractControllerTes public function setUp() { parent::setUp(); + Storm_Cache::beVolatile(); $tom = Class_Users::newInstanceWithId(300, ['nom' => 'Ate', 'prenom' => 'Tom']); ZendAfi_Auth::getInstance()->logUser($tom); } - + /** @test */ - public function requestMusicMeWithNoTicketShouldRespondAccountDisabledXML() { + public function requestMusicMeWithNoTicketShouldRespondAccountDisabledXML() { $this->dispatch('/opac/cas-server/validate-musicme?MediaLibraryID=150&ticket=ST-0a1b2c3d'); $this->assertContains('<User />',$this->_response->getBody()); } /** @test */ - public function requestMusicMeWithValidTicketShouldRespondValidXML() { + public function requestMusicMeWithValidTicketShouldRespondValidXML() { $this->dispatch('/opac/cas-server/validate-musicme?ticket=ST-'.md5(Zend_Session::getId().'300').'&MediaLibraryID=http://test.com'); $this->assertContains('<ID>300</ID>',$this->_response->getBody()); } diff --git a/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php b/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php index 9649a27c33d4a8c1a6e4fe90f90d2cb0461989d0..b49997b1ee78e045b625aa31be8421c5e6b6f65e 100644 --- a/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php +++ b/tests/application/modules/opac/controllers/CmsControllerCalendarActionTest.php @@ -75,10 +75,15 @@ class CmsControllerCalendarActionCacheTest extends CmsControllerCalendarActionTe public function setUp() { parent::setUp(); $cache = Storm_Test_ObjectWrapper::mock(); + $cache->whenCalled('save') + ->answers(true); + Storm_Cache::setDefaultZendCache($cache); $module_cal = new ZendAfi_View_Helper_Accueil_Calendar(1, $this->cfg_accueil['modules']['1']); $module_cal->setView(new ZendAfi_Controller_Action_Helper_View()); } + + /** * Test non-regression vu sur Bucarest (prenait le layout normal au lieu du layout iframe) * @test diff --git a/tests/application/modules/opac/controllers/OAIControllerListRecordsTest.php b/tests/application/modules/opac/controllers/OAIControllerListRecordsTest.php index 0e14b68f453262d15231dc766cf2205b7b52ca2d..0f4a68c9f2baeee077cb8ac21e83ff52e23ce22b 100644 --- a/tests/application/modules/opac/controllers/OAIControllerListRecordsTest.php +++ b/tests/application/modules/opac/controllers/OAIControllerListRecordsTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'AbstractControllerTestCase.php'; @@ -102,7 +102,7 @@ class OAIControllerListRecordsInZorkSetTest extends OAIControllerListRecordsInZo protected function _assertHeaderContentAt($header, $content, $position) { - $path = sprintf('//oai:ListRecords/oai:record[%s]/oai:header/oai:%s', + $path = sprintf('//oai:ListRecords/oai:record[%s]/oai:header/oai:%s', $position, $header); $this->_xpath->assertXPathContentContains($this->_response->getBody(), $path, $content); } @@ -116,6 +116,8 @@ class OAIControllerListRecordsInZorkSetWithBadResumptionTokenTest extends OAICon parent::setUp(); $cache = Storm_Test_ObjectWrapper::mock() + ->whenCalled('save') + ->answers(true) ->whenCalled('load') ->answers(false); Storm_Cache::setDefaultZendCache($cache); diff --git a/tests/application/modules/opac/controllers/PanierControllerTest.php b/tests/application/modules/opac/controllers/PanierControllerTest.php index 047c6c517703de9999da9f68eea5e6b69192795a..e48b1467ca0f5c90e57b359773941e9169d7049d 100644 --- a/tests/application/modules/opac/controllers/PanierControllerTest.php +++ b/tests/application/modules/opac/controllers/PanierControllerTest.php @@ -55,7 +55,7 @@ abstract class PanierControllerTestCase extends AbstractControllerTestCase { public function setUp() { parent::setUp(); Class_Users::beVolatile(); - + Class_NoticeDomain::beVolatile(); Class_UserGroup::beVolatile(); Class_Notice::beVolatile(); Class_PanierNotice::beVolatile(); @@ -1216,24 +1216,35 @@ class PanierControllerAjouterNoticeDansBoitePanierTest extends AbstractControlle 'type_module' => 'PANIER', 'preferences' => ['titre' => 'Mon panier']]]]; - $notice = Class_Notice::newInstanceWithId(4, - ['titre_principal' => 'Le Montespan', - 'auteur_principal' => 'Jean Teulテゥ', - 'clef_alpha' => 'MONTESPAN']); + $this->fixture('Class_Notice', + ['id' => 4, + 'titre_principal' => 'Le Montespan', + 'auteur_principal' => 'Jean Teulテゥ', + 'clef_alpha' => 'MONTESPAN']); + } - $notice->save(); - $this->postDispatch('/panier/ajout-ajax/id_notice/4', ['id_panier' => '0']); + /** @test */ + public function contextShouldExpectation() { + $this->fixture('Class_PanierNotice', + ['id' => 1, + 'titre' => 'my cart', + 'user' => Class_Users::getIdentity()]); + $this->postDispatch('/panier/ajout-ajax/id_notice/4/id_panier/1', ['id_notice' => 4, + 'id_panier' => 1]); + $this->assertEquals([Class_Notice::find(4)], Class_PanierNotice::find(1)->getNoticesAsArray()); } /** @test */ public function newPanierShouldNotHaveBeenCreated() { + $this->postDispatch('/panier/ajout-ajax/id_notice/4', ['id_panier' => '0']); $this->assertEmpty(Class_PanierNotice::find(1)); } /** @test */ public function responseShouldRedirectToIndex() { + $this->postDispatch('/panier/ajout-ajax/id_notice/4', ['id_panier' => '0']); $this->assertRedirectTo('/index'); } } @@ -1604,6 +1615,246 @@ class PanierControllerChangePanierAjaxPostRenderPopupTest extends PanierControll +class PanierControllerIndexedByMajTitreTest extends PanierControllerTestCase { + public function setUp() { + parent::setUp(); + $this->postDispatch('/panier/majtitrepanier/id_panier/15', + ['new_libelle' => 'Mes supers romans', + 'domaine_ids' => '97-199'], + true); + } + + + /** @test */ + public function mesSupersRomainsShouldBeIndexedInDomain97() { + $this->assertEquals(Class_Notice::find(4), Class_NoticeDomain::findFirstBy(['domain_id' => 97])->getNotice()); + } + + + /** @test */ + public function mesSupersRomainsShouldBeIndexedInDomain199() { + $this->assertEquals(Class_Notice::find(4), Class_NoticeDomain::findFirstBy(['domain_id' => 199])->getNotice()); + } +} + + + +class PanierControllerIndexedByEditActionTest extends PanierControllerTestCase { + public function setUp() { + parent::setUp(); + $this->postDispatch('/panier/edit/id_panier/15', + ['new_libelle' => 'Mes supers romans', + 'domaine_ids' => '97-199'], + true); + } + + + /** @test */ + public function mesSupersRomainsShouldBeIndexedInDomain97() { + $this->assertEquals(Class_Notice::find(4), Class_NoticeDomain::findFirstBy(['domain_id' => 97, + 'panier_id' => 15])->getNotice()); + } + + + /** @test */ + public function mesSupersRomainsShouldBeIndexedInDomain199() { + $this->assertEquals(Class_Notice::find(4), Class_NoticeDomain::findFirstBy(['domain_id' => 199, + 'panier_id' => 15])->getNotice()); + } + +} + + + +class PanierControllerDesindexedByMajTitreTest extends PanierControllerTestCase { + public function setUp() { + parent::setUp(); + $this->fixture('Class_NoticeDomain', + ['id' => 1, + 'domain_id' => 97, + 'notice_id' => 4, + 'panier_id' => 15]); + + $this->fixture('Class_NoticeDomain', + ['id' => 2, + 'domain_id' => 199, + 'notice_id' => 4, + 'panier_id' => 15]); + + $this->fixture('Class_NoticeDomain', + ['id' => 3, + 'domain_id' => 1789, + 'notice_id' => 4, + 'panier_id' => 15]); + + $this->postDispatch('/panier/majtitrepanier/id_panier/15', + ['new_libelle' => 'Mes supers romans', + 'domaine_ids' => '1789'], + true); + } + + + /** @test */ + public function mesSupersRomainsShouldNotBeIndexedInDomain97() { + $this->assertNull(Class_NoticeDomain::findFirstBy(['domain_id' => 97])); + } + + + /** @test */ + public function mesSupersRomainsShouldNotBeIndexedInDomain199() { + $this->assertNull(Class_NoticeDomain::findFirstBy(['domain_id' => 199])); + } + + + /** @test */ + public function mesSupersRomainsShouldBeIndexedInDomain456() { + $this->assertEquals($this->panier_romans, Class_NoticeDomain::findFirstBy(['domain_id' => 1789])->getPanierNotice()); + } +} + + +abstract class PanierControllerUnindexTestCase extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + Class_Exemplaire::beVolatile(); + Class_PanierNoticeCatalogue::beVolatile(); + + $this->fixture('Class_Catalogue', + ['id' => 1, + 'libelle' => 'my cata']); + + $this->fixture('Class_Notice', + ['id' => 10, + 'titre_principal' => 'Le combat ordinaire', + 'clef_alpha' => 'COMBAT ORDINAIRE']); + + $this->fixture('Class_Notice', + ['id' => 12, + 'titre_principal' => 'Blacksad', + 'clef_alpha' => 'BLACKSAD']); + + $this->fixture('Class_PanierNotice', + ['id' => 2, + 'libelle' => 'Mes BD', + 'date_maj' => '10/02/2011', + 'notices' => 'COMBAT ORDINAIRE;BLACKSAD', + 'user' => Class_Users::getIdentity()]); + + Class_PanierNotice::find(2)->setDomaineIds(1)->save(); + Class_PanierNotice::find(2)->index(); + } +} + + + +class PanierControllerUnindexedBySupprimerNoticePanierTest extends PanierControllerUnindexTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/panier/paniersupprimernotice/id_panier/2/id_notice/10', true); + } + + + /** @test */ + public function cartShouldContainsOneRecord() { + $this->assertCount(1, Class_PanierNotice::find(2)->getNoticesAsArray()); + } + + + /** @test */ + public function domainShouldRemainLinkedToRecord12() { + $this->assertNotNull(Class_NoticeDomain::findFirstBy(['panier_id' => 2, + 'domain_id' => 1, + 'record_alpha_key' => 'BLACKSAD'])); + } + + + /** @test */ + public function record12ShouldHaveFacetH1() { + $this->assertContains('Q1', Class_Notice::find(12)->getFacettes()); + } + + + /** @test */ + public function record10ShouldNotContainsFacetH1() { + $this->assertNotContains('H1', Class_Notice::find(10)->getFacettes()); + } + + + /** @test */ + public function domainShouldNotBeLinkedToRecord10() { + $this->assertNull(Class_NoticeDomain::findFirstBy(['panier_id' => 2, + 'domain_id' => 1, + 'record_alpha_key' => 'COMBAT ORDINAIRE'])); + } +} + + + +class PanierControllerUnindexedByDeleteFullCartTest extends PanierControllerUnindexTestCase { + public function setUp() { + parent::setUp(); + + $this->fixture('Class_Article', + ['id' => 1, + 'titre' => 'Article', + 'contenu' => 'Mon contenu']); + + Class_Article::find(1)->setDomaineIds(1)->save(); + Class_Article::find(1)->index(); + + $panier = Class_PanierNotice::find(2); + $panier->addNotice(Class_Article::find(1)->getNotice())->save(); + $panier->index(); + + $this->dispatch('/panier/supprimerpanier/id_panier/2', true); + } + + + /** @test */ + public function articleShouldStillBeInDomain() { + $this->assertNotNull(Class_NoticeDomain::findFirstBy(['record_alpha_key' => Class_Article::find(1)->getAlphaKey(), + 'domain_id' => 1])); + } + + + /** @test */ + public function articleShouldNotBeInDomainWithCart() { + $this->assertNull(Class_NoticeDomain::findFirstBy(['record_alpha_key' => Class_Article::find(1)->getAlphaKey(), + 'domain_id' => 1, + 'panier_id' => 2])); + } + + + /** @test */ + public function domainShouldNotRemainLinkedToRecord12() { + $this->assertNull(Class_NoticeDomain::findFirstBy(['panier_id' => 2, + 'domain_id' => 1, + 'record_alpha_key' => 'BLACKSAD'])); + } + + + /** @test */ + public function record12ShouldNotHaveFacetH1() { + $this->assertNotContains('H1', Class_Notice::find(12)->getFacettes()); + } + + + /** @test */ + public function record10ShouldNotContainsFacetH1() { + $this->assertNotContains('H1', Class_Notice::find(10)->getFacettes()); + } + + + /** @test */ + public function domainShouldNotBeLinkedToRecord10() { + $this->assertNull(Class_NoticeDomain::findFirstBy(['panier_id' => 2, + 'domain_id' => 1, + 'record_alpha_key' => 'COMBAT ORDINAIRE'])); + } +} + + + class PanierControllerSavePanierTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); @@ -1646,7 +1897,6 @@ class PanierControllerSavePanierTest extends AbstractControllerTestCase { $this->assertEquals(date('Y-m-d'), Class_PanierNotice::find(1)->getDateMaj()); } - /** @test */ public function responseShouldContainsAjaxSucessJson() { $this->assertContains('<div class=\"ajout-result\"><span>La notice Pomme a bien \u00e9t\u00e9 ajout\u00e9e au panier <\/span>\n <a href=\"\/panier\/index\/id_panier\/1#panier_contenu\">Voir le panier<\/a>\n <a href=\"#\" onclick=\"opacDialogClose();return false\">Fermer<\/a>\n<\/div>\n', $this->_response->getBody()); diff --git a/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php b/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php index 8fa76767c0cdca0c829ec2488a7d5e5f4ee881d9..c7083ed5988f2b80cade9221dcebd2230378978f 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php @@ -125,6 +125,18 @@ class RechercheControllerAlbumAudioRecordViewNoticeTest extends RechercheControl } + /** @test */ + public function noticeShouldNotHaveUrlImageSet() { + $this->assertEmpty($this->_notice->getUrlImage()); + } + + + /** @test */ + public function noticeShouldNotHaveUrlVignetteSet() { + $this->assertEmpty($this->_notice->getUrlVignette()); + } + + /** * @disabledtest * en attendant de bien gérer la nouveauté pour les albums bib num (update de notice et non nouvelle création diff --git a/tests/application/modules/opac/controllers/RechercheControllerTest.php b/tests/application/modules/opac/controllers/RechercheControllerTest.php index 9ec24bf52757edbce860835667ebbb7431e2cdf3..65c4b303787a9c71ba33437e2fea54c775c46289 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php @@ -929,7 +929,7 @@ class RechercheControllerSimpleActionWithListeFormatMurTest extends RechercheCon /** @test **/ public function resumeNoticeLinkShouldBeReset() { - $this->assertXPathContentContains('//head/script', "/noticeajax/resumenotice';"); + $this->assertXPathContentContains('//head/script', "/noticeajax/resumenotice';", $this->_response->getBody()); } @@ -2393,6 +2393,7 @@ class RechercheControllerViewnoticeWithBreadcrumbAndIdPanierParamTest extends Re + class RechercheControlleSimpleActionWithEmptyDomainSettingsTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); @@ -2426,14 +2427,14 @@ class RechercheControlleSimpleActionWithEmptyDomainSettingsAndSiteLinkedTest ext 'domaine_ids' => 3, ]); + Class_Exemplaire::beVolatile(); Class_Notice::beVolatile(); Class_NoticeDomain::beVolatile(); Class_Sitotheque::find(1)->index(); - $mock_sql = $this->mock() ->whenCalled('fetchAllByColumn') - ->with("Select id_notice from notices Where notices.clef_alpha in('MONLIEN------10')") + ->with("Select id_notice from notices Where MATCH(facettes) AGAINST('Q3' IN BOOLEAN MODE)") ->answers([1]) ->whenCalled('fetchOne') ->answers(1) @@ -2473,6 +2474,7 @@ class RechercheControlleSimpleActionWithEmptyDomainSettingsAndSiteLinkedTest ext class RechercheControlleSimpleActionWithEmptyDomainSettingsAndArticlesLinkedTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); + Class_Exemplaire::beVolatile(); Class_Notice::beVolatile(); $this->fixture('Class_Catalogue', @@ -2531,3 +2533,5 @@ class RechercheControlleSimpleActionWithEmptyDomainSettingsAndArticlesLinkedTest $this->assertXPathContentContains('//div[@class="resultat_recherche"]//a', 'News of the sprint'); } } + +?> diff --git a/tests/application/modules/telephone/controllers/CasServerControllerTest.php b/tests/application/modules/telephone/controllers/CasServerControllerTest.php index 7e98fe2249a4d067c0d422282afb0f53efc54a5b..745f4700baf2bef1aaea66d9972ab37177046a5f 100644 --- a/tests/application/modules/telephone/controllers/CasServerControllerTest.php +++ b/tests/application/modules/telephone/controllers/CasServerControllerTest.php @@ -24,14 +24,14 @@ require_once 'TelephoneAbstractControllerTestCase.php'; class Telephone_CasServerControllerLoggedTest extends TelephoneAbstractControllerTestCase { public function setUp() { parent::setUp(); + Storm_Cache::beVolatile(); $user = new StdClass(); $user->ID_USER=300; Class_Users::newInstanceWithId(300, ['login' => '87364', 'pseudo' => 'georges']); - Zend_Registry::get('cache')->save('300', - md5(Zend_Session::getId().'300')); - + (new Storm_Cache())->save('300', + md5(Zend_Session::getId().'300')); } /** @test */ diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3c0d2efbce70b23edbe35f5b77b13775ba9123f8..866127bfa7c979d9bf28e436b8aca67c84ec0a93 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ chdir(realpath(dirname(__FILE__)).'/../'); @@ -56,7 +56,7 @@ defineConstant("URL_SHARED_IMG", BASE_URL . "/public/opac/images"); setupOpac(); -Zend_Registry::get('cache')->setOption('caching', true); +(new Storm_Cache())->getCache()->setOption('caching', true); $db_cache = Zend_Cache::factory('Core', 'File', @@ -66,7 +66,6 @@ $db_cache = Zend_Cache::factory('Core', Zend_Db_Table_Abstract::setDefaultMetadataCache($db_cache); - Storm_Cache::setSeed('local'); $cfg = new Zend_Config(Zend_Registry::get('cfg')->toArray(), true); diff --git a/tests/library/Class/ArticleTest.php b/tests/library/Class/ArticleTest.php index 03434ae6d37657c6c8cd31b7ce59cdbcfa7e6954..e292af1f14ca8ac50194417ad985a93cc664197f 100644 --- a/tests/library/Class/ArticleTest.php +++ b/tests/library/Class/ArticleTest.php @@ -1049,6 +1049,7 @@ class EventsByMonthWithArticleNextYearTest extends EventsByMonthWithArticleTestC class ArticleIndexAllTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); + Class_Exemplaire::beVolatile(); Class_Notice::beVolatile(); Class_NoticeDomain::beVolatile(); $this->fixture('Class_Catalogue', @@ -1073,7 +1074,7 @@ class ArticleIndexAllTest extends Storm_Test_ModelTestCase { /** @test */ - public function articleAlphaKeyShouldBeAsExpected() { + public function articleAlphaKeyShouldBeAsMYCMSFIRSTSTEP_8() { $this->assertEquals('MYCMSFIRSTSTEP------8', Class_Article::find(1)->getAlphaKey()); } @@ -1084,6 +1085,12 @@ class ArticleIndexAllTest extends Storm_Test_ModelTestCase { } + /** @test */ + public function recordShouldHaveExpectedFacette() { + $this->assertContains(Class_Catalogue::find(1)->getFacette(), Class_Notice::find(2)->getFacettes()); + } + + /** @test */ public function myDomainShouldHaveANoticeLineked() { $this->assertEquals('My Cms article', Class_NoticeDomain::findFirstBy(['domain_id' => 1])->getNotice()->getTitrePrincipal()); @@ -1095,26 +1102,52 @@ class ArticleIndexAllTest extends Storm_Test_ModelTestCase { class ArticleUnindexTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); + Class_Exemplaire::beVolatile(); Class_Notice::beVolatile(); Class_NoticeDomain::beVolatile(); + $this->fixture('Class_Catalogue', ['id' => 1, 'libelle' => 'My domain']); + $this->fixture('Class_Catalogue', + ['id' => 2, + 'libelle' => 'My domain2']); + $this->fixture('Class_Article', ['id' => 1, 'titre' => 'My Cms First Step', 'contenu' => 'My Cms First Step', 'indexation' => 1, - 'domaine_ids' => 1]); + 'domaine_ids' => '1;2']); + + $this->fixture('Class_Article', + ['id' => 2, + 'titre' => 'My Cms second Step', + 'contenu' => 'My Cms second Step', + 'indexation' => 1, + 'domaine_ids' => '1;2']); Class_Article::find(1)->index(); - Class_Article::find(1)->setDomaineIds('')->save(); + Class_Article::find(2)->index(); + Class_Article::find(1)->setDomaineIds(1)->save(); + Class_Article::find(2)->setDomaineIds('')->save(); } /** @test */ - public function myDomainShouldNotHaveBeenLinkedToNotice() { - $this->assertNull(Class_NoticeDomain::find(1)); + public function secondSteprecordShouldNotHaveNoticeDomain() { + $this->assertNull(Class_NoticeDomain::findFirstBy(['record_alpha_key' => Class_Notice::find(2)->getAlphaKey()])); + } + + + /** @test */ + public function recordShouldHaveBeenUnindexedFromDomain2() { + $this->assertNull(Class_NoticeDomain::findFirstBy(['domain_id' => 2])); + } + + /** @test */ + public function recordShouldNotHaveDomainFacet() { + $this->assertNotContains('H2', Class_Notice::find(1)->getFacettes()); } } \ No newline at end of file diff --git a/tests/library/Class/Indexation/PseudoNoticeTest.php b/tests/library/Class/Indexation/PseudoNoticeTest.php index 675ac88af6d0ceb80f7ace520a71791397b23eba..8f1c5d0059101f975fa93a8a3798c7c470a94ee9 100644 --- a/tests/library/Class/Indexation/PseudoNoticeTest.php +++ b/tests/library/Class/Indexation/PseudoNoticeTest.php @@ -23,6 +23,7 @@ abstract class Class_Indexation_PseudoNoticeTestCase extends Storm_Test_ModelTes public function setUp() { parent::setUp(); Class_Notice::beVolatile(); + Class_Exemplaire::beVolatile(); } } @@ -90,7 +91,7 @@ class Class_Indexation_PseudoNoticeSitothequeFromRawSQLTest extends Class_Indexa 'tags' => 'VOD']); /** as done in Cosmogramme */ - Class_Indexation_PseudoNotice::newWith(Class_Indexation_PseudoNotice::TYPE_SITO, + Class_Indexation_PseudoNotice::newWith(Class_TypeDoc::SITE, ['ID_SITO' => 12, 'TITRE' => 'Thot cursus', 'URL' => 'http://cursus.edu/', @@ -122,7 +123,7 @@ class Class_Indexation_PseudoNoticeSitothequeTest extends Class_Indexation_Pseud 'description' => 'Top notch site', 'tags' => 'VOD']); - Class_Indexation_PseudoNotice::newWith(Class_Indexation_PseudoNotice::TYPE_SITO, + Class_Indexation_PseudoNotice::newWith(Class_TypeDoc::SITE, $this->_sito->toArray() + ['ID_SITO' => $this->_sito->getId()]) ->save(); @@ -144,7 +145,7 @@ class Class_Indexation_PseudoNoticeSitothequeTest extends Class_Indexation_Pseud /** @test */ public function typeShouldBeSite() { - $this->assertEquals(Class_Indexation_PseudoNotice::TYPE_SITO, + $this->assertEquals(Class_TypeDoc::SITE, $this->_notice->getTypeDoc()); } @@ -160,6 +161,7 @@ class Class_Indexation_PseudoNoticeSitothequeTest extends Class_Indexation_Pseud class Class_Indexation_PseudoNoticeArticleTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); + Class_Exemplaire::beVolatile(); $this->fixture('Class_NoticeDomain', ['id' => 189, 'domain_id' => 17, diff --git a/tests/library/Class/MoteurRecherche/MoteurRechercheFacettesTest.php b/tests/library/Class/MoteurRecherche/MoteurRechercheFacettesTest.php index eba7123ca7f76f8d4f4ade43d053bb195cd1a3a4..b0a41ecf88ebe092dd9c97a0aba2a88ecbdbeb4c 100644 --- a/tests/library/Class/MoteurRecherche/MoteurRechercheFacettesTest.php +++ b/tests/library/Class/MoteurRecherche/MoteurRechercheFacettesTest.php @@ -194,7 +194,11 @@ class MoteurRechercheFacettesTest extends Storm_Test_ModelTestCase { public function WithCacheShouldNotExecuteSQL(){ $cache = Storm_Test_ObjectWrapper::mock(); Storm_Cache::setDefaultZendCache($cache); - $cache->whenCalled('load')->answers(serialize($this->facettes)); + $cache + ->whenCalled('save') + ->answers(true) + ->whenCalled('load') + ->answers(serialize($this->facettes)); $this->mock_sql->clearAllRedirections(); $this->assertEquals( $this->facettes, $this->moteur_recherche->getFacettes($this->_requete, diff --git a/tests/library/Class/MoteurRechercheTest.php b/tests/library/Class/MoteurRechercheTest.php index f1600755a4b8ab2218abf8786cc7f31a24853350..f6490b17c25679fe9705f7462f4b21edb32af66c 100644 --- a/tests/library/Class/MoteurRechercheTest.php +++ b/tests/library/Class/MoteurRechercheTest.php @@ -35,8 +35,6 @@ abstract class MoteurRechercheTestCase extends Storm_Test_ModelTestCase { Zend_Registry::set('sql', $this->mock_sql); Class_MoteurRecherche::setTimeSource(new TimeSourceForTest('2012-05-03 09:00:00')); - $this->criteres_recherche= new Class_CriteresRecherche(); - $this->moteur_recherche = new Class_MoteurRecherche(); } @@ -57,8 +55,14 @@ abstract class MoteurRechercheTestCase extends Storm_Test_ModelTestCase { ->setBibs([ Class_Bib::newInstanceWithId(3), Class_Bib::newInstanceWithId(4) ]); - $profil = Class_Profil::getLoader()->newInstanceWithId(26) - ->setTypeDoc('1'); + + $profil = $this->fixture('Class_Profil', + ['id' => 26]) + ->setTypeDoc('1') + ->setSelAnnexe('') + ->setIdSite('') + ->setSelection(''); + $profil->save(); if (isset($params['selection_annexe'])) $profil->setSelAnnexe($params['selection_annexe']); @@ -69,6 +73,8 @@ abstract class MoteurRechercheTestCase extends Storm_Test_ModelTestCase { if (isset($params['selection_sections'])) $profil->setSelSection($params['selection_sections']); + $profil->save(); + Class_Profil::setCurrentProfil($profil); } @@ -214,6 +220,9 @@ class MoteurRechercheAvanceeTest extends MoteurRechercheTestCase { public function lancerRechercheAvanceeShouldBe($params, $req_notices, $req_comptage ,$req_facettes) { $this->mockReqProfilAndZone($req_comptage,$params); + $this->criteres_recherche= new Class_CriteresRecherche(); + $this->moteur_recherche = new Class_MoteurRecherche(); + $this->criteres_recherche->setParams($params); $retour = $this->moteur_recherche->lancerRecherche( $this->criteres_recherche); $this->assertEquals(['nombre' => 10, @@ -303,6 +312,9 @@ class MoteurRechercheSimpleTest extends MoteurRechercheTestCase { */ public function lancerRechercheSimpleShouldBe($params, $nb_mots,$req_comptage ,$req_notices ,$req_facettes) { $this->mockReqProfilAndZone($req_comptage,$params); + $this->criteres_recherche= new Class_CriteresRecherche(); + $this->moteur_recherche = new Class_MoteurRecherche(); + $this->criteres_recherche->setParams($params); $retour = $this->moteur_recherche->lancerRecherche( $this->criteres_recherche); $this->assertEquals(['nombre' => 10, @@ -335,6 +347,9 @@ class MoteurRechercheSerieTest extends MoteurRechercheTestCase { */ public function lancerRechercheSerieShouldBe($params, $req_comptage ,$req_notices ,$req_facettes) { $this->mockReqProfilAndZone($req_comptage,$params); + $this->criteres_recherche= new Class_CriteresRecherche(); + $this->moteur_recherche = new Class_MoteurRecherche(); + $this->criteres_recherche->setParams($params); $retour = $this->moteur_recherche->lancerRecherche($this->criteres_recherche); $this->assertEquals(['nombre' => 10, @@ -447,6 +462,9 @@ class MoteurRechercheRebondTest extends MoteurRechercheTestCase { */ public function lancerRechercheRebondShouldBe($params, $req_comptage ,$req_notices ,$req_facettes) { $this->mockReqProfilAndZone($req_comptage,$params); + $this->criteres_recherche= new Class_CriteresRecherche(); + $this->moteur_recherche = new Class_MoteurRecherche(); + $this->criteres_recherche->setParams($params); $retour = $this->moteur_recherche->lancerRecherche($this->criteres_recherche); $this->assertEquals(['nombre' => 10, @@ -492,6 +510,8 @@ class MoteurRechercheGuideeWithOneSubCategorieTest extends MoteurRechercheTestCa */ public function lancerRechercheGuideeShouldBe($params,$fil_ariane, $req_comptage, $req_liste,$req_facettes,$req_allcodif) { $this->mockReqProfilAndZone($req_comptage,$params); + $this->criteres_recherche= new Class_CriteresRecherche(); + $this->moteur_recherche = new Class_MoteurRecherche(); Class_CodifDewey::newInstanceWithId($params['rubrique'][1], ['libelle' => 'un libelle']); @@ -592,6 +612,8 @@ class MoteurRechercheGuideeWithTwoSubCategorieTest extends MoteurRechercheTestCa ->with($req_allcodif) ->answers([]) ->beStrict(); + $this->criteres_recherche= new Class_CriteresRecherche(); + $this->moteur_recherche = new Class_MoteurRecherche(); $this->criteres_recherche->setParams($params); @@ -708,6 +730,9 @@ class MoteurRechercheCatalogueTest extends MoteurRechercheTestCase { */ public function lancerRechercheCatalogueWithNouveauteShouldBe($params,$req_comptage ,$req_libelle,$req_liste,$req_facettes) { $this->mockReqProfilAndZone($req_comptage,$params); + $this->criteres_recherche= new Class_CriteresRecherche(); + $this->moteur_recherche = new Class_MoteurRecherche(); + $this->mock_sql ->whenCalled('fetchOne') ->with($req_libelle) @@ -750,6 +775,9 @@ class MoteurRecherchePhonetixCollisionTest extends MoteurRechercheTestCase { ->with("Select count(*) from notices Where MATCH(titres, auteurs, editeur, collection, matieres, dewey) AGAINST('+(JEAN JEANS) +(GENET GENETS) +(PARCOUR PARCOURS PARKOUR)' IN BOOLEAN MODE)") ->answers(5000) ->beStrict(); + $this->criteres_recherche= new Class_CriteresRecherche(); + $this->moteur_recherche = new Class_MoteurRecherche(); + $this->criteres_recherche->setParams(['expressionRecherche' => 'jean genet parcours']); $retour = $this->moteur_recherche->lancerRecherche($this->criteres_recherche); } @@ -763,7 +791,7 @@ abstract class MoteurRechercheWithCatalogueTestCase extends Storm_Test_ModelTest public function setUp() { parent::setUp(); - + Class_Exemplaire::beVolatile(); Class_NoticeDomain::beVolatile(); Class_Notice::beVolatile(); @@ -779,7 +807,6 @@ abstract class MoteurRechercheWithCatalogueTestCase extends Storm_Test_ModelTest ]); Class_Sitotheque::find(1)->index(); - } } @@ -796,8 +823,8 @@ class MoteurRechercheWithCatalogueTest extends MoteurRechercheWithCatalogueTestC /** @test */ - public function requestShouldNotContainsProfilSettings() { - $this->assertEquals('Select id_notice from notices Where notices.clef_alpha in(\'MONLIEN------10\')', $this->request['req_liste']); + public function requestShouldContainsProfilSettings() { + $this->assertEquals('Select id_notice from notices Where (MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE)) and MATCH(facettes) AGAINST(\'+(Y2,4,1)\' IN BOOLEAN MODE)', $this->request['req_liste']); } } @@ -816,7 +843,6 @@ class MoteurRechercheWithCatalogueAndParamsTest extends MoteurRechercheWithCatal 'nouveaute' => 1, 'type_doc' => '1;4' ]); - $criteres_recherche = (new Class_CriteresRecherche()) ->setParams(['id_catalogue' => 5, 'aleatoire' => 1, @@ -826,14 +852,13 @@ class MoteurRechercheWithCatalogueAndParamsTest extends MoteurRechercheWithCatal 'selection_annexe' => ' ', 'style_liste' => '']); - $this->request = (new Class_MoteurRecherche())->lancerRecherche($criteres_recherche); } /** @test */ public function requestShouldUseProfilSettings() { - $this->assertEquals('Select id_notice from notices Where ((date_creation >\'2014-12-23\' and MATCH(facettes) AGAINST(\'+P4* +(Y2,4,1) +(T1 T4)\' IN BOOLEAN MODE)) or notices.clef_alpha in(\'MONLIEN------10\')) and MATCH(facettes) AGAINST(\'+P4* +(Y2,4,1)\' IN BOOLEAN MODE)', $this->request['req_liste']); + $this->assertEquals('Select id_notice from notices Where ((date_creation >\'2014-12-23\' and MATCH(facettes) AGAINST(\'+(T1 T4)\' IN BOOLEAN MODE)) or MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE)) and MATCH(facettes) AGAINST(\'+P4* +(Y2,4,1)\' IN BOOLEAN MODE)', $this->request['req_liste']); } } @@ -850,12 +875,48 @@ class MoteurRechercheWithCatalogueAndUrlParamsTest extends MoteurRechercheWithCa 'libelle' => 'Our domain', 'type_doc' => '1;4' ]); - $criteres_recherche = (new Class_CriteresRecherche())->setParams(['id_catalogue' => 5, 'tri' => 'date_creation+desc', - 'facette' =>'T4']); + 'facettes' =>'T1-T10', + 'facette' => 'T5']); + $this->request = (new Class_MoteurRecherche())->lancerRecherche($criteres_recherche); + } + + + /** @test */ + public function requestShouldUseProfilSettings() { + $this->assertEquals('Select id_notice from notices Where ((MATCH(facettes) AGAINST(\'+(T1 T4)\' IN BOOLEAN MODE)) or MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE)) and MATCH(facettes) AGAINST(\'+T1 +T10 +T5\' IN BOOLEAN MODE)', $this->request['req_liste']); + } +} + + + +class MoteurRechercheWithCatalogueWithNoSettingsAndUrlParamsTest extends MoteurRechercheWithCatalogueTestCase { + public function setUp() { + parent::setUp(); + Class_Profil::getCurrentProfil()->setSelAnnexe(''); + Class_MoteurRecherche::setTimeSource(new TimeSourceForTest('2014-12-23 09:00:00')); + + $this->fixture('Class_Catalogue', + ['id' => 5, + 'libelle' => 'Our domain', + 'type_doc' => '' ]); + + $this->fixture('Class_Sitotheque', + ['id' => 1, + 'domaine_ids' => 5, + 'titre' => 'mon lien', + 'url' => 'http://monlien.com' + ]); + + Class_Sitotheque::find(1)->index(); + + $criteres_recherche = + (new Class_CriteresRecherche())->setParams(['id_catalogue' => 5, + 'tri' => 'date_creation+desc', + 'facettes' =>'T4-T8']); $this->request = (new Class_MoteurRecherche())->lancerRecherche($criteres_recherche); } @@ -863,6 +924,6 @@ class MoteurRechercheWithCatalogueAndUrlParamsTest extends MoteurRechercheWithCa /** @test */ public function requestShouldUseProfilSettings() { - $this->assertEquals('Select id_notice from notices Where ((MATCH(facettes) AGAINST(\'+T4 +(T1 T4)\' IN BOOLEAN MODE)) or notices.clef_alpha in(\'MONLIEN------10\')) and MATCH(facettes) AGAINST(\'+T4\' IN BOOLEAN MODE)', $this->request['req_liste']); + $this->assertEquals('Select id_notice from notices Where (MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE)) and MATCH(facettes) AGAINST(\'+T4 +T8\' IN BOOLEAN MODE)', $this->request['req_liste']); } } \ No newline at end of file diff --git a/tests/library/Class/Notice/ClefAlphaTest.php b/tests/library/Class/Notice/ClefAlphaTest.php index 2a310e02ed56cb3c3a5fbf48d31e2bea8edc21a4..91118a5c271f430ac64f846eca7e8b44f7e60d52 100644 --- a/tests/library/Class/Notice/ClefAlphaTest.php +++ b/tests/library/Class/Notice/ClefAlphaTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Notice_ClefAlphaSusAImprevuTest extends Storm_Test_ModelTestCase { @@ -25,7 +25,7 @@ class Notice_ClefAlphaSusAImprevuTest extends Storm_Test_ModelTestCase { $this->_clef = new Class_Notice_ClefAlpha('SUSALIMPREVU--BOUCQF-2-LELOMBARD-2012-1'); - $this->_sus_imprevu = Class_Notice::newInstanceWithId(5, + $this->_sus_imprevu = Class_Notice::newInstanceWithId(5, ['clef_alpha' => 'SUSALIMPREVU--BOUCQF-2-LELOMBARD-2010-1']); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice') @@ -57,17 +57,17 @@ class Notice_ClefAlphaSusAImprevuTest extends Storm_Test_ModelTestCase { /** @test */ public function getUniqueNoticeWithSameTitleTomeTypeDocShouldReturnSusALimprevu() { - $this->assertEquals($this->_sus_imprevu, + $this->assertEquals($this->_sus_imprevu, $this->_clef->getUniqueNoticeWithSameTitleTomeTypeDoc()); } /** @test */ public function withTwoNoticesWithSameTitleShouldReturnOneWithHighestNumberOfMatchingElements() { - $sus_imprevu2 = Class_Notice::newInstanceWithId(5, + $sus_imprevu2 = Class_Notice::newInstanceWithId(5, ['clef_alpha' => 'SUSALIMPREVU--BOUCQF-3-LELOMBARD-2010-1']); - $sus_imprevu3 = Class_Notice::newInstanceWithId(6, + $sus_imprevu3 = Class_Notice::newInstanceWithId(6, ['clef_alpha' => 'SUSALIMPREVU--BOUCQF-3-LELOMBARD-2012-1']); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice') @@ -79,4 +79,70 @@ class Notice_ClefAlphaSusAImprevuTest extends Storm_Test_ModelTestCase { } } -?> \ No newline at end of file + + +class Notice_ClefAlphaOnPseudoNoticeTest extends Storm_Test_ModelTestCase { + public function expectedAlphaKeysForModels() { + return + [ + ['ILNEIGE------8', + + 'Class_Article', + + ['id' => 1, + 'titre' => 'il neige', + 'contenu' => 'c\'est tout blanc'] + ], + + + ['MYSITO------10', + + 'Class_Sitotheque', + + ['id' => 2, + 'url' => 'http://web.afi-sa.net', + 'titre' => 'My sito', + 'description' => 'My sito' + ] + ], + + + ['LEMONDE------9', + + 'Class_Rss', + + ['id' => 4, + 'titre' => 'Le monde', + 'description' => 'A la Une', + 'url' => 'http://rss.lemonde.fr/c/205/f/3050/index.rss'] + ] + ]; + } + + + /** + * @test + * @dataProvider expectedAlphaKeysForModels + */ + public function onModelAlphaKeyShouldBe($alpha_key, $classname, $data) { + $this->assertEquals($alpha_key, (new Class_Notice_ClefAlpha($this->fixture($classname, $data)))->keyString()); + } + + + /** @test */ + public function ironMaidenAlbumAlphaKeyShouldBeIRON_MAIDEN() { + $album = $this->fixture('Class_Album', + ['id' => 4, + 'type_doc_id' => Class_TypeDoc::AUDIO_RECORD, + 'titre' => 'Seventh Son of a Seventh Son', + 'sous_titre' => 'Evil that men do', + 'annee' => '1988' + ]) + ->addAuthor('Iron Maiden') + ->addAuthor('Bruce Dickinson', 'Chanteur') + ->addEditor('EMI'); + + $this->assertEquals('SEVENTHSONOFASEVENTHSON-EVILTHATMENDO-IRONMAIDENBRUCEDICKINSON--EMI-1988-109', + (new Class_Notice_ClefAlpha($album))->keyString()); + } +} diff --git a/tests/library/Class/PanierNoticeTest.php b/tests/library/Class/PanierNoticeTest.php index 63aace92aa9ea839724f0f325a4fc44c27fb31c4..9db9b2eb8e5fd87acde5dae13fecd86365d97bb6 100644 --- a/tests/library/Class/PanierNoticeTest.php +++ b/tests/library/Class/PanierNoticeTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'ModelTestCase.php'; @@ -99,11 +99,11 @@ abstract class PanierNoticeWithThreeNoticesTestCase extends ModelTestCase { 'notices' => ';STARWARS;;INDIANAJONES;SPIDERMAN;INDIANAJONES;TEMPLEPERDU---3--1985-1;ZORK']); - $this->star_wars = $this->fixture('Class_Notice',['id' => 3, + $this->star_wars = $this->fixture('Class_Notice',['id' => 3, 'url_vignette' => 'http://premiere.com/star_wars.png', 'clef_alpha' => 'STARWARS']); - $this->indiana_jones = $this->fixture('Class_Notice',['id' => 5, + $this->indiana_jones = $this->fixture('Class_Notice',['id' => 5, 'url_vignette' => 'NO', 'clef_alpha' => 'INDIANAJONES']); @@ -115,41 +115,67 @@ abstract class PanierNoticeWithThreeNoticesTestCase extends ModelTestCase { } -class PanierNoticeWithThreeNoticesTest extends PanierNoticeWithThreeNoticesTestCase { +class PanierNoticeWithThreeNoticesTest extends ModelTestCase { public function setUp() { parent::setUp(); - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice') - ->whenCalled('findAllBy') - ->with(['clef_alpha' => ['STARWARS', 'INDIANAJONES', 'SPIDERMAN', 'TEMPLEPERDU---3--1985-1', 'ZORK'], - 'order' => 'FIELD(clef_alpha, "STARWARS","INDIANAJONES","SPIDERMAN","TEMPLEPERDU---3--1985-1","ZORK")']) - ->answers([$this->star_wars, $this->indiana_jones, $this->spiderman]) + $this->fixture('Class_Notice', + ['id' => 1, + 'clef_alpha' => 'STARWARS', + 'url_vignette' => 'http://bokeh.fr/img.png']); - ->whenCalled('findAllBy') - ->with(['where' => 'clef_alpha like "ZORK-%"']) - ->answers([]); + $this->fixture('Class_Notice', + ['id' => 2, + 'clef_alpha' => 'INDIANAJONES']); + + $this->fixture('Class_Notice', + ['id' => 3, + 'clef_alpha' => 'SPIDERMAN', + 'url_vignette' => 'http://bokeh.fr/img.png']); + + $this->fixture('Class_Notice', + ['id' => 4, + 'clef_alpha' => 'TEMPLEPERDU', + 'type_doc' => 1]); + + $this->fixture('Class_Notice', + ['id' => 6, + 'clef_alpha' => 'TEMPLEPERDU', + 'type_doc' => 3]); + + $this->fixture('Class_Notice', + ['id' => 5, + 'clef_alpha' => 'ZORK']); + + $this->fixture('Class_PanierNotice', + ['id' => 4, + 'libelle' => 'Fictions', + 'notices' => ';STARWARS;;INDIANAJONES;SPIDERMAN;INDIANAJONES;TEMPLEPERDU---3--1985-1;ZORK-456456']); } - public function testGetAllNotices() { - $notices = $this->fictions->getNoticesAsArray(); - $this->assertEquals(array($this->star_wars, $this->indiana_jones, $this->spiderman), - $notices); + /** @test */ + public function fictionsShouldContainsExpectedRecords() { + $this->assertEquals([Class_Notice::find(3), + Class_Notice::find(2), + Class_Notice::find(1)], + Class_PanierNotice::find(4)->getNoticesAsArray()); } - public function testGetNoticesWithVignettesTrue() { - $notices = $this->fictions->getNoticesOnlyVignettes(true); - $this->assertEquals([$this->star_wars, '2' => $this->spiderman], - $notices); + /** @test */ + public function fictionRecordsWithImgShouldReturnExpectedRecords() { + $this->assertEquals([Class_Notice::find(3), + Class_Notice::find(1)], + Class_PanierNotice::find(4)->getNoticesOnlyVignettes(true)); } - public function testGetNoticesWithVignettesFalse() { - $notices = $this->fictions->getNoticesOnlyVignettes(false); - $this->assertEquals(array($this->star_wars, $this->indiana_jones, $this->spiderman), - $notices); + /** @test */ + public function fictionsRecordsWithoutImgShouldReturnAllRecords() { + $this->assertEquals(Class_PanierNotice::find(4)->getNoticesAsArray(), + Class_PanierNotice::find(4)->getNoticesOnlyVignettes(false)); } @@ -160,69 +186,61 @@ class PanierNoticeWithThreeNoticesTest extends PanierNoticeWithThreeNoticesTestC /** @test */ public function numberOfLostNoticesShouldBeTwo() { - $this->assertEquals(2, $this->fictions->numberOfLostNotices()); + $this->assertEquals(2, Class_PanierNotice::find(4)->numberOfLostNotices()); } /** @test */ public function getLostClesNoticesShouldBeTEMPLEPERDUAndZORK() { - $this->assertEquals(['TEMPLEPERDU---3--1985-1', 'ZORK'], $this->fictions->getLostClesNotices()); + $this->assertEquals(['TEMPLEPERDU---3--1985-1', 'ZORK-456456'], Class_PanierNotice::find(4)->getLostClesNotices()); } /** @test */ - public function afterTryToFindLostClesNoticesShouldUpdateClesNoticeWithTEMPLERETROUVE() { - Class_Notice::getLoader() + public function fixLostClesNoticeShouldUpadteFictionRecordsKeyWithExpectedDatas() { + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice') + ->whenCalled('findAllBy') + ->with(['where' => 'clef_alpha like "ZORK-%"']) + ->answers([Class_Notice::find(5)]) ->whenCalled('findAllBy') ->with(['where' => 'clef_alpha like "TEMPLEPERDU-%"']) - ->answers([Class_Notice::newInstanceWithId(54, ['clef_alpha' => 'TEMPLERETROUVE'])]) - ->beStrict(); - - + ->answers([Class_Notice::find(4)]); + Class_PanierNotice::fixLostClesNoticesForAll(); - Class_PanierNotice::clearCache(); - $this->assertEquals(['STARWARS', 'INDIANAJONES', 'SPIDERMAN', 'TEMPLERETROUVE', 'ZORK'], + $this->assertEquals(['STARWARS', 'INDIANAJONES', 'SPIDERMAN', 'TEMPLEPERDU', 'ZORK'], Class_PanierNotice::find(4)->getClesNotices()); - - return Class_PanierNotice::getLoader(); } /** @test */ public function afterTryToFindLostClesNoticesShouldUpdateClesNoticeWithTEMPLERETROUVEWithDoublons() { - $notices_found = [Class_Notice::newInstanceWithId(54, ['clef_alpha' => 'TEMPLERETROUVE','type_doc' => 1]), - Class_Notice::newInstanceWithId(56, ['clef_alpha' => 'TEMPLERETROUVE','type_doc' => 3])]; - Class_Notice::getLoader() + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice') ->whenCalled('findAllBy') ->with(['where' => 'clef_alpha like "TEMPLEPERDU-%"']) - ->answers($notices_found) + ->answers([Class_Notice::find(6), Class_Notice::find(4)]) ->whenCalled('findAllBy') ->with(['where' => 'clef_alpha like "TEMPLEPERDU-%"', 'tome_alpha' => '3']) - ->answers($notices_found) + ->answers([Class_Notice::find(6), Class_Notice::find(4)]) ->whenCalled('findAllBy') ->with(['where' => 'clef_alpha like "TEMPLEPERDU-%"', 'tome_alpha' => '3', 'type_doc' => '1']) - ->answers([$notices_found[0]]) - ->beStrict(); - - Class_PanierNotice::fixLostClesNoticesForAll(); - $this->assertEquals(['STARWARS', 'INDIANAJONES', 'SPIDERMAN', 'TEMPLERETROUVE', 'ZORK'], - $this->fictions->getClesNotices()); + ->answers([Class_Notice::find(4)]); - return Class_PanierNotice::getLoader(); + Class_PanierNotice::fixLostClesNoticesForAll(); + $this->assertEquals(['STARWARS', 'INDIANAJONES', 'SPIDERMAN', 'TEMPLEPERDU', 'ZORK'], + Class_PanierNotice::find(4)->getClesNotices()); } - } class PanierNoticeAssociatedToCatalogueTest extends Storm_Test_ModelTestCase { - protected + protected $_fictions, $_catalogue_films, $_assoc_fictions_films, @@ -232,7 +250,7 @@ class PanierNoticeAssociatedToCatalogueTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); $this->_old_sql = Zend_Registry::get('sql'); - Zend_Registry::set('sql', + Zend_Registry::set('sql', $this->mock() ->whenCalled('query')->answers(true)); @@ -243,11 +261,13 @@ class PanierNoticeAssociatedToCatalogueTest extends Storm_Test_ModelTestCase { $this->_catalogue_films = $this->fixture('Class_Catalogue', ['id' =>6, 'libelle' => 'Films']); + $this->_fictions->setCatalogues([$this->_catalogue_films])->save(); + $this->_catalogue_cinema->setSousDomaines([$this->_catalogue_films]); $this->_assoc_fictions_films = $this->fixture('Class_PanierNoticeCatalogue', ['id' =>19, 'id_panier' => 4, - 'id_catalogue' => 6]); + 'id_catalogue' => 6]); } @@ -268,8 +288,8 @@ class PanierNoticeAssociatedToCatalogueTest extends Storm_Test_ModelTestCase { $this->assertEquals([$this->_fictions], $this->_catalogue_films->getPanierNotices()); } - - /** @test */ + + /** @test */ public function catalogueCinemaShouldHaveSousDomaineFilms() { $this->assertEquals([$this->_catalogue_films], $this->_catalogue_cinema->getSousDomaines()); } @@ -317,10 +337,15 @@ class NewPanierNoticeForUserTest extends Storm_Test_ModelTestCase { } } -class PanierNoticeWithWrongUserIdTest extends PanierNoticeWithThreeNoticesTestCase { + + +class PanierNoticeWithWrongUserIdTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); + ZendAfi_Auth::setInstance(null); + Class_PanierNoticeCatalogue::beVolatile(); + $this->fixture('Class_Users', ['id'=>78, 'idabon' => 888, 'login' => 'tom', @@ -331,10 +356,15 @@ class PanierNoticeWithWrongUserIdTest extends PanierNoticeWithThreeNoticesTestCa 'login' => 'jerry', 'password' => 'toto']); + $this->fixture('Class_PanierNotice', + ['id' =>4, + 'libelle' => 'Fictions', + 'notices' => ';STARWARS;INDIANAJONES;SPIDERMAN']); + + Class_PanierNotice::find(4)->setIdabon(888) + ->setIdUser(777) + ->save(); - $this->fictions->setIdabon(888) - ->setIdUser(777) - ->save(); $this->fixture('Class_PanierNotice', ['id' => 99, 'id_user' => 78, 'idabon' => 877, @@ -346,17 +376,17 @@ class PanierNoticeWithWrongUserIdTest extends PanierNoticeWithThreeNoticesTestCa 'libelle' => 'Demon']); $voyage=$this->fixture('Class_PanierNotice', ['id' => 28, - 'id_user' => 78, - 'idabon' => 111, - 'libelle' => 'Voyage']); - + 'id_user' => 78, + 'idabon' => 111, + 'libelle' => 'Voyage']); + $voyage->setDateMaj('2013-12-12'); Class_PanierNotice::getLoader()->save($voyage); - Class_PanierNotice::fixLostUserIdForAll(); Class_PanierNotice::clearCache(); } + /** @test */ public function cartFictionsShouldChangeUserIdForIdabon() { $this->assertEquals(78, Class_PanierNotice::find(4)->getIdUser()); @@ -374,16 +404,102 @@ class PanierNoticeWithWrongUserIdTest extends PanierNoticeWithThreeNoticesTestCa $this->assertEquals(666, Class_PanierNotice::find(990)->getIdUser()); } - + /** @test */ public function cartVoyageShouldChangeIdUser() { $this->assertEquals(11, Class_PanierNotice::find(28)->getIdUser()); } + /** @test */ public function dateMajCartVoyageShouldNotChange() { $this->assertEquals('2013-12-12', Class_PanierNotice::find(28)->getDateMaj()); } +} + + +class PanierNoticeIndexAllTest extends ModelTestCase { + public function setUp() { + parent::setUp(); + $this->fixture('Class_Notice', ['id' => 4, + 'titre_principal' => 'Le Montespan', + 'auteur_principal' => 'Jean Teulテδゥ', + 'clef_alpha' => 'MONTESPAN']); + + $this->fixture('Class_Catalogue', + ['id' => 1, + 'id_catalogue' => 1, + 'libelle' => 'art']); + + $this->fixture('Class_Catalogue', + ['id' => 2, + 'id_catalogue' => 2, + 'libelle' => 'musique']); + + $this->fixture('Class_PanierNotice', ['id' => 2, + 'id_panier' => 2, + 'libelle' => 'Mes BD', + 'date_maj' => '10/02/2011', + 'notices' => 'MONTESPAN', + 'user' => Class_Users::getIdentity()]) + ->setCatalogues([Class_Catalogue::find(1), Class_Catalogue::find(2)]); + + $this->fixture('Class_PanierNotice', ['id' => 9, + 'id_panier' => 9, + 'libelle' => 'Orphelin', + 'date_maj' => '25/05/2010', + 'notices' => 'MONTESPAN', + 'user' => Class_Users::getIdentity()]) + ->setCatalogues([Class_Catalogue::find(1)]); + + $this->fixture('Class_PanierNotice', ['id' => 15, + 'id_panier' => 15, + 'libelle' => 'Mes Romans', + 'date_maj' => '25/05/2010', + 'notices' => 'MONTESPAN', + 'user' => Class_Users::getIdentity()]); + + $this->fixture('Class_PanierNoticeCatalogue', + ['id' => 1, + 'id_panier' => 2, + 'id_catalogue' => 1]); + + $this->fixture('Class_PanierNoticeCatalogue', + ['id' => 2, + 'id_panier' => 2, + 'id_catalogue' => 2]); + + $this->fixture('Class_PanierNoticeCatalogue', + ['id' => 3, + 'id_panier' => 9, + 'id_catalogue' => 1]); + + $this->fixture('Class_NoticeDomain', + ['id' => 1, + 'domain_id' => 1, + 'record_alpha_key' => 'MONTESPAN', + 'panier_id' => 15]); + + Class_PanierNotice::indexAll(); + Class_PanierNotice::find(2)->setCatalogues([Class_Catalogue::find(1)])->save(); + } + + + /** @test */ + public function facetOfRecordMontespanShouldContainsFacetQ1() { + $this->assertContains('Q1', Class_Notice::findFirstBy(['clef_alpha' => 'MONTESPAN'])->getFacettes()); + } + + + /** @test */ + public function allCartsShouldBeIndexed() { + $this->assertCount(2, Class_NoticeDomain::findAll()); + } + + + /** @test */ + public function recordMonstespanShouldNotHaveFacetQ2() { + $this->assertNotContains('Q2', Class_Notice::findFirstBy(['clef_alpha' => 'MONTESPAN'])->getFacettes()); + } } -?> \ No newline at end of file diff --git a/tests/library/Class/SitothequeTest.php b/tests/library/Class/SitothequeTest.php index ec2d9d91b8ff1bb1574262503a0e645f0409ba69..b813c58152d76845c42288eade1578bc132a8713 100644 --- a/tests/library/Class/SitothequeTest.php +++ b/tests/library/Class/SitothequeTest.php @@ -45,6 +45,7 @@ class SitothequeIndexAllTest extends Storm_Test_ModelTestCase { parent::setUp(); Class_Notice::beVolatile(); Class_NoticeDomain::beVolatile(); + Class_Exemplaire::beVolatile(); $this->fixture('Class_Catalogue', ['id' => 1, 'libelle' => 'My domain']); @@ -69,7 +70,6 @@ class SitothequeIndexAllTest extends Storm_Test_ModelTestCase { 'description' => 'My sito2', 'domaine_ids' => '1']); - Class_Sitotheque::indexAll(); Class_Sitotheque::find(3)->setDomaineIds('1')->save(); } @@ -86,14 +86,16 @@ class SitothequeIndexAllTest extends Storm_Test_ModelTestCase { $this->assertCount(3, Class_Notice::findAll()); } - /** @test */ + + /** @test */ public function domainShouldHaveMySitoRecord() { $this->assertEquals('My sito', Class_NoticeDomain::findFirstBy(['domain_id' => 1])->getNotice()->getTitrePrincipal()); } + /** @test */ public function domainShouldHaveMySito2Record() { - $this->assertEquals('My sito2', Class_NoticeDomain::find(2)->getNotice()->getTitrePrincipal()); + $this->assertNotNull(Class_NoticeDomain::findFirstBy(['record_alpha_key' => 'MYSITO2------10'])); } } @@ -101,25 +103,31 @@ class SitothequeIndexAllTest extends Storm_Test_ModelTestCase { class SitothequeUnindexTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); + Class_Exemplaire::beVolatile(); Class_Notice::beVolatile(); Class_NoticeDomain::beVolatile(); $this->fixture('Class_Catalogue', ['id' => 1, 'libelle' => 'My domain']); + $this->fixture('Class_Catalogue', + ['id' => 2, + 'libelle' => 'My domain news']); + + $this->fixture('Class_Sitotheque', ['id' => 1, 'url' => 'http://web.afi-sa.net', 'titre' => 'My website', 'description' => 'My Cms First Step', - 'domaine_ids' => '1']); + 'domaine_ids' => '1;2']); Class_Sitotheque::find(1)->index(); - Class_Sitotheque::find(1)->setDomaineIds('')->save(); + Class_Sitotheque::find(1)->setDomaineIds('1')->save(); } /** @test */ - public function myDomainShouldNotHaveBeenLinkedToNotice() { - $this->assertNull(Class_NoticeDomain::find(1)); + public function sitoRecordShouldNotBeLinkedToMyDomainNews() { + $this->assertNull(Class_NoticeDomain::findFirstBy(['domain_id' => 2])); } } \ No newline at end of file diff --git a/tests/library/Class/SuggestionAchatTest.php b/tests/library/Class/SuggestionAchatTest.php index 59c19ca4b4d0477af75c0c59ac805cb6f87e637a..07cb64b3fe436b61ada8183c7f4b52c2163718ca 100644 --- a/tests/library/Class/SuggestionAchatTest.php +++ b/tests/library/Class/SuggestionAchatTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -43,7 +43,7 @@ abstract class SuggestionAchatTestCase extends Storm_Test_ModelTestCase { 'annexes' => '4;8', 'sections' => '9;10']); - $type_doc=$this->fixture('Class_TypeDoc', ['id'=>Class_TypeDoc::LIVRE, + $type_doc=$this->fixture('Class_TypeDoc', ['id'=>Class_TypeDoc::LIVRE, 'codif_type_doc' => $codif_type_doc, 'label'=> 'Livres Numériques']); @@ -71,21 +71,20 @@ class SuggestionAchatMailTest extends SuggestionAchatTestCase { public function setUp() { parent::setUp(); - $this->_suggestion->sendMail('noreply@astromelun.fr'); $this->_sent_mail = $this->_mock_transport->sent_mail; } protected function assertBodyContains($text) { - $this->assertContains($text, + $this->assertContains($text, quoted_printable_decode($this->_sent_mail->getBodyText()->getContent())); } /** @test */ public function mailSubjectShouldBeSuggestionAchatHarryPotter() { - $this->assertEquals('Suggestion d\'achat: Harry emPotté', + $this->assertEquals('Suggestion d\'achat: Harry emPotté', quoted_printable_decode($this->_sent_mail->getSubject())); } @@ -174,7 +173,7 @@ class SuggestionAchatMailErrorsTest extends SuggestionAchatTestCase { public function withoutMailSiteShouldSendMailOnlyToUser() { Class_Profil::getCurrentProfil()->setMailSuggestionAchat(''); $this->_suggestion->sendMail('noreply@astromelun.fr'); - $this->assertEquals(['sbelle@gmail.com'], + $this->assertEquals(['sbelle@gmail.com'], $this->_mock_transport->sent_mail->getRecipients()); } @@ -183,7 +182,7 @@ class SuggestionAchatMailErrorsTest extends SuggestionAchatTestCase { public function withoutMailUserShouldSendMailOnlyToMailProfil() { $this->_suggestion->getUser()->setMail(''); $this->_suggestion->sendMail('noreply@astromelun.fr'); - $this->assertEquals(['laurent@afi-sa.fr', 'patrick@afi-sa.fr', 'estelle@afi-sa.fr'], + $this->assertEquals(['laurent@afi-sa.fr', 'patrick@afi-sa.fr', 'estelle@afi-sa.fr'], $this->_mock_transport->sent_mail->getRecipients()); } } diff --git a/tests/library/Class/Systeme/ModulesMenu/NumilogTest.php b/tests/library/Class/Systeme/ModulesMenu/NumilogTest.php index 4d10c49a7ce708f2ee8a8c0209663cc6c2f1d10b..c9d408c86a8afc128a0a67bbb3ed217571ad8a19 100644 --- a/tests/library/Class/Systeme/ModulesMenu/NumilogTest.php +++ b/tests/library/Class/Systeme/ModulesMenu/NumilogTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -33,7 +33,7 @@ class Class_Systeme_ModulesMenu_NumilogTest extends Storm_Test_ModelTestCase { 'date_debut' => '1999-02-10', 'date_fin' => '2025-09-12', 'user_groups' => [$this->fixture('Class_UserGroup', [ - 'id' => 20, + 'id' => 20, 'libelle' => 'Numilog' ])->addRight(Class_UserGroup::RIGHT_ACCES_NUMILOG)] ])->beAbonneSIGB(); @@ -53,4 +53,3 @@ class Class_Systeme_ModulesMenu_NumilogTest extends Storm_Test_ModelTestCase { $this->assertContains('numilog', $this->menu->getDynamiqueUrl()); } } -?> \ No newline at end of file diff --git a/tests/library/Class/WebService/CyberlibrisTest.php b/tests/library/Class/WebService/CyberlibrisTest.php index e96f935614b279240edfcb155d9733cbddb4a0bc..7bcd79c6188df9d0c91bccc77e6e52e5280c731d 100644 --- a/tests/library/Class/WebService/CyberlibrisTest.php +++ b/tests/library/Class/WebService/CyberlibrisTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -24,8 +24,9 @@ class CyberlibrisHarvestSaveTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); - Class_AdminVar::newInstanceWithId('CYBERLIBRIS_URL', ['valeur' => 'http://oai-bibliovox.cyberlibris.fr/oai.aspx']); - + Class_AdminVar::newInstanceWithId('CYBERLIBRIS_URL', ['valeur' => 'http://oai-bibliovox.cyberlibris.fr/oai.aspx']); + Class_Notice::beVolatile(); + Class_Exemplaire::beVolatile(); Class_Album::beVolatile(); $catalogue_xml = file_get_contents(realpath(dirname(__FILE__)). '/../../../fixtures/cyberlibris_oai.xml'); diff --git a/tests/library/ZendAfi/AuthTest.php b/tests/library/ZendAfi/AuthTest.php index d7611236cd1ad6758fe4b5cf52f7460e7bc0b53b..89c44b9cfb306e7eccf4be74ac3d2aedd94c0d8c 100644 --- a/tests/library/ZendAfi/AuthTest.php +++ b/tests/library/ZendAfi/AuthTest.php @@ -16,22 +16,21 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class AuthSessionNamespaceTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setup(); - $this->old_cache=Zend_Registry::get('cache'); $this->cache_mock=Storm_Test_ObjectWrapper::mock(); $this->cache_mock->whenCalled('save') ->answers(true) ->whenCalled('remove') ->answers(true); - - - Zend_Registry::set('cache',$this->cache_mock); + + + Storm_Cache::setDefaultZendCache($this->cache_mock); $this->fixture('Class_Users', ['id' => 25, 'login' => 'gigi', @@ -41,12 +40,13 @@ class AuthSessionNamespaceTest extends Storm_Test_ModelTestCase { $this->islogged=$this->zendAuth->authenticateLoginPassword('gigi', 'amoroso', [new Mock_ZendAfi_Auth_MD5_BASE64_Adapter()]); - + } public function tearDown() { - Zend_Registry::set('cache',$this->old_cache); + Storm_Cache::setDefaultZendCache(null); + parent::tearDown(); } @@ -58,8 +58,8 @@ class AuthSessionNamespaceTest extends Storm_Test_ModelTestCase { } - /** - * @test + /** + * @test */ public function validAuthenticationInMd5ShouldRedirect() { $this->assertTrue($this->islogged); @@ -68,7 +68,7 @@ class AuthSessionNamespaceTest extends Storm_Test_ModelTestCase { /** @test */ public function validAuthenticationUserIdShouldBeStoredInCache() { - $this->assertEquals(25, $this->cache_mock->getFirstAttributeForLastCallOn('save')); + $this->assertEquals(25, unserialize($this->cache_mock->getFirstAttributeForLastCallOn('save'))); } @@ -98,7 +98,7 @@ class Mock_ZendAfi_Auth_MD5_BASE64_Adapter implements Zend_Auth_Adapter_Interfa } - + public function authenticate() { if ($this->_credential == 'KxhJ6qNkU3d4A8U5rqJvCw') return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $this->getResultObject()); @@ -106,7 +106,7 @@ class Mock_ZendAfi_Auth_MD5_BASE64_Adapter implements Zend_Auth_Adapter_Interfa return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identity); } - + public function getResultObject() { $object = new StdClass; @@ -115,5 +115,5 @@ class Mock_ZendAfi_Auth_MD5_BASE64_Adapter implements Zend_Auth_Adapter_Interfa return $object; } } - + ?> \ No newline at end of file diff --git a/tests/library/ZendAfi/View/Helper/Accueil/CacheTest.php b/tests/library/ZendAfi/View/Helper/Accueil/CacheTest.php index 10b0e75ea76b9c2467f6282eea55d1dfdba3f455..f9fba49b7af1bd2459ff11fa7580a62e1b502723 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/CacheTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/CacheTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'library/ZendAfi/View/Helper/ViewHelperTestCase.php'; @@ -26,18 +26,17 @@ 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', - 'titre' => 'Critiques', - 'rss_avis' => false, - 'display_order' => 'Random', - 'only_img' => true)); + Storm_Cache::beVolatile(); - $this->avis_loader = $this->getMock('MockLoader', array('getAvisFromPreferences')); + $params = ['type_module' => 'CRITIQUES', + 'division' => 2, + 'preferences' => ['boite' => 'boite_vide', + 'titre' => 'Critiques', + 'rss_avis' => false, + 'display_order' => 'Random', + 'only_img' => true]]; + + $this->avis_loader = $this->getMock('MockLoader', ['getAvisFromPreferences']); Storm_Model_Abstract::setLoaderFor('Class_AvisNotice', $this->avis_loader); $this->critiques_helper = new ZendAfi_View_Helper_Accueil_Critiques(2, $params); diff --git a/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php b/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php index dd4fe666e3522f0bd631e5b85524b8bc9f090128..a1c8269e52c6d85ac2e606535bc007a1b3afe946 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php @@ -599,6 +599,7 @@ class ZendAfi_View_Helper_Accueil_KiosqueWithLinkedRecordsInDomainSetTest extend public function setUp() { parent::setUp(); + Class_Exemplaire::beVolatile(); Class_NoticeDomain::beVolatile(); $this->fixture('Class_Sitotheque', @@ -617,6 +618,6 @@ class ZendAfi_View_Helper_Accueil_KiosqueWithLinkedRecordsInDomainSetTest extend /** @test */ public function requestShouldBeAsExpected() { - $this->assertEquals('select id_notice from notices Where notices.clef_alpha in(\'MONLIEN------10\') order by date_creation DESC LIMIT 0,50', $this->_request['req_liste']); + $this->assertEquals('select id_notice from notices Where MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE) order by date_creation DESC LIMIT 0,50', $this->_request['req_liste']); } } diff --git a/tests/library/ZendAfi/View/Helper/Notice/UnimarcTest.php b/tests/library/ZendAfi/View/Helper/Notice/UnimarcTest.php new file mode 100644 index 0000000000000000000000000000000000000000..9563d47649c1507938af3461d753ac099bbd6bd4 --- /dev/null +++ b/tests/library/ZendAfi/View/Helper/Notice/UnimarcTest.php @@ -0,0 +1,54 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + + class ZendAfi_View_Helper_Notice_UnimarcTest extends ViewHelperTestCase { + public function setUp() { + parent::setUp(); + $this->_helper = new ZendAfi_View_Helper_Notice_Unimarc(); + $this->_helper->setView(new ZendAfi_Controller_Action_Helper_View()); + $this->_html = $this->_helper->notice_Unimarc($this->fixture('Class_Notice', + ['id' => 1, + 'titre' => 'Pomme et Ananas', + 'clef_alpha' => 'POMMEETANANAS', + 'facettes' => 'A1 Q9', + 'date_maj' => '01/01/2015', + 'unimarc' => ''])); + } + + + /** @test */ + public function alphaKeyShouldBePresent() { + $this->assertContains('Clé alpha: POMMEETANANAS', $this->_html); + } + + + /** @test */ + public function dateMajShouldBePresent() { + $this->assertContains('Mis à jour le: 01/01/2015', $this->_html); + } + + + /** @test */ + public function facetsShouldBePresent() { + $this->assertContains('Facettes: A1 Q9', $this->_html); + } + } diff --git a/tests/library/ZendAfi/View/Helper/ViewHelperTestCase.php b/tests/library/ZendAfi/View/Helper/ViewHelperTestCase.php index 2872f6def543b969beb472242f1e5424dbf9c37f..a78ce5bbc606fd8db0e38d954ea71d97a3bb1b0d 100644 --- a/tests/library/ZendAfi/View/Helper/ViewHelperTestCase.php +++ b/tests/library/ZendAfi/View/Helper/ViewHelperTestCase.php @@ -129,7 +129,7 @@ abstract class ViewHelperTestCase extends PHPUnit_Framework_TestCase { protected function tearDown() { Storm_Model_Abstract::unsetLoaders(); - Zend_Registry::get('cache')->clean(); + (new Storm_Cache)->clean(); $this->logout(); }