diff --git a/application/modules/admin/controllers/ModoController.php b/application/modules/admin/controllers/ModoController.php index a553de9ff0e5e637fce202d500decb3c8588c25a..e8b3c634584cf935b0df1b209f15d777bfa2d4bc 100644 --- a/application/modules/admin/controllers/ModoController.php +++ b/application/modules/admin/controllers/ModoController.php @@ -27,16 +27,63 @@ class Admin_ModoController extends ZendAfi_Controller_Action { public function avisnoticeAction() { + $this->subviewForStatus(0); + $this->_forward('index'); + } + + + public function invisibleavisnoticeAction() { + if (!$review_id=$this->_request->getParam('id',0)) + $this->_forward('index'); + $review=Class_AvisNotice::find($review_id); + $review->setFlags(Class_AvisNotice::ARCHIVED_FLAG)->save(); + + $this->_forward('index'); + } + - $all_avis = Class_AvisNotice::getLoader()->findAllBy(['statut' => 0,'limit'=>100]); - $all_avis = Class_AvisNotice::sortByDateAvisDesc($all_avis); + public function visibleavisnoticeAction() { + if (!$review_id=$this->_request->getParam('id',0)) + $this->_forward('index'); + $review=Class_AvisNotice::find($review_id); + $review->setFlags(Class_AvisNotice::NO_FLAG)->save(); - $avis_bib = Class_AvisNotice::filterByBibliothecaire($all_avis); - $avis_abo = Class_AvisNotice::filterByAbonne($all_avis); + $this->_forward('index'); + } + + protected function subviewForStatus($status) { + + $page = $this->_getParam('page',1); + $nb_bib=Class_AvisNotice::countBiblioReviews($status); + $nb_abo=Class_AvisNotice::countAboReviews($status); + $display_per_page=$page*10; + $avis_bib = Class_AvisNotice::findBiblioReviews($status, + [($nb_bib<=$display_per_page)? 1: $page,10]); + + $avis_abo = Class_AvisNotice::findAboReviews($status, + [($nb_abo<=$display_per_page)? 1 : $page,10]); + $nb_orphans=Class_AvisNotice::countOrphanReviews($status); + $nb_archived=Class_AvisNotice::countArchivedReviews($status); + $orphans = Class_AvisNotice::findOrphanReviews($status,[($nb_orphans<=$display_per_page)? 1: $page,10]); + $archived = Class_AvisNotice::findArchivedReviews($status,[($nb_archived<=$display_per_page)? 1: $page,10]); $this->view->subview = $this->view->partial('modo/avisnotice.phtml', ['list_avis_bibliothecaires' => $avis_bib, - 'list_avis_utilisateurs' => $avis_abo]); + 'list_avis_utilisateurs' => $avis_abo, + 'list_orphan_reviews' => $orphans, + 'list_archived_reviews' => $archived, + 'display_all' => $status, + 'nb_bib' => $nb_bib, + 'nb_abo' => $nb_abo, + 'nb_orphans' => $nb_orphans, + 'nb_archived' => $nb_archived, + 'page' => $page +]); + +} + public function allreviewsAction() { + + $this->subviewForStatus(1); $this->_forward('index'); } diff --git a/application/modules/admin/views/scripts/modo/_avis_partial.phtml b/application/modules/admin/views/scripts/modo/_avis_partial.phtml index 5c62ec2e78c9c948d5b15f2dd01bbfb9548ed157..d62871b971ccfd30203be4720ce61bb401a814fb 100644 --- a/application/modules/admin/views/scripts/modo/_avis_partial.phtml +++ b/application/modules/admin/views/scripts/modo/_avis_partial.phtml @@ -1,4 +1,9 @@ <div class="<?php echo $this->item_class ?>"> + <?php + $actions = ['validate', 'edit', 'del']; + if ($this->avis->getFlags()>=0) + $actions[] = ($this->avis->getFlags()==0) ? 'invisible' :'visible'; + $this->getHelper('avis')->setActions($actions); ?> <?php echo $this->avis($this->avis) ?> <div class='clear'></div> -</div> \ No newline at end of file +</div> diff --git a/application/modules/admin/views/scripts/modo/avisnotice.phtml b/application/modules/admin/views/scripts/modo/avisnotice.phtml index c0cd162c77e71ce0bb572cc29da49069b4b29a1b..31e27bb605d21c2f368cc9e019569db2063bc650 100644 --- a/application/modules/admin/views/scripts/modo/avisnotice.phtml +++ b/application/modules/admin/views/scripts/modo/avisnotice.phtml @@ -1,24 +1,34 @@ -<?php +<?php -echo '<h1>'.$this->traduire('Modération des avis sur les notices').'</h1>'; +if ($this->display_all) { + echo '<h1>'.$this->traduire('Tous les avis de notices modérés').'</h1>'; + echo $this->tagAnchor(['action' => 'avisnotice'],"Afficher les avis non modérés"); +} +if (!$this->display_all) { + echo '<h1>'.$this->traduire('Modération des avis sur les notices').'</h1>'; + echo $this->tagAnchor(['action' => 'allreviews'],"Afficher tous les avis modérés"); +} echo '<div id="avis-notice-liste" >'; -echo $this->avisBloc('Bibliothécaires', $this->list_avis_bibliothecaires); +echo $this->avisBloc('Avis de bibliothécaires ('.$this->nb_bib.')', $this->list_avis_bibliothecaires,$this->page,$this->nb_bib); -echo $this->avisBloc('Abonnés', $this->list_avis_utilisateurs); -echo '</div>'; +echo $this->avisBloc('Avis d\'abonnés ('. $this->nb_abo.')', $this->list_avis_utilisateurs,$this->page,$this->nb_abo); + +echo $this->avisBloc('Avis orphelins ('.$this->nb_orphans.')', $this->list_orphan_reviews,$this->page,$this->nb_orphans); +echo $this->avisBloc('Avis archivés ('.$this->nb_archived.')', $this->list_archived_reviews,$this->page,$this->nb_archived); +echo '</div>'; -?> +?> <script type='text/javascript'> $(document).ready(function() { $('.critique a:not(.actions a)').attr('target', '_blank'); - $('#avis-notice-liste').accordion({heightStyle:'content',disabled:true, icons:null}); - $('#avis-notice-liste .ui-accordion-content').show(); + $('#avis-notice-liste').accordion({heightStyle:'content',collapsible:true,disabled:false}); +// $('#avis-notice-liste .ui-accordion-content').show(); }); </script> diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 246ca25151f71f042bf38d0492a0446e2a0e3803..9ec3ebb5d239bad69673ceb97f704b86ce769ef3 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -145,6 +145,7 @@ class AbonneController extends ZendAfi_Controller_Action { ->setAvis($this->_request->getParam('avisTexte')) ->setNote($this->_request->getParam('avisNote')) ->setUser($this->_user) + ->setIdNotice($id_notice) ->setClefOeuvre($notice->getClefOeuvre()) ->setStatut(0); diff --git a/application/modules/opac/controllers/BlogController.php b/application/modules/opac/controllers/BlogController.php index f54b71d4b7d75b836bf653f6ae4d8dc1c6deec7d..70b7d0a358d16a4e1a54afff318ffb9477bf580c 100644 --- a/application/modules/opac/controllers/BlogController.php +++ b/application/modules/opac/controllers/BlogController.php @@ -80,6 +80,7 @@ class BlogController extends ZendAfi_Controller_Action { public function lastcritiqueAction() { $nb_avis = (int)$this->_getParam('nb', 20); $liste_avis = Class_AvisNotice::findAllBy(['order' => 'date_avis desc', + 'flags' => Class_AvisNotice::NO_FLAG, 'limit' => $nb_avis]); $this->view->nb_aff = $nb_avis; diff --git a/application/modules/opac/controllers/RssController.php b/application/modules/opac/controllers/RssController.php index 8efa311b86388edd2beb5c780cc7446680ccd99a..3ddbb1cd58be55ca156961e3452385b796ff4328 100644 --- a/application/modules/opac/controllers/RssController.php +++ b/application/modules/opac/controllers/RssController.php @@ -301,10 +301,11 @@ class RssController extends Zend_Controller_Action $avis_helper = $this->view->getHelper('Avis'); - $items = array(); + $items = []; foreach($user_avis as $avis) { $desc = $avis_helper->avis($avis, 0, $vignette_link_to_avis = true); - + if ($desc=='') + continue; $items [] = ['titre' => $avis->getEntete(), 'lien' => $this->view->absoluteUrl([ 'controller' => 'blog', diff --git a/cosmogramme/php/_init.php b/cosmogramme/php/_init.php index 15b3b4cec766c63d85b246f18663819722df8f37..fd12ea4641593a002fdb218c22c0c1e3dca605b0 100644 --- a/cosmogramme/php/_init.php +++ b/cosmogramme/php/_init.php @@ -1,7 +1,7 @@ <?php error_reporting(E_ERROR | E_PARSE); -define("PATCH_LEVEL","263"); +define("PATCH_LEVEL","265"); define("APPLI","cosmogramme"); define("COSMOPATH", "/var/www/html/vhosts/opac2/www/htdocs"); diff --git a/cosmogramme/php/integre_traite_main.php b/cosmogramme/php/integre_traite_main.php index cf167dda41804d10ca4e4dbc446df3a8ceaf3932..8afab8dcd0aff5fa3b4283310fb77e77a656e8a6 100644 --- a/cosmogramme/php/integre_traite_main.php +++ b/cosmogramme/php/integre_traite_main.php @@ -496,7 +496,19 @@ if (!$mode_cron and $chrono->tempsPasse() > 5) sauveContexte(); startIntegrationPhase('ItemFacets'); -$phase = 8; +$phase = 7.5; + +// ---------------------------------------------------------------- +// Reattach Reviews +// ---------------------------------------------------------------- + +if ($phase == 7.5) { + startIntegrationPhase('Reviews'); + $phase = 8; +} + + + // ---------------------------------------------------------------- // Integration des abonnés diff --git a/cosmogramme/sql/patch/patch_264.php b/cosmogramme/sql/patch/patch_264.php new file mode 100644 index 0000000000000000000000000000000000000000..73c2cc32a6add91c7cd6b3bb8decb2a04db05339 --- /dev/null +++ b/cosmogramme/sql/patch/patch_264.php @@ -0,0 +1,11 @@ +<?php +$adapter = Zend_Db_Table::getDefaultAdapter(); + +try { + $adapter->query('select flags from notices_avis limit 1'); +} catch (Exception $e) { + $adapter->query('ALTER TABLE notices_avis ADD COLUMN flags tinyint default 0'); + $adapter->query('ALTER TABLE notices_avis ADD INDEX (flags)'); +} + +?> \ No newline at end of file diff --git a/cosmogramme/sql/patch/patch_265.php b/cosmogramme/sql/patch/patch_265.php new file mode 100644 index 0000000000000000000000000000000000000000..8491258ebb0991426e0d90576317b381fd9fddad --- /dev/null +++ b/cosmogramme/sql/patch/patch_265.php @@ -0,0 +1,11 @@ +<?php +$adapter = Zend_Db_Table::getDefaultAdapter(); + +try { + $adapter->query('select flags from cms_avis limit 1'); +} catch (Exception $e) { + $adapter->query('ALTER TABLE cms_avis ADD COLUMN flags tinyint default 0'); + $adapter->query('ALTER TABLE cms_avis ADD INDEX (flags)'); +} + +?> \ No newline at end of file diff --git a/library/Class/Avis.php b/library/Class/Avis.php index 98b3157976343aad6a86c6f034e17849cdb05bac..7ada26071f2525136baffdeabfdac098968d719b 100644 --- a/library/Class/Avis.php +++ b/library/Class/Avis.php @@ -37,11 +37,10 @@ class Class_Avis extends Storm_Model_Abstract { protected $_default_attribute_values = ['entete' => '', 'avis' => '', + 'flags' => 0, 'note' => 0 ]; - - /** Ecrire 1 avis (update si existe déjà ) */ public static function ecrireCmsAvis($id_user, $role_level, $id_news, $note, $entete, $content) { $modo_avis_abo = getVar('MODO_AVIS'); // 0 apres / 1 avant de publier sur le site @@ -120,6 +119,10 @@ class Class_Avis extends Storm_Model_Abstract { $rank->save(); } + + public function getFlags() { + return -1; + } } ?> \ No newline at end of file diff --git a/library/Class/AvisNotice.php b/library/Class/AvisNotice.php index c4a97f61d2ed9b981d61abe856b36eb1eae89aa6..37744676f12d5c81018b247217e7291df682f784 100644 --- a/library/Class/AvisNotice.php +++ b/library/Class/AvisNotice.php @@ -42,6 +42,76 @@ class AvisNoticeLoader extends Storm_Model_Loader { return $this; } + public function findOrphanReviews($status, $limitPage=null) { + $req = ['flags' => Class_AvisNotice::ORPHAN_FLAG, + 'order' => 'date_avis desc', + 'statut' => $status]; + if ($limitPage) + $req['limitPage'] = $limitPage; + return Class_AvisNotice::findAllBy($req); + } + + public function findBiblioReviews($status, $limitPage=null) { + $req = ['flags' => Class_AvisNotice::NO_FLAG, + 'abon_ou_bib' => Trait_Avis::$AVIS_BIBLIO, + 'order' => 'date_avis desc', + 'statut' => $status]; + if ($limitPage) + $req['limitPage'] = $limitPage; + return Class_AvisNotice::findAllBy($req); + } + + public function countBiblioReviews($status) { + $req = ['flags' => Class_AvisNotice::NO_FLAG, + 'abon_ou_bib' => Trait_Avis::$AVIS_BIBLIO, + 'statut' => $status]; + return Class_AvisNotice::countBy($req); + } + + public function countAboReviews($status) { + $req = ['flags' => Class_AvisNotice::NO_FLAG, + 'abon_ou_bib' => Trait_Avis::$AVIS_ABONNE, + 'statut' => $status]; + return Class_AvisNotice::countBy($req); + } + + + public function findAboReviews($status, $limitPage=null) { + $req = ['flags' => Class_AvisNotice::NO_FLAG, + 'abon_ou_bib' => Trait_Avis::$AVIS_ABONNE, + 'order' => 'date_avis desc', + 'statut' => $status]; + if ($limitPage) + $req['limitPage'] = $limitPage; + return Class_AvisNotice::findAllBy($req); + } + + + public function countOrphanReviews($status) { + $req = ['flags' => Class_AvisNotice::ORPHAN_FLAG, + 'order' => 'date_avis desc', + 'statut' => $status]; + + return Class_AvisNotice::countBy($req); + } + + public function countArchivedReviews($status) { + $req = ['flags' => Class_AvisNotice::ARCHIVED_FLAG, + 'order' => 'date_avis desc', + 'statut' => $status]; + + return Class_AvisNotice::countBy($req); + } + + public function findArchivedReviews($status,$limitPage=null) { + $req = ['flags' => Class_AvisNotice::ARCHIVED_FLAG, + 'order' => 'date_avis desc', + 'statut' => $status]; + if ($limitPage) + $req['limitPage'] = $limitPage; + + return Class_AvisNotice::findAllBy($req); + } protected function _addStatutAbonBibWhereClause($abon_ou_bib, &$params) { $modo_avis_abo = Class_AdminVar::get('MODO_AVIS'); // 0 apres / 1 avant de publier sur le site @@ -67,18 +137,22 @@ class AvisNoticeLoader extends Storm_Model_Loader { } + /* Renvoie les avis correspondants aux préférences de recherches données - id_catalogue: le catalogue de notices dont on veut récupérer les avis - id_panier: le panier de notices dont on veut récupérer les avis On prends les avis soit du catalogue, soit du panier, soit les dernier avis */ - public function getAvisFromPreferences($preferences, $limit_page=null) { + public function getAvisFromPreferences($preferences, $limit_page=null, $include_orphan = false) { $params = ['order' => 'DATE_AVIS DESC']; + if (!$include_orphan) + $params['flags'] = Class_AvisNotice::NO_FLAG; $preferences = array_merge(['id_panier' => 0, 'id_catalogue' => 0, - 'abon_ou_bib' => 'all'], + 'abon_ou_bib' => 'all', + ], $preferences); $id_panier = $preferences['id_panier']; @@ -94,7 +168,7 @@ class AvisNoticeLoader extends Storm_Model_Loader { if ($limit_page) $params['limitPage'] = $limit_page; - return Class_AvisNotice::getLoader()->findAllBy($params); + return Class_AvisNotice::findAllBy($params); } @@ -109,6 +183,9 @@ class AvisNoticeLoader extends Storm_Model_Loader { class Class_AvisNotice extends Storm_Model_Abstract { use Trait_Avis, Trait_Translator; + const NO_FLAG=0; + const ORPHAN_FLAG=1; + const ARCHIVED_FLAG=2; protected $_loader_class = 'AvisNoticeLoader'; protected $_table_name = 'notices_avis'; @@ -117,7 +194,11 @@ class Class_AvisNotice extends Storm_Model_Abstract { protected $_belongs_to = ['user' => ['model' => 'Class_Users', 'referenced_in' => 'id_user']]; - protected $_default_attribute_values = ['statut' => 0]; + protected $_default_attribute_values = ['statut' => 0, + 'flags' => self::NO_FLAG, + 'clef_oeuvre' => '', + 'date_avis' => null, + 'note' => 0]; protected $_notices; protected $_import_mode = false; @@ -144,6 +225,16 @@ class Class_AvisNotice extends Storm_Model_Abstract { } + public static function filterByOrphan($avis_list) { + return self::filterByMethod($avis_list, 'isOrphan'); + } + + + public static function filterByArchived($avis_list) { + return self::filterByMethod($avis_list, 'isArchived'); + } + + public static function filterByBibliothecaire($avis_list) { return self::filterByMethod($avis_list, 'isWrittenByBibliothecaire'); } @@ -154,11 +245,6 @@ class Class_AvisNotice extends Storm_Model_Abstract { } - public function getNote() { - return !$this->_attributes['note'] ? - 0 : $this->_attributes['note']; - } - public static function getNoteAverage($avis_list) { if (!$avis_list or count($avis_list) == 0) @@ -173,8 +259,6 @@ class Class_AvisNotice extends Storm_Model_Abstract { public function getNotices() { - if (!isset($this->_notices)) - $this->_notices = $this->_findNoticesByClefOeuvre(); return $this->_notices; } @@ -183,25 +267,24 @@ class Class_AvisNotice extends Storm_Model_Abstract { * Recherche les notices liées à cet avis. Si non trouvé (par exemple l'auteur de la clé * oeuvre à été mis à jour dans le SIGB, essaye de retrouver la notice et réaffecte l'avis */ - protected function _findNoticesByClefOeuvre() { - if ($notices = Class_Notice::findAllBy(['clef_oeuvre' => $this->getClefOeuvre()])) - return $notices; + public function findNoticesByClefOeuvre() { + if ($this->_notices = Class_Notice::findAllBy(['clef_oeuvre' => $this->getClefOeuvre()])) + return $this->_notices; if (!$notices = Class_Notice::findAllBy(['where' => 'clef_oeuvre like "'.$this->getTitreClefOeuvre().'-%"'])) - return []; + return $this->_notices = []; $clef_oeuvre = $notices[0]->getClefOeuvre(); foreach($notices as $notice) { //on assume que les notices ont été retrouvées si elles ont toutes la même clé oeuvre if ($clef_oeuvre !== $notice->getClefOeuvre()) - return []; + return $this->_notices = []; $this ->setClefOeuvre($clef_oeuvre) - ->setModerationNOK() ->save(); } - + $this->_notices=$notices; return $notices; } @@ -217,6 +300,8 @@ class Class_AvisNotice extends Storm_Model_Abstract { public function getFirstNotice() { + if ($this->id_notice>0) + return Class_Notice::find($this->id_notice); $notices = $this->getNotices(); if (count($notices) == 0) return null; diff --git a/library/Class/Cosmogramme/Integration/PhaseReviews.php b/library/Class/Cosmogramme/Integration/PhaseReviews.php new file mode 100644 index 0000000000000000000000000000000000000000..40aa67d398d4a546d6225bd8923a17316fa4a56f --- /dev/null +++ b/library/Class/Cosmogramme/Integration/PhaseReviews.php @@ -0,0 +1,121 @@ +<?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 + */ +require_once('cosmogramme/php/classes/classe_notice_integration.php'); + +class Class_Cosmogramme_Integration_PhaseReviews extends Class_Cosmogramme_Integration_PhaseAbstract { + const MY_ID=7.5; + + protected $_label = 'Reviews attachments'; + + public function __construct($phase, $log, $chrono) { + parent::__construct($phase, $log, $chrono); + $this->_previous_records = []; + + } + + + protected function _init($new_phase) { + + $new_phase + ->resetDatas() + ->setData('nombre', 0) + ->setData('pointeur_notice', 0) + ->setData('pointeur', + $last_update_date ? $last_update_date : '0000-00-00 00:00:00'); + + $this->_chrono + ->startOnFile() + ->startOnRecords(); + } + + + public function _execute() { + $this->_setData('pointeur_notice', 0); + while ($records = Class_AvisNotice::findAllAfter($this->_getData('pointeur_notice'))) { + + if (0 == ($this->_getData('nombre') % 100)) + $this->_log->ecrire('<span class="vert"> ' . $this->_getData('nombre') . ' records updated </span>'); + if ($this->_previous_records && (0 == count(array_filter(array_diff($this->_previous_records, $records))))) + break; + + $this->_previous_records = $records; + + $this->runUpdateForRecords($records); + + $this->_resetDbConnection(); + + } + + $this->_log->ecrire('<span class="vert">'. + 'Tous les avis ont été mis à jour :' . + ' pointeur avis : ' . $this->_getData('pointeur_avis') . + ' pointeur : ' . $this->_getData('pointeur') . + '<br>' . $this->_getData('nombre') . ' avis traités.</span>'); + + $msg = '<span class="vert">Temps de traitement : ' + . $this->_chrono->endFile() + . ' (' . $this->_chrono->meanOnFile($this->_getData('nombre'), + 'notices') . ')</span>'; + + $this->_log->ecrire($msg); + + } + protected function runUpdateForRecords($records) { + foreach ($records as $record) { + if ($this->isTimeOut()) + return $this->_resetDbConnection() + ->_phase; + $this->_runOne($record); + + } + } + + + protected function _runOne($record) { + // types starting with 100 are indexed at another phase + + $record->findNoticesByClefOeuvre(); + if ($notice = $record->getFirstNotice()) + $record->setIdNotice($notice->getId())->save(); + + $this->_setData('pointeur_notice', $record->getId()); + $this->_incrementData('nombre'); + + } + + /** @category testing */ + public function noDbReset() { + $this->_db_reset = false; + return $this; + } + protected function _resetDbConnection() { + if (!$this->_db_reset) + return $this; + + Storm_Model_Abstract::unsetLoaders(); + Zend_Db_Table::getDefaultAdapter()->closeConnection(); + setupDatabase(loadConfig()); + gc_collect_cycles(); + return $this; + } + + +} \ No newline at end of file diff --git a/library/Class/Users.php b/library/Class/Users.php index f5dca6e7d9fe166bfe1fa659e1479b7b3b7c4050..78458c16c8c9003e538c072ec610d68b94c22c17 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -627,6 +627,7 @@ class Class_Users extends Storm_Model_Abstract { public function getLastAvis() { return Class_AvisNotice::findAllBy(['id_user' => $this->getId(), 'order' => 'date_avis desc', + 'flags' => Class_AvisNotice::NO_FLAG, 'limit' => 10]); } diff --git a/library/Trait/Avis.php b/library/Trait/Avis.php index 2c4a9c88d4e69f827226abf86169e864556ec52c..9cce4a6f6a7cbadd79d12a4672f3579c59a8aaae 100644 --- a/library/Trait/Avis.php +++ b/library/Trait/Avis.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 */ trait Trait_Avis { @@ -79,6 +79,13 @@ trait Trait_Avis { return $this->getAbonOuBib() == self::$AVIS_ABONNE; } + public function isOrphan() { + return $this->getFlags() == self::ORPHAN_FLAG ; + } + + public function isArchived() { + return $this->getFlags() == self::ARCHIVED_FLAG ; + } public function beWrittenByAbonne() { return $this->setAbonOuBib(self::$AVIS_ABONNE); diff --git a/library/ZendAfi/View/Helper/Avis.php b/library/ZendAfi/View/Helper/Avis.php index 654ad437334c983bc22312237ec73a3aacc8cc57..9140d8b1bec05de234f807d20da60161cc26ac0d 100644 --- a/library/ZendAfi/View/Helper/Avis.php +++ b/library/ZendAfi/View/Helper/Avis.php @@ -63,7 +63,7 @@ class ZendAfi_View_Helper_Avis extends ZendAfi_View_Helper_BaseHelper { $this->setLimitNbWord($limit_nb_word); return ($avis->isAvisNotice()) ? - $this->avisNotice($avis, $limit_nb_word, $vignette_link_to_avis) : + $this->avisNotice($avis) : $this->avisCms($avis); } @@ -86,18 +86,19 @@ class ZendAfi_View_Helper_Avis extends ZendAfi_View_Helper_BaseHelper { } - protected function avisNotice($avis, $vignette_link_to_avis) { + protected function avisNotice($avis) { $url_vignette = URL_ADMIN_IMG . 'supports/vignette_vide.gif'; $title = $this->_('Oeuvre non trouvée'); - if (null !== $notice = $avis->getFirstNotice()) { - $title = $notice->getTitrePrincipal(); + $notice = $avis->getFirstNotice(); + if ((null !==$notice)) + { + $title = $notice->getTitrePrincipal(); - if (strlen($auteur_principal = $notice->getAuteurPrincipal()) > 0) - $title .= ' (' . $auteur_principal . ')'; - - $url_vignette = $notice->fetchUrlVignette(); - } + if (strlen($auteur_principal = $notice->getAuteurPrincipal()) > 0) + $title .= ' (' . $auteur_principal . ')'; + $url_vignette = $notice->fetchUrlVignette(); + } $content = $this->contenu_avis($avis); return $this-> diff --git a/library/ZendAfi/View/Helper/AvisBloc.php b/library/ZendAfi/View/Helper/AvisBloc.php index a94796d343af099b55175467f60095791dcbef36..db6fa4fb26ec24fb0cd39f614ec2de720ab97a97 100644 --- a/library/ZendAfi/View/Helper/AvisBloc.php +++ b/library/ZendAfi/View/Helper/AvisBloc.php @@ -16,18 +16,18 @@ * * 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 ZendAfi_View_Helper_AvisBloc extends Zend_View_Helper_HtmlElement { - public function avisBloc($libelle_bloc, $avis_list) { + public function avisBloc($libelle_bloc, $avis_list,$page=0,$nb_elements=0) { $libelle_bloc = $this->view->_($libelle_bloc); - return $this->renderHtmlAvisBloc($libelle_bloc, $avis_list); - } + return $this->renderHtmlAvisBloc($libelle_bloc, $avis_list,$page,$nb_elements); + } - public function renderHtmlAvisBloc($libelle, $list) { + public function renderHtmlAvisBloc($libelle, $list,$page=0 ,$nb_elements=0) { $html = '<h2>'.$libelle.'</h2>'; $html.= '<div>'; @@ -35,15 +35,18 @@ class ZendAfi_View_Helper_AvisBloc extends Zend_View_Helper_HtmlElement { $empty = $this->view->_('Aucun avis ' . ($libelle ? $libelle . ' ' : '') . 'à modérer.'); $html.='<p align="center" class="error">'.$empty.'</p>'; } else { - $this->view->getHelper('avis')->setActions(['validate', 'edit', 'del']); - $html.= $this->view->partialCycle('modo/_avis_partial.phtml', + + $html.= $this->view->partialCycle('modo/_avis_partial.phtml', 'avis', $list, ['first', - 'second']); + 'second']); + if ($page>0) + $html.= $this->view->Pager($nb_elements,10,$page,$this->view->url(['page' => null],null,false)); } + + return $html.='</div>'; } } - diff --git a/library/ZendAfi/View/Helper/BoutonIco.php b/library/ZendAfi/View/Helper/BoutonIco.php index 7ec4993d55362d1254c1a69756f11cc6df7c4430..6abedb0e2bbce0055b8ed4d3058d522816cbdd00 100644 --- a/library/ZendAfi/View/Helper/BoutonIco.php +++ b/library/ZendAfi/View/Helper/BoutonIco.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 ZendAfi_View_Helper_BoutonIco extends ZendAfi_View_Helper_BaseHelper { @@ -43,7 +43,7 @@ class ZendAfi_View_Helper_BoutonIco extends ZendAfi_View_Helper_BaseHelper { $options = [ - 'src' => $this->picto, + 'src' => $this->picto, 'class' => 'ico']; if ($this->bulle) { @@ -51,7 +51,7 @@ class ZendAfi_View_Helper_BoutonIco extends ZendAfi_View_Helper_BaseHelper { $options['title'] = $this->bulle; } - if ('DEL' == strtoupper($this->type)) + if ('DEL' == strtoupper($this->type)) $options['onclick'] = 'javascript:return confirm(\'' . $this->traduire('Êtes vous sûr de vouloir supprimer cet élément ?') . '\');'; $html = $this->view->tag('img', null, $options); @@ -64,14 +64,16 @@ class ZendAfi_View_Helper_BoutonIco extends ZendAfi_View_Helper_BaseHelper { protected function predefined($type) { $mapping = [ - 'ADD' => ['add.gif', $this->traduire('Ajouter')], - 'EDIT'=> ['edit.gif', $this->traduire('Modifier')], - 'DEL' => ['del.gif', $this->traduire('Supprimer')], - 'CONFIRM'=> ['coche_verte.gif', $this->traduire('Confirmer')], - 'VALIDATE' => ['coche_verte.gif', $this->traduire('Valider')], - 'TEST' => ['tester.gif', $this->traduire('Tester')], - 'SHOW' => ['show.gif', $this->traduire('Visualiser')], - 'MAIL' => ['mail.png', $this->traduire('Envoyer par mail')] + 'ADD' => ['add.gif', $this->traduire('Ajouter')], + 'EDIT'=> ['edit.gif', $this->traduire('Modifier')], + 'DEL' => ['del.gif', $this->traduire('Supprimer')], + 'CONFIRM'=> ['coche_verte.gif', $this->traduire('Confirmer')], + 'VALIDATE' => ['coche_verte.gif', $this->traduire('Valider')], + 'TEST' => ['tester.gif', $this->traduire('Tester')], + 'SHOW' => ['show.gif', $this->traduire('Visualiser')], + 'MAIL' => ['mail.png', $this->traduire('Envoyer par mail')], + 'VISIBLE' => ['hide.gif', $this->traduire('Rendre visible')], + 'INVISIBLE' => ['show.gif', $this->traduire('Archiver')] ]; $type = strtoupper($type); diff --git a/tests/application/modules/admin/controllers/ModoControllerTest.php b/tests/application/modules/admin/controllers/ModoControllerTest.php index 4b042f15cc6a998d7c0ba9db5f9709e7f6499cfb..9ec78abf35d6de487a2cc02b69642d406c575d9f 100644 --- a/tests/application/modules/admin/controllers/ModoControllerTest.php +++ b/tests/application/modules/admin/controllers/ModoControllerTest.php @@ -53,9 +53,25 @@ class ModoControllerIndexActionTest extends Admin_AbstractControllerTestCase { $this->fixture('Class_AvisNotice', ['id' => 1, 'id_notice' => 1002, 'entete' => 'Mon avis', + 'note'=> 2, + 'id_user' => null, 'avis' => 'Ce livre est vraiment bien !', 'statut' => 0]); + $this->fixture('Class_Notice', ['id' => 1032, + 'titre_principal' => 'B comme bière : la bière expliquée aux (grands) enfants']); + + $this->fixture('Class_AvisNotice', ['id' => 223, + 'id_notice' => 1002, + 'entete' => 'Bulles', + 'note'=> 2, + 'id_user' => null, + 'flags' => 0, + 'avis' => ' Pour faire aimer la biere aux enfants!', + 'id_notice' => 1032, + 'statut' => 1]); + + $this->fixture('Class_SuggestionAchat', ['id' => 92, 'titre' => 'Kikolol', 'auteur' => 'Moi', @@ -602,13 +618,103 @@ class ModoControllerAvisnoticeActionTest extends Admin_AbstractControllerTestCas /** @test **/ public function avisnoticeShouldContainsListAvisBibliothecaires() { - $this->assertXpathContentContains('//div//h2', 'Bibliothécaires', $this->_response->getBody()); + $this->assertXpathContentContains('//div//h2', 'bibliothécaires', $this->_response->getBody()); } /** @test **/ public function avisnoticeShouldContainsListAvisAbonnes() { - $this->assertXpathContentContains('//div//h2', 'Abonnés', $this->_response->getBody()); + $this->assertXpathContentContains('//div//h2', 'abonnés', $this->_response->getBody()); + } + + + /** @test **/ + public function avisnoticeShouldContainsOrphanFlag() { + $this->assertXpathContentContains('//div//h2', 'Avis orphelins', $this->_response->getBody()); + } + + + /** @test */ + public function LinkToAllModeratedReviewsShouldBeDisplayed() { + $this->assertXPathContentContains('//a', 'Afficher tous les avis modérés', $this->_response->getBody()); + } +} + + + + + +class ModoControllerAllReviewsActionTest extends ModoControllerIndexActionTest { + + public function setup() { + parent::setup(); + $this->dispatch('admin/modo/allreviews', true); + } + + + /** @test **/ + public function moderatedReviewsShouldBeDisplayed() { + $this->assertXpathContentContains('//div//h2', 'B comme bière : la bière expliquée aux (grands) enfants', $this->_response->getBody()); + } + + + /** @test **/ + public function unmoderatedReviewsShouldNotBeDisplayed() { + $this->assertNotXpathContentContains('//div//h2', 'Para Ana', $this->_response->getBody()); + } + +} + + + + + +class ModoControllerAllReviewsPageActionTest extends ModoControllerIndexActionTest { + + public function setup() { + parent::setup(); + $this->dispatch('admin/modo/allreviews/page/10', true); + } + + + /** @test **/ + public function moderatedReviewsShouldBeDisplayedEvenIfPageIsOutOfBound() { + $this->assertXpathContentContains('//div//h2', 'B comme bière : la bière expliquée aux (grands) enfants', $this->_response->getBody()); + } + + + /** @test */ + public function LinkToNonModeratedReviewsShouldBeDisplayed() { + $this->assertXPathContentContains('//a', 'Afficher les avis non modérés', $this->_response->getBody()); + } +} + + + +class ModoControllerArchivedReviewsActionTest extends ModoControllerIndexActionTest { + + public function setup() { + parent::setup(); + } + + /** @test **/ + public function moderatedReviewsShouldBeArchived() { + $this->dispatch('admin/modo/invisibleavisnotice/id/223', true); + $this->assertEquals(2,Class_AvisNotice::find(223)->getFlags()); + } + + /** @test **/ + public function moderatedReviewsShouldBeVisible() { + $avis=(Class_AvisNotice::find(223)); + $avis->setFlags(2); + $avis->save(); + $this->dispatch('admin/modo/visibleavisnotice/id/223', true); + $this->assertEquals(0,Class_AvisNotice::find(223)->getFlags()); + } + } + + + ?> \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php b/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php index b678eae6443f6a10e55afc965d81ee337b751a38..f081f6303ee1b17b740e4a7ba1b5a936a22d037a 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php @@ -21,6 +21,8 @@ require_once 'AbstractControllerTestCase.php'; abstract class AbonneFlorenceIsLoggedControllerTestCase extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + protected function _initProfilHook($profil) { $profil ->setBrowser('opac') @@ -30,19 +32,23 @@ abstract class AbonneFlorenceIsLoggedControllerTestCase extends AbstractControll public function setUp() { parent::setUp(); - Class_Users::beVolatile(); - Class_AvisNotice::beVolatile(); - Class_Notice::beVolatile(); - $this->florence = Class_Users::newInstanceWithId(123456) - ->setPseudo('FloFlo') - ->setRoleLevel(2) - ->setRole('abonne_sigb') - ->setLogin('florence') - ->setPassword('caramel') - ->setIdSite(1) - ->setIdabon('00123') - ->setFicheSIGB(['type_com' => 0]); - $this->florence->save(); + $this->fixture('Class_AdminVar', + ['id' => 'AVIS_MIN_SAISIE', + 'valeur' => 0]); + $this->fixture('Class_AdminVar', + ['id' => 'AVIS_MAX_SAISIE', + 'valeur' => 1000]); + + $this->florence = $this->fixture('Class_Users', + ['id' => 123456, + 'pseudo' => 'FloFlo', + 'role_level' => 2, + 'role' => 'abonne_sigb', + 'login' => 'florence', + 'password' => 'caramel', + 'id_site' => 1, + 'idabon' => '00123', + 'fiche_sigb' => ['type_com' => 0]]); ZendAfi_Auth::getInstance()->logUser($this->florence); @@ -207,12 +213,12 @@ class AbonneControllerAvisNoticeWithAvisTest extends AbonneControllerAvisTestCas public function setUp() { parent::setUp(); - $avis = Class_AvisNotice::newInstanceWithId(12, ['Avis' => 'Excellent livre', - 'Entete' => 'Le sorcier super mimi', - 'note' => 4, - 'clef_oeuvre' => 'POTTER', - 'user' => $this->florence]); - $avis->save(); + $avis = $this->fixture('Class_AvisNotice', ['id' => 12, + 'Avis' => 'Excellent livre', + 'Entete' => 'Le sorcier super mimi', + 'note' => 4, + 'clef_oeuvre' => 'POTTER', + 'user' => $this->florence]); $this->dispatch('/opac/abonne/avis/id_notice/53'); $this->_xpath = new Storm_Test_XPath(); $this->_json = json_decode($this->_response->getBody()); @@ -250,105 +256,128 @@ abstract class AvisControllersFixturesTestCase extends AbonneFlorenceIsLoggedCon public function setUp() { parent::setUp(); - $this->modo_avis = new Class_AdminVar(); - $this->modo_avis - ->setId('MODO_AVIS') - ->setValeur(0); - $this->modo_avis_biblio = new Class_AdminVar(); - $this->modo_avis_biblio - ->setId('MODO_AVIS_BIBLIO') - ->setValeur(0); + $this->fixture('Class_AdminVar', + ['id' => 'MODO_AVIS', + 'valeur' => 0]); - $this->readspeaker = new Class_AdminVar(); - $this->readspeaker - ->setId('ID_READ_SPEAKER') - ->setValeur('54QCJRHZ31IPBV7GW3DKBPUYYP579A14'); + $this->fixture('Class_AdminVar', + ['id' => 'MODO_AVIS_BIBLIO', + 'valeur' => 0]); + $this->fixture('Class_AdminVar', + ['id' => 'ID_READ_SPEAKER', + 'valeur' => '54QCJRHZ31IPBV7GW3DKBPUYYP579A14']); - Class_AdminVar::getLoader() - ->cacheInstance($this->modo_avis) - ->cacheInstance($this->modo_avis_biblio) - ->cacheInstance($this->readspeaker); - $this->millenium = Class_Notice::newInstanceWithId(816, ['titre_principal' => 'Millenium', - 'clef_alpha' => 'MILLENIUM', - 'auteur_principal' => 'Stieg Larsson', - 'url_vignette' => '', - 'url_image' => '' - ] + $this->millenium = $this->fixture('Class_Notice', ['id' => 816, + 'titre_principal' => 'Millenium', + 'clef_alpha' => 'MILLENIUM', + 'auteur_principal' => 'Stieg Larsson', + 'url_vignette' => '', + 'url_image' => '' + ] ); - $this->millenium->save(); - $this->millenium_with_vignette = Class_Notice::newInstanceWithId(817, ['titre_principal' => 'Millenium', - 'clef_alpha' => 'MILLENIUM', - 'auteur_principal' => 'Stieg Larsson', - 'url_vignette' => 'http://amazon.com/vignette_millenium.png' - ] + + + + + $this->millenium_with_vignette = $this->fixture('Class_Notice', ['id' => 817, + 'titre_principal' => 'Millenium', + 'clef_alpha' => 'MILLENIUM', + 'auteur_principal' => 'Stieg Larsson', + 'url_vignette' => 'http://amazon.com/vignette_millenium.png' + ] ); - $this->millenium_with_vignette->save(); + $this->avis_millenium = $this->fixture('Class_AvisNotice', ['id' => 13, 'entete' => "J'adore", - 'avis' => '<div><ul><li>Suspense Intense !</li><li>Suspense Intense !</li></ul></div>', - 'note' => 5, - 'date_avis' => '2011-03-18 13:00:00', - 'user' => $this->florence, - 'statut' => 0, - 'abon_ou_bib'=>1 , - 'notices' => [$this->millenium, - $this->millenium_with_vignette] ]); - - $this->avis_millenium->save(); - $this->potter = Class_Notice::newInstance(); - $this->potter - ->setTitrePrincipal('Potter et la chambre des secrets') - ->setAuteurPrincipal('') - ->setUrlVignette('http://amazon.com/vignette_potter.png'); - $this->potter->save(); - $this->avis_potter = Class_AvisNotice::newInstanceWithId(25, - ['entete' => 'Prenant', - 'avis' => "Mais un peu trop naïf", - 'note'=>4, - 'date_avis' => '2010-10-12 10:00:00', - 'user'=>$this->florence, - 'statut' => 1, - 'abon_out_bib' => 1, - 'notices' => [$this->potter]]); - - $this->avis_potter->save(); - - $this->avis_lost = Class_AvisNotice::newInstanceWithId(67, - ['entete' =>"C'est perdu", - 'avis' =>"Plus de notice, ni d'utilisateur", - 'note' => 4, - 'date_avis' => '2008-10-12 10:00:00', - 'user'=>null, - 'statut' => 1, - 'abon_out_bib' => 1, - 'notices' => []]); - $this->avis_lost->save(); - - - $this->florence->setAvis([$this->avis_millenium, $this->avis_potter]); - $this->florence->save(); - $dupont = Class_Users::newInstanceWithId(56, ['nom'=>'Dupont']); - - $avis_millenium_dupont = Class_AvisNotice::newInstanceWithId(156) - ->setEntete("Cool") - ->setAvis("effrayant") - ->setNote(5) - ->setDateAvis('2011-03-18 13:00:00') - ->setAuteur($dupont) - ->setUser($dupont) - ->setStatut(0) - ->setAbonOuBib(1) - ->setNotices([$this->millenium]); - $dupont->setAvis([$avis_millenium_dupont]); - $dupont->save(); - $avis_millenium_dupont->save(); + 'avis' => '<div><ul><li>Suspense Intense !</li><li>Suspense Intense !</li></ul></div>', + 'note' => 5, + 'date_avis' => '2011-03-18 13:00:00', + 'user' => $this->florence, + 'statut' => 0, + 'abon_ou_bib'=>1 , + 'notices' => [$this->millenium, + $this->millenium_with_vignette] ]); + + $this->potter = $this->fixture('Class_Notice', + ['id'=> 22, + 'titre_principal' => 'Potter et la chambre des secrets', + 'auteur_principal' => '', + 'url_vignette' => 'http://amazon.com/vignette_potter.png']); + + $this->avis_potter = $this->fixture('Class_AvisNotice', + ['id' => 25, + 'entete' => 'Prenant', + 'avis' => "Mais un peu trop naïf", + 'note'=>4, + 'date_avis' => '2010-10-12 10:00:00', + 'user'=>$this->florence, + 'statut' => 1, + 'abon_out_bib' => 1, + 'notices' => [$this->potter]]); + + $lost=$this->fixture('Class_AvisNotice', ['id' => 178, + 'entete' => "Lost highway", + 'clef_oeuvre' => 'LOST-LOST', + 'avis' => 'Oh po po !', + 'note' => 5, + 'date_avis' => '2015-03-18 13:00:00', + 'user' => $this->florence, + 'statut' => 1, + 'flags' => Class_AvisNotice::ORPHAN_FLAG, + 'abon_ou_bib'=>1, + 'id_notice' => 30]); + + + $this->avis_lost = $this->fixture('Class_AvisNotice', + ['id' => 67, + 'entete' =>"C'est perdu", + 'avis' =>"Plus de notice, ni d'utilisateur", + 'note' => 4, + 'date_avis' => '2008-10-12 10:00:00', + 'user'=>null, + 'statut' => 1, + 'abon_out_bib' => 1, + 'flags' => 1, + 'notices' => []]); + + + + $dupont = $this->fixture('Class_Users', ['id' => 56 , + 'login' => 'Dupont', + 'nom'=>'Dupont', + 'password' => 'pwd', + 'id_abon' => 435]); + + + $avis_millenium_dupont = $this->fixture('Class_AvisNotice', + ['id' => 156, + 'entete' => "Cool", + 'avis' => "effrayant", + 'note' => 5, + 'setDateAvis' => '2011-03-18 13:00:00', + 'auteur' => $dupont, + 'user' => $dupont, + 'statut' => 0, + 'abon_out_bib' => 1, + 'notices' =>[$this->millenium] + ]); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice') + ->whenCalled('findAllBy') + ->with(['where' => 'clef_oeuvre like "LOST-%"']) + ->answers(null) + ->whenCalled('findAllBy') + ->with(['where' => 'clef_oeuvre like "MILLENIUM-%"']) + ->answers([$this->millenium,$this->millenium_with_vignette]) + ; + + } } @@ -381,9 +410,9 @@ class AbonneControllerAvisViewFicheWithAvisTest extends AvisControllersFixturesT } /** @test */ - public function pageShouldDisplayVousAvezRedigeDeuxAvis() { + public function pageShouldDisplayVousAvezRedigeTroiAvis() { $this->assertXPathContentContains('//a', - 'Vous avez rédigé 2 avis', + 'Vous avez rédigé 3 avis', $this->_response->getBody()); } @@ -392,6 +421,8 @@ class AbonneControllerAvisViewFicheWithAvisTest extends AvisControllersFixturesT public function linkAvisShouldGoToAbonneViewAvis() { $this->assertXPath('//a[contains(@href, "/abonne/viewavis/id/123456")]'); } + + } @@ -400,26 +431,36 @@ class AbonneControllerAvisViewFicheWithAvisTest extends AvisControllersFixturesT class AbonneControllerAvisBlogControllerViewAuteurActionTest extends AvisControllersFixturesTestCase { public function setUp() { parent::setUp(); + + $this->dispatch('/opac/blog/viewauteur/id/123456'); } + + /** @test */ + public function AvisWithoutNoticeShouldBeDisplayedForAuthor() { + $this->assertXPathContentContains("//div[@class='critique'][1]//a", 'Lost highway'); + } + + public function testPageIsRendered() { $this->assertController('blog'); $this->assertAction('viewauteur'); } public function testMilleniumIsHere() { - $this->assertXPathContentContains("//div[@class='critique'][1]//h2", 'Millenium (Stieg Larsson)'); + $this->assertXPathContentContains("//div[@class='critique'][2]//h2", 'Millenium (Stieg Larsson)'); } + /** @test */ public function milleniumShouldLinkToNoticeMilleniumWithRetourAbonneViewAvis() { - $this->assertXPath('//a[contains(@href, "/recherche/viewnotice/id/817/clef/MILLENIUM/retour_abonne/viewavis")]',$this->_response->getBody()); + $this->assertXPath('//a[contains(@href, "/recherche/viewnotice/id/817/clef/MILLENIUM/retour_abonne/viewavis")]'); } public function testPotterIsHere() { - $this->assertXPathContentContains("//div[@class='critique'][2]//h2", 'Potter et la chambre des secrets'); + $this->assertXPathContentContains("//div[@class='critique'][3]//h2", 'Potter et la chambre des secrets'); } public function testDeleteMilleniumButtonPresent() { @@ -504,7 +545,7 @@ class AbonneControllerAvisRssControllerViewAvisUserTest extends AvisControllersF /** @test */ function firstItemTitleShouldBeJAdore() { - $this->assertXPathContentContains('//channel/item/title', "J'adore"); + $this->assertXPathContentContains('//channel/item/title', "J'adore",$this->_response->getBody()); } @@ -601,8 +642,8 @@ class AbonneControllerAvisBlogControllerLastCritiquesTest extends AvisController /** @test */ - public function lostRratingShouldBeAtThirdPlace() { - $this->assertXPathContentContains("//div[@class='critique'][3]//h2", 'Oeuvre non trouvée'); + public function lostRratingShouldNotBeDIsplayed() { + $this->assertNotXPathContentContains("//div[@class='critique'][3]//h2", 'Oeuvre non trouvée'); } } @@ -612,21 +653,16 @@ abstract class ModuleSelectionCritiquesTestCase extends AvisControllersFixturesT public function setUp() { parent::setUp(); - $preferences = array('modules' => array(3 => array('division' => 2, - 'type_module' => 'CRITIQUES', - 'preferences' => array('titre' => 'Coups de coeur' - )))); - $profil = Class_Profil::getLoader() - ->find(2) - ->setCfgModules( ['blog' => ['viewcritiques' => ['nb_display' => 2]]]) - ->setCfgAccueil($preferences); + $preferences = ['modules' => [3 => ['division' => 2, + 'type_module' => 'CRITIQUES', + 'preferences' => ['titre' => 'Coups de coeur' + ] + ]]]; + $profil = $this->fixture('Class_Profil', + ['id'=>2, + 'cfg_modules' => ['blog' => ['viewcritiques' => ['nb_display' => 2]]], + 'cfg_accueil' => $preferences]); - $this->_generateLoaderFor('Class_AvisNotice', ['getAvisFromPreferences']) -// ->expects($this->once()) - ->method('getAvisFromPreferences') - ->will($this->returnValue([$this->avis_millenium, - $this->avis_potter, - $this->avis_lost])); } } @@ -665,11 +701,11 @@ class AbonneControllerAvisBlogControllerViewCritiquesTest extends ModuleSelectio } public function testMilleniumIsHere() { - $this->assertQueryContentContains('h2', 'Millenium'); + $this->assertQueryContentContains('h2', 'Millenium',$this->_response->getBody()); } public function testPotterIsHere() { - $this->assertQueryContentContains('h2', 'Potter'); + $this->assertQueryContentContains('h2', 'Potter',$this->_response->getBody()); } /** @test */ @@ -781,9 +817,9 @@ class AbonneControllerAvisBlogControllerViewReadAvisTest extends AbonneFlorence class AbonneControllerEditAvisNoticeNotFoundActionTest extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; public function setUp() { parent::setUp(); - Class_AvisNotice::beVolatile(); $this->dispatch('/opac/abonne/editavisnotice/id/54', true); } diff --git a/tests/application/modules/opac/controllers/BlogControllerTest.php b/tests/application/modules/opac/controllers/BlogControllerTest.php index 8ccc8b87621b11a5442ee55904e17d671b5003b5..c01c62513941be41e1a273e92b26b1c476e153ab 100644 --- a/tests/application/modules/opac/controllers/BlogControllerTest.php +++ b/tests/application/modules/opac/controllers/BlogControllerTest.php @@ -68,8 +68,10 @@ class BlogControllerHierarchicalTest extends AbstractControllerTestCase { $this->fixture('Class_AvisNotice', ['id' => 1, + 'id_notice' => 233134, 'note' => 5, 'entete' => 'Incroyable', + 'id_notice' => $this->ksp->getId(), 'avis' => 'What a wonderful game', 'statut' => 1, 'date_avis' => '2015-05-18 00:00:00', @@ -143,7 +145,7 @@ class BlogControllerHierarchicalTest extends AbstractControllerTestCase { /** @test */ public function kspShouldBePresent() { - $this->assertXPathContentContains('//h2', 'Kerbal Space Program'); + $this->assertXPathContentContains('//h2', 'Kerbal Space Program',$this->_response->getBody()); } diff --git a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php index b87bdc6d4b43d25eb881292c8d96b92e06f22434..779e101872d096abfdab79c0835153f85d30d91c 100644 --- a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php +++ b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php @@ -48,7 +48,6 @@ abstract class ProfilOptionsControllerWithProfilAdulteTestCase extends AbstractC 'clef_oeuvre' => 'HPELPA', 'clef_alpha' => 'POTTER', 'exemplaires' => []])]); - $this->setUpProfilAdulte(); $this->setUpProfilJeunesse(); } diff --git a/tests/library/Class/AvisNoticeTest.php b/tests/library/Class/AvisNoticeTest.php index 3a39385cacf05c9aae66d4076c55fba38398f0e9..4ba7297a05416b8aaf41bd399c007bd02ab605cc 100644 --- a/tests/library/Class/AvisNoticeTest.php +++ b/tests/library/Class/AvisNoticeTest.php @@ -367,39 +367,35 @@ class AvisTestFindAllByUserAndClefOeuvreTestCase extends AvisTestFindAllTestCase class NoticeTestHasManyAvisTest extends Storm_Test_ModelTestCase { public function setUp() { - $this->millenium = Class_Notice::newInstanceWithId(34, ['clef_oeuvre' => 'MILLENIUM--LARSSON']); + $this->millenium = $this->fixture('Class_Notice', ['id' => 34, + 'clef_oeuvre' => 'MILLENIUM--LARSSON']); $this->steve = Class_Users::newInstanceWithId(5, ['prenom' => 'Steve']); - $this->avis_millenium_steve = Class_AvisNotice::newInstanceWithId(12, - ['user' => $this->steve, - 'entete' => 'ça fait peur', - 'avis' => "c'est glauque", - 'clef_oeuvre' => 'MILLENIUM--LARSSON', - 'note' => 2]); - - $this->bryan = Class_Users::newInstanceWithId(6, ['prenom' => 'Bryan']); - $this->avis_millenium_lost_bryan = Class_AvisNotice::newInstanceWithId(15, - ['user' => $this->bryan, - 'entete' => 'perdu', - 'avis' => "perdu sniff sniff", - 'clef_oeuvre' => 'MILLENIUM--SLARSSON', - 'note' => 5]); - - - $this->avis_loader = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_AvisNotice'); - $this->avis_loader->whenCalled('save')->answers(true); + $this->avis_millenium_steve = $this->fixture('Class_AvisNotice', ['id' => 12, + 'user' => $this->steve, + 'entete' => 'ça fait peur', + 'avis' => "c'est glauque", + 'clef_oeuvre' => 'MILLENIUM--LARSSON', + 'note' => 2]); + + $this->bryan = $this->fixture('Class_Users' , ['id' =>6, 'login' => 'bryan', 'password' => 'toto', 'prenom' => 'Bryan']); + $this->avis_millenium_lost_bryan = $this->fixture('Class_AvisNotice', ['id' =>15, + 'user' => $this->bryan, + 'entete' => 'perdu', + 'avis' => "perdu sniff sniff", + 'clef_oeuvre' => 'MILLENIUM--SLARSSON', + 'note' => 5]); + + + //$this->avis_loader = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_AvisNotice'); + // $this->avis_loader->whenCalled('save')->answers(true); $this->notice_loader = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice'); + } /** @test */ public function noticeMilleniumGetAvisForUserSteveShouldReturnAvisSteve() { - $this->avis_loader - ->whenCalled('findAllBy') - ->with(['clef_oeuvre' => 'MILLENIUM--LARSSON', - 'id_user' => 5]) - ->answers([$this->avis_millenium_steve]); - $found_avis = $this->millenium->getAvisByUser($this->steve); $this->assertEquals([$this->avis_millenium_steve], $found_avis); @@ -408,31 +404,18 @@ class NoticeTestHasManyAvisTest extends Storm_Test_ModelTestCase { /** @test */ public function noticeMilleniumGetAvisShouldReturnAllAvisOnClefOeuvre() { - $avis_millenium_robert = new Class_AvisNotice(); - - $this->avis_loader - ->whenCalled('findAllBy') - ->with(['clef_oeuvre' => 'MILLENIUM--LARSSON']) - ->answers([$this->avis_millenium_steve, - $avis_millenium_robert]); - $found_avis = $this->millenium->getAvis(); - $this->assertEquals([$this->avis_millenium_steve, - $avis_millenium_robert], + $this->assertEquals([$this->avis_millenium_steve + ], $found_avis); } + /** @test */ public function avisMilleniumSteveGetNoticesShouldReturnNoticeMillenium() { - $this->notice_loader - ->whenCalled('findAllBy') - ->with(['clef_oeuvre' => 'MILLENIUM--LARSSON']) - ->answers([$this->millenium]); - - $notices_found = $this->avis_millenium_steve->getNotices(); - $this->assertEquals(array($this->millenium), - $notices_found); + $notices_found = $this->avis_millenium_steve->findNoticesByClefOeuvre(); + $this->assertEquals(array($this->millenium), $notices_found); } @@ -447,28 +430,29 @@ class NoticeTestHasManyAvisTest extends Storm_Test_ModelTestCase { ->with(['where' => 'clef_oeuvre like "MILLENIUM-%"']) ->answers([$this->millenium]) ->beStrict(); - + $this->avis_millenium_lost_bryan->setStatut(1); + $this->avis_millenium_lost_bryan->findNoticesByClefOeuvre(); $this->assertEquals([$this->millenium], $this->avis_millenium_lost_bryan->getNotices()); - return $this->avis_loader->getFirstAttributeForLastCallOn('save'); + return $this->avis_millenium_lost_bryan; } - - /** + /** * @test * @depends lostAvisMilleniumGetNoticesShouldSearchNoticeOnTitleClefOeuvre */ - public function avisLostShouldBeSaved($saved_avis) { - $this->assertEquals('MILLENIUM--LARSSON', $saved_avis->getClefOeuvre()); + public function ModerationShouldNotBeReset($saved_avis) { + $this->assertEquals(1, $saved_avis->getStatut()); } + /** * @test * @depends lostAvisMilleniumGetNoticesShouldSearchNoticeOnTitleClefOeuvre */ - public function avisLostShouldGoThroughModeration($saved_avis) { - $this->assertEquals(0, $saved_avis->getStatut()); + public function avisLostShouldBeSaved($saved_avis) { + $this->assertEquals('MILLENIUM--LARSSON', $saved_avis->getClefOeuvre()); } } @@ -602,14 +586,14 @@ class AvisLoaderGetAvisFromPreferencesTest extends AvisTestFindAllTestCase { public function testDefaultSQLQuery() { $this->assertQueryIs("SELECT `notices_avis`.* ". "FROM `notices_avis` ". - "ORDER BY `DATE_AVIS` DESC"); + "WHERE (flags=0) ORDER BY `DATE_AVIS` DESC"); } public function testWithAllAndModoAPosteriori() { $this->preferences['abon_ou_bib'] = 'all'; $this->assertQueryIs("SELECT `notices_avis`.* ". "FROM `notices_avis` ". - "ORDER BY `DATE_AVIS` DESC"); + "WHERE (flags=0) ORDER BY `DATE_AVIS` DESC"); } @@ -618,7 +602,7 @@ class AvisLoaderGetAvisFromPreferencesTest extends AvisTestFindAllTestCase { $this->preferences['abon_ou_bib'] = 'all'; $this->assertQueryIs("SELECT `notices_avis`.* ". "FROM `notices_avis` ". - "WHERE ((STATUT=1 OR ABON_OU_BIB=1)) ". + "WHERE (flags=0) AND ((STATUT=1 OR ABON_OU_BIB=1)) ". "ORDER BY `DATE_AVIS` DESC"); } @@ -628,7 +612,7 @@ class AvisLoaderGetAvisFromPreferencesTest extends AvisTestFindAllTestCase { $this->preferences['abon_ou_bib'] = 'all'; $this->assertQueryIs("SELECT `notices_avis`.* ". "FROM `notices_avis` ". - "WHERE ((STATUT=1 OR ABON_OU_BIB=0)) ". + "WHERE (flags=0) AND ((STATUT=1 OR ABON_OU_BIB=0)) ". "ORDER BY `DATE_AVIS` DESC"); } @@ -641,7 +625,7 @@ class AvisLoaderGetAvisFromPreferencesTest extends AvisTestFindAllTestCase { $this->assertQueryIs("SELECT `notices_avis`.* ". "FROM `notices_avis` ". - "WHERE ((STATUT=1 OR ABON_OU_BIB=1) ". + "WHERE (flags=0) AND ((STATUT=1 OR ABON_OU_BIB=1) ". "AND (STATUT=1 OR ABON_OU_BIB=0)) ". "ORDER BY `DATE_AVIS` DESC"); } @@ -651,7 +635,7 @@ class AvisLoaderGetAvisFromPreferencesTest extends AvisTestFindAllTestCase { $this->preferences['abon_ou_bib'] = '0'; $this->assertQueryIs("SELECT `notices_avis`.* ". "FROM `notices_avis` ". - "WHERE (ABON_OU_BIB='0') ". + "WHERE (flags=0) AND (ABON_OU_BIB='0') ". "ORDER BY `DATE_AVIS` DESC"); } @@ -662,7 +646,7 @@ class AvisLoaderGetAvisFromPreferencesTest extends AvisTestFindAllTestCase { $this->preferences['abon_ou_bib'] = '0'; $this->assertQueryIs("SELECT `notices_avis`.* ". "FROM `notices_avis` ". - "WHERE (ABON_OU_BIB='0') ". + "WHERE (flags=0) AND (ABON_OU_BIB='0') ". "AND ((STATUT=1 OR ABON_OU_BIB=1)) ". "ORDER BY `DATE_AVIS` DESC"); } @@ -672,7 +656,7 @@ class AvisLoaderGetAvisFromPreferencesTest extends AvisTestFindAllTestCase { $this->preferences['abon_ou_bib'] = '1'; $this->assertQueryIs("SELECT `notices_avis`.* ". "FROM `notices_avis` ". - "WHERE (ABON_OU_BIB='1') ". + "WHERE (flags=0) AND (ABON_OU_BIB='1') ". "ORDER BY `DATE_AVIS` DESC"); } @@ -682,7 +666,7 @@ class AvisLoaderGetAvisFromPreferencesTest extends AvisTestFindAllTestCase { $this->preferences['abon_ou_bib'] = '1'; $this->assertQueryIs("SELECT `notices_avis`.* ". "FROM `notices_avis` ". - "WHERE (ABON_OU_BIB='1') ". + "WHERE (flags=0) AND (ABON_OU_BIB='1') ". "AND ((STATUT=1 OR ABON_OU_BIB=0)) ". "ORDER BY `DATE_AVIS` DESC"); } @@ -811,7 +795,6 @@ class AvisVisibilityTest extends ModelTestCase { } - class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); @@ -864,9 +847,11 @@ class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { ->whenCalled('findAllBy') ->with(['order' => 'DATE_AVIS DESC', 'clef_oeuvre' => ['POTTER'], + 'flags' => '0', 'where' => '(STATUT=1 OR ABON_OU_BIB=1) AND (STATUT=1 OR ABON_OU_BIB=0)']) ->answers([$this->_avis_bib_moderated, $this->_avis_abon_moderated]); + $this->assertEquals([$this->_avis_bib_moderated, $this->_avis_abon_moderated], Class_AvisNotice::getAvisFromPreferences(['id_panier' => 1])); } @@ -879,6 +864,7 @@ class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { ->with(['order' => 'DATE_AVIS DESC', 'clef_oeuvre' => ['POTTER'], 'ABON_OU_BIB' => 0, + 'flags' => 0, 'where' => '(STATUT=1 OR ABON_OU_BIB=1) AND (STATUT=1 OR ABON_OU_BIB=0)']) ->answers([$this->_avis_abon_moderated]); @@ -894,6 +880,7 @@ class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { ->with(['order' => 'DATE_AVIS DESC', 'clef_oeuvre' => ['POTTER'], 'ABON_OU_BIB' => 1, + 'flags' => 0, 'where' => '(STATUT=1 OR ABON_OU_BIB=1) AND (STATUT=1 OR ABON_OU_BIB=0)']) ->answers([$this->_avis_bib_moderated]); @@ -911,6 +898,7 @@ class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { ->with(['order' => 'DATE_AVIS DESC', 'clef_oeuvre' => ['POTTER'], 'ABON_OU_BIB' => 0, + 'flags' => 0, 'where' => '(STATUT=1 OR ABON_OU_BIB=0)']) ->answers([$this->_avis_abon_moderated, $this->_avis_abon_not_moderated]); @@ -928,6 +916,7 @@ class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { ->whenCalled('findAllBy') ->with(['order' => 'DATE_AVIS DESC', 'clef_oeuvre' => ['POTTER'], + 'flags' => 0, 'where' => '(STATUT=1 OR ABON_OU_BIB=0)']) ->answers([$this->_avis_bib_moderated, $this->_avis_abon_moderated, $this->_avis_abon_not_moderated]); @@ -947,6 +936,7 @@ class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { ->whenCalled('findAllBy') ->with(['order' => 'DATE_AVIS DESC', 'clef_oeuvre' => ['POTTER'], + 'flags' => 0, 'where' => '(STATUT=1 OR ABON_OU_BIB=1)']) ->answers([$this->_avis_bib_moderated, $this->_avis_bib_not_moderated, $this->_avis_abon_moderated]); @@ -970,6 +960,7 @@ class AvisNoticeAvisFromPreferencesTest extends Storm_Test_ModelTestCase { Storm_Test_ObjectWrapper::onLoaderOfModel('Class_AvisNotice') ->whenCalled('findAllBy') ->with(['order' => 'DATE_AVIS DESC', + 'flags' => 0, 'id_notice' => -1]) ->answers([$this->_avis_bib_moderated, $this->_avis_bib_not_moderated, $this->_avis_abon_moderated]); diff --git a/tests/library/Class/Cosmogramme/Integration/PhaseReviewsTest.php b/tests/library/Class/Cosmogramme/Integration/PhaseReviewsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..ce21f084dc5f5cf0698a580ecf92ba759b41476b --- /dev/null +++ b/tests/library/Class/Cosmogramme/Integration/PhaseReviewsTest.php @@ -0,0 +1,113 @@ +<?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 + */ + + +abstract class PhaseReviewsTestCase extends Class_Cosmogramme_Integration_PhaseTestCase { + public function setUp() { + parent::setUp(); + + $this->_phase = $this->_buildPhase('Reviews') + ->noDbReset() + ->run(); + } +} + + + +class PhaseReviewsBadPreviousPhaseTest extends PhaseReviewsTestCase { + protected function _getPreviousPhase() { + return new Class_Cosmogramme_Integration_Phase(6); + } + + + /** @test */ + public function shouldNotChangePhase() { + $this->assertTrue($this->_phase->isId(6)); + } +} + + + +class PhaseReviewsExpectedPreviousPhaseTest extends PhaseReviewsTestCase { + protected function _getPreviousPhase() { + return (new Class_Cosmogramme_Integration_Phase(7.5)) + ->beCron(); + } + + + protected function _prepareFixtures() { + $this->fixture('Class_AdminVar', + ['id' => 'AVIS_MIN_SAISIE', + 'valeur' => 0]); + $this->fixture('Class_AdminVar', + ['id' => 'AVIS_MAX_SAISIE', + 'valeur' => 1000]); + + $this->millenium = $this->fixture('Class_Notice', ['id' => 816, + 'titre_principal' => 'Millenium', + 'clef_alpha' => 'MILLENIUM', + 'auteur_principal' => 'Stieg Larsson', + 'url_vignette' => '', + 'url_image' => '' + ] + ); + + + $this->avis_millenium = $this->fixture('Class_AvisNotice', ['id' => 13, + 'entete' => "J'adore", + 'avis' => '<div><ul><li>Suspense Intense !</li><li>Suspense Intense !</li></ul></div>', + 'note' => 5, + 'date_avis' => '2011-03-18 13:00:00', + + 'statut' => 0, + 'abon_ou_bib'=>1 , + 'notices' => [] ]); + + + $this + ->onLoaderOfModel('Class_AvisNotice') + ->whenCalled('findAllAfter') + ->answers([$this->avis_millenium]); + } + + + /** @test */ + public function shouldChangePhase() { + $this->assertTrue($this->_phase->isId(7.5)); + } + + + /** @test */ + public function logShouldContainsPhaseLabel() { + $this->assertLogContains('Tous les avis ont été mis à jour'); + } + + + /** @test */ + public function logShouldContainsProcessedRecordCount() { + $this->assertLogContains('1 avis traités'); + } + +/** @test */ + public function noticeMilleniumShouldBeAttached() { + $this->assertEquals(816,Class_AvisNotice::find(13)->getIdNotice()); + } +}