From d6febc20e067bff47db5c9f5b40f5ac06de42832 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Mon, 22 Jan 2018 17:29:31 +0100 Subject: [PATCH] dev #69826 refacto to plugin manager --- .../opac/controllers/AbonneController.php | 95 +--------------- .../BookmarkedSearchesController.php | 33 ++++++ .../opac/views/scripts/abonne/settings.phtml | 12 +- .../scripts/bookmarked-searches/add.phtml | 1 + library/Class/User/BookmarkedSearch.php | 5 + .../ZendAfi/Controller/Plugin/AdminAuth.php | 4 +- .../Plugin/Manager/BookmarkedSearches.php | 104 ++++++++++++++++++ .../Controller/Plugin/Manager/Manager.php | 34 +++++- .../Plugin/ResourceDefinition/Abstract.php | 11 +- .../ResourceDefinition/BookmarkedSearches.php | 42 +++++++ ...ookmarkSearch.php => BookmarkedSearch.php} | 11 +- library/ZendAfi/View/Helper/Search/Header.php | 4 +- tests/scenarios/bookmarks/SearchTest.php | 87 +++++++++++++-- 13 files changed, 321 insertions(+), 122 deletions(-) create mode 100644 application/modules/opac/controllers/BookmarkedSearchesController.php create mode 100644 application/modules/opac/views/scripts/bookmarked-searches/add.phtml create mode 100644 library/ZendAfi/Controller/Plugin/Manager/BookmarkedSearches.php create mode 100644 library/ZendAfi/Controller/Plugin/ResourceDefinition/BookmarkedSearches.php rename library/ZendAfi/Form/User/{BookmarkSearch.php => BookmarkedSearch.php} (77%) diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 56b42552f82..7a30d6aa066 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -1019,7 +1019,8 @@ class AbonneController extends ZendAfi_Controller_Action { public function settingsAction() { $this->view->titre = $this->view->_('Mes favoris'); - $this->view->bookmarked_searches = Class_User_BookmarkedSearch::findAllBy(['id_user' => $this->_user->getId()]); + $this->view->bookmarked_searches = Class_User_BookmarkedSearch::findAllBy(['id_user' => $this->_user->getId(), + 'order' => 'creation_date desc']); $form = ZendAfi_Form_User_Settings::forUser($this->_user); $this->view->form = $form->getElements() ? $form @@ -1223,96 +1224,4 @@ class AbonneController extends ZendAfi_Controller_Action { $this->renderPopupResult($this->_('Compléter votre adresse email'), $this->view->render('abonne/ajax-email.phtml')); } - - - public function bookmarkSearchAction() { - $this->view->titre = $this->_('Enregister la recherche dans mes favoris'); - if (!$this->_user) - return $this->_forward('popup-login', 'auth', 'opac', ['redirect' => $this->view->url()]); - - $this->view->form = $form = new ZendAfi_Form_User_BookmarkSearch(); - $form->setAction(Class_Url::absolute('/abonne/bookmark-search')); - - if( !$this->_request->isPost() || !$form->isValid($this->_request->getPost())) - return; - - $criterias = Class_User_BookmarkedSearch::newInstance(['id_user' => $this->_user->getId(), - 'label' => $this->_getParam('label'), - 'criterias' => $this->_getCriterias()]); - if(!$criterias->save()) { - $this->_helper->_notify($this->_('La recherche n\'a pas été enregistrée dans vos favoris')); - $this->_redirectToReferer(); - } - - $this->_helper->_notify($this->_('Cette recherche a été enregistrée dans vos favoris')); - return $this->_redirectClose($this->_getReferer()); - } - - - protected function _getCriterias() { - if (!$namespace = new Zend_Session_Namespace('historiqueRecherche')) - return null; - - if (!$searches = $namespace->criteres) - return null; - - return array_pop($searches); - } - - - public function deleteBookmarkedSearchAction() { - $this->view->titre = $this->_('Supprimer la recherche de mes favoris'); - - if(!$search = $this->_checkBookmarkedSearchRequest()) - return; - - $search->delete(); - $this->_helper->_notify($this->_('La recherche "%s" a été supprimée.', $search->getLabel())); - return $this->_redirectClose($this->_getReferer()); - } - - - protected function _checkBookmarkedSearchRequest() { - if(!$this->_user) { - $this->_forward('popup-login', 'auth', 'opac', ['redirect' => $this->view->url()]); - return; - } - - if(!$search = Class_User_BookmarkedSearch::find($this->_getParam('id', 0))) { - $this->_helper->_notify($this->_('La recherche demandée est introuvable.')); - $this->_redirectClose($this->_getReferer()); - return; - } - - if(!$search->belongsTo($this->_user)) { - $this->_helper->_notify($this->_('Cette recherche ne vous appartient pas.')); - $this->_redirectClose($this->_getReferer()); - return; - } - - return $search; - - } - - - public function notifyBookmarkedSearchAction() { - if(!$search = $this->_checkBookmarkedSearchRequest()) - return; - - $search->beNotified()->save(); - - $this->_helper->_notify($this->_('Les notifications de nouveautés pour la recherche "%s" sont activées.', $search->getLabel())); - return $this->_redirectClose($this->_getReferer()); - } - - - public function unnotifyBookmarkedSearchAction() { - if(!$search = $this->_checkBookmarkedSearchRequest()) - return; - - $search->beUnnotified()->save(); - - $this->_helper->_notify($this->_('Les notifications de nouveautés pour la recherche "%s" sont désactivées.', $search->getLabel())); - return $this->_redirectClose($this->_getReferer()); - } } \ No newline at end of file diff --git a/application/modules/opac/controllers/BookmarkedSearchesController.php b/application/modules/opac/controllers/BookmarkedSearchesController.php new file mode 100644 index 00000000000..58d1adf7617 --- /dev/null +++ b/application/modules/opac/controllers/BookmarkedSearchesController.php @@ -0,0 +1,33 @@ +<?php +/** + * Copyright (c) 2012-2017, 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 BookmarkedSearchesController extends ZendAfi_Controller_Action { + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_BookmarkedSearches', + 'ZendAfi_Controller_Plugin_Manager_BookmarkedSearches']; + } + + + public function indexAction() { + return $this->_redirectClose($this->_getReferer()); + } +} diff --git a/application/modules/opac/views/scripts/abonne/settings.phtml b/application/modules/opac/views/scripts/abonne/settings.phtml index 36dd06aa81e..2c324adb1ce 100644 --- a/application/modules/opac/views/scripts/abonne/settings.phtml +++ b/application/modules/opac/views/scripts/abonne/settings.phtml @@ -9,7 +9,7 @@ if($this->form) { $description = (new Class_TableDescription('bookmarked_searches')) ->addColumn($this->_('Libellé'), function($model) { return $model->getLabel(); }) ->addColumn($this->_('Critères'), function($model) { return $this->Search_Criterias($model->getUnserializedCriterias()); }) - ->addColumn($this->_('Date création'), function($model) { return $model->getCreationDate(); }) + ->addColumn($this->_('Date de création'), function($model) { return $model->getCreationDate(); }) ->addRowAction(function($model) { return $this->tagPreview(Class_Url::relative($model->getCriteriasUrl()), $this->_('Voir le résultat de la recherche')); @@ -17,17 +17,17 @@ return $this->tagPreview(Class_Url::relative($model->getCriteriasUrl()), }) ->addRowAction(function($model) { - $action = 'notify-bookmarked-search'; + $action = 'notify'; $label = $this->_('Me notifier des nouveautés'); $icon = 'toggle_off'; if($model->isNotified()) { - $action = 'unnotify-bookmarked-search'; + $action = 'unnotify'; $label = $this->_('Annuler la notification des nouveautés'); $icon = 'toggle_on'; } - $params = ['controller' => 'abonne', + $params = ['controller' => 'bookmarked-searches', 'action' => $action, 'id' => $model->getId()]; @@ -40,8 +40,8 @@ return $this->tagPreview(Class_Url::relative($model->getCriteriasUrl()), ->addRowAction(function ($model) { $label = $this->_('Supprimer la recherche "%s"', $model->getLabel()); - return $this->tagAnchor($this->url(['controller' => 'abonne', - 'action' => 'delete-bookmarked-search', + return $this->tagAnchor($this->url(['controller' => 'bookmarked-searches', + 'action' => 'delete', 'id' => $model->getId()],null,true), Class_Admin_Skin::current()->renderActionIconOn('delete', $this, ['title' => $label, diff --git a/application/modules/opac/views/scripts/bookmarked-searches/add.phtml b/application/modules/opac/views/scripts/bookmarked-searches/add.phtml new file mode 100644 index 00000000000..c52ca489f90 --- /dev/null +++ b/application/modules/opac/views/scripts/bookmarked-searches/add.phtml @@ -0,0 +1 @@ +<?php echo $this->renderForm($this->form); ?> diff --git a/library/Class/User/BookmarkedSearch.php b/library/Class/User/BookmarkedSearch.php index 66fe3c0b519..c748a10a709 100644 --- a/library/Class/User/BookmarkedSearch.php +++ b/library/Class/User/BookmarkedSearch.php @@ -77,4 +77,9 @@ class Class_User_BookmarkedSearch extends Storm_Model_Abstract { public function beUnnotified() { return $this->setNotified(0); } + + + public function getLibelle() { + return $this->getLabel(); + } } \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/AdminAuth.php b/library/ZendAfi/Controller/Plugin/AdminAuth.php index fa212269446..871b912c036 100644 --- a/library/ZendAfi/Controller/Plugin/AdminAuth.php +++ b/library/ZendAfi/Controller/Plugin/AdminAuth.php @@ -52,7 +52,9 @@ class ZendAfi_Controller_Plugin_AdminAuth extends Zend_Controller_Plugin_Abstrac $action = 'sitedown'; } - if ((!$user = Class_Users::getIdentity()) && ($controller == "abonne" && $action !== "authenticate")) { + if ((!$user = Class_Users::getIdentity()) + && $action !== "authenticate" + && in_array($controller, ["abonne", 'bookmarked-searches'])) { $request->setParam('redirect', Class_Url::absolute()); $controller = 'auth'; $action = ($request->getParam('render') == 'popup') ? 'popup-login' : 'login'; diff --git a/library/ZendAfi/Controller/Plugin/Manager/BookmarkedSearches.php b/library/ZendAfi/Controller/Plugin/Manager/BookmarkedSearches.php new file mode 100644 index 00000000000..46f3b541e24 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/BookmarkedSearches.php @@ -0,0 +1,104 @@ +<?php +/** + * Copyright (c) 2012-2017, 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_Controller_Plugin_Manager_BookmarkedSearches extends ZendAfi_Controller_Plugin_Manager_Manager { + protected $_user; + + public function init() { + parent::init(); + $this->_user = Class_Users::getIdentity(); + } + + + protected function _getPost() { + $post = parent::_getPost(); + $post['id_user'] = $this->_user->getId(); + $post['criterias'] = $this->_getCriterias(); + + return $post; + } + + + protected function _getCriterias() { + if (!$namespace = new Zend_Session_Namespace('historiqueRecherche')) + return null; + + if (!$searches = $namespace->criteres) + return null; + + return array_pop($searches); + } + + + protected function _checkBookmarkedSearchRequest() { + if(!$search = $this->_findModel()) { + $this->_helper->_notify($this->_('La recherche demandée est introuvable.')); + $this->_redirectClose($this->_getReferer()); + return; + } + + if(!$search->belongsTo($this->_user)) { + $this->_helper->_notify($this->_('Cette recherche ne vous appartient pas.')); + $this->_redirectClose($this->_getReferer()); + return; + } + + return $search; + } + + + protected function _redirectToIndex() { + return $this->_redirectClose($this->_getReferer()); + } + + + protected function _canDelete($model) { + return $model->belongsTo($this->_user); + } + + + public function notifyAction() { + if(!$search = $this->_checkBookmarkedSearchRequest()) + return; + + $search->beNotified()->save(); + + $this->_helper->_notify($this->_('Les notifications de nouveautés pour la recherche "%s" sont activées.', $search->getLabel())); + return $this->_redirectClose($this->_getReferer()); + } + + + public function unnotifyAction() { + if(!$search = $this->_checkBookmarkedSearchRequest()) + return; + + $search->beUnnotified()->save(); + + $this->_helper->_notify($this->_('Les notifications de nouveautés pour la recherche "%s" sont désactivées.', $search->getLabel())); + return $this->_redirectClose($this->_getReferer()); + } + + + public function editAction() { + return $this->_redirectToIndex(); + } +} diff --git a/library/ZendAfi/Controller/Plugin/Manager/Manager.php b/library/ZendAfi/Controller/Plugin/Manager/Manager.php index 87a40a6f4bd..8c0217170fc 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/Manager.php +++ b/library/ZendAfi/Controller/Plugin/Manager/Manager.php @@ -165,18 +165,24 @@ class ZendAfi_Controller_Plugin_Manager_Manager extends ZendAfi_Controller_Plugi } - public function deleteAction() { if ($this->_response->isRedirect()) return; - if ($model = $this->_findModel()) { - $values = $this->_getCustomFieldModelValues($model); - $values->deleteValues(); - $model->delete(); - $this->_helper->notify($this->_getSuccessfulDeleteMessage($model)); + if (!$model = $this->_findModel()) + return $this->_redirectToIndex(); + + if (!$this->_canDelete($model)) { + $this->_helper->notify($this->_view->_('Vous n\'avez pas la permission "%s"', + $this->_getDeleteActionTitle($model))); + return $this->_redirectToIndex(); } + $values = $this->_getCustomFieldModelValues($model); + $values->deleteValues(); + $model->delete(); + $this->_helper->notify($this->_getSuccessfulDeleteMessage($model)); + $this->_redirectToIndex(); $this->_getDoAfterDelete($model); } @@ -190,6 +196,11 @@ class ZendAfi_Controller_Plugin_Manager_Manager extends ZendAfi_Controller_Plugi } + protected function _canDelete($model) { + return true; + } + + protected function _getEditUrl($model) { return ['module' => 'admin', 'action' => 'edit', @@ -442,11 +453,22 @@ class ZendAfi_Controller_Plugin_Manager_Manager extends ZendAfi_Controller_Plugi } + public function visitDeleteActionTitle($callback) { + $this->_delete_action_title = $callback; + return $this; + } + + protected function _getEditActionTitle($model) { return call_user_func($this->_edit_action_title, $model); } + protected function _getDeleteActionTitle($model) { + return call_user_func($this->_delete_action_title, $model); + } + + public function visitSuccessfulSaveMessage($callback) { $this->_successful_save_message = $callback; return $this; diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php index 7da0526457c..21ba349cfa4 100644 --- a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php @@ -146,7 +146,12 @@ abstract class ZendAfi_Controller_Plugin_ResourceDefinition_Abstract extends Zen public function editActionTitle($model) { - return sprintf($this->titleForAction('edit'),$model->getLibelle()); + return sprintf($this->titleForAction('edit'), $model->getLibelle()); + } + + + public function deleteActionTitle($model) { + return sprintf($this->titleForAction('delete'), $model->getLibelle()); } @@ -307,6 +312,10 @@ abstract class ZendAfi_Controller_Plugin_ResourceDefinition_Abstract extends Zen { return $this->editActionTitle($model); }) + ->visitDeleteActionTitle(function($model) + { + return $this->deleteActionTitle($model); + }) ->visitSuccessfulSaveMessage(function($model) { return $this->successfulSaveMessage($model); diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/BookmarkedSearches.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/BookmarkedSearches.php new file mode 100644 index 00000000000..9e7ac17e405 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/BookmarkedSearches.php @@ -0,0 +1,42 @@ +<?php +/** + * Copyright (c) 2012-2017, 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_Controller_Plugin_ResourceDefinition_BookmarkedSearches + extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + public function getDefinitions() { + return [ + 'model' => ['class' => 'Class_User_BookmarkedSearch', + 'name' => 'search', + 'order' => 'label'], + + 'messages' => ['successful_save' => $this->_('La recherche "%s" a été enregistrée dans mes favoris'), + 'successful_add' => $this->_('La recherche "%s" a été enregistrée dans mes favoris'), + 'successful_delete' => $this->_('La recherche "%s" a été supprimée de mes favoris')], + + 'actions' => ['add' => ['title' => $this->_('Enregister la recherche dans mes favoris')], + 'edit' => ['title' => $this->_('Enregister la recherche dans mes favoris')], + 'delete' => ['title' => $this->_('Supprimer la recherche de mes favoris')]], + + 'form_class_name' => 'ZendAfi_Form_User_BookmarkedSearch', + ]; + } +} diff --git a/library/ZendAfi/Form/User/BookmarkSearch.php b/library/ZendAfi/Form/User/BookmarkedSearch.php similarity index 77% rename from library/ZendAfi/Form/User/BookmarkSearch.php rename to library/ZendAfi/Form/User/BookmarkedSearch.php index b3b7e4dc555..14e6c7983c2 100644 --- a/library/ZendAfi/Form/User/BookmarkSearch.php +++ b/library/ZendAfi/Form/User/BookmarkedSearch.php @@ -20,7 +20,7 @@ */ -class ZendAfi_Form_User_BookmarkSearch extends ZendAfi_Form { +class ZendAfi_Form_User_BookmarkedSearch extends ZendAfi_Form { public function init() { parent::init(); $this @@ -31,7 +31,14 @@ class ZendAfi_Form_User_BookmarkSearch extends ZendAfi_Form { 'allowEmpty' => false, 'placeholder' => $this->_('Titre de votre recherche')]) - ->addDisplayGroup(['label'], + ->addElement('checkbox', + 'notified', + ['label' => $this->_('Me notifier des nouveautés par email'), + 'required' => true, + 'allowEmpty' => false]) + + ->addDisplayGroup(['label', + 'notified'], 'group_bookmark_search'); } } \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Search/Header.php b/library/ZendAfi/View/Helper/Search/Header.php index 26925520167..3a32792a47e 100644 --- a/library/ZendAfi/View/Helper/Search/Header.php +++ b/library/ZendAfi/View/Helper/Search/Header.php @@ -144,8 +144,8 @@ class ZendAfi_View_Helper_Search_Header extends ZendAfi_View_Helper_BaseHelper { return ''; return $this->_tag('span', - $this->view->tagAnchor($this->view->url(['controller' => 'abonne', - 'action' => 'bookmark-search'], null, true), + $this->view->tagAnchor($this->view->url(['controller' => 'bookmarked-searches', + 'action' => 'add'], null, true), $this->_('Enregistrer ma recherche'), ['title' => $this->_('Enregistrer ma recherche dans mes favoris'), 'data-popup' => true]), diff --git a/tests/scenarios/bookmarks/SearchTest.php b/tests/scenarios/bookmarks/SearchTest.php index e8e11de15c9..6a20001e4c6 100644 --- a/tests/scenarios/bookmarks/SearchTest.php +++ b/tests/scenarios/bookmarks/SearchTest.php @@ -36,7 +36,7 @@ class Bookmarks_SearchLinkTest extends AbstractControllerTestCase { /** @test */ public function linkToBookmarkSearchShouldBePresent() { - $this->assertXPathContentContains('//a[contains(@href, "/abonne/bookmark-search")]', 'Enregistrer ma recherche'); + $this->assertXPathContentContains('//a[contains(@href, "/bookmarked-searches/add")]', 'Enregistrer ma recherche'); } } @@ -77,7 +77,7 @@ class Bookmarks_SearchAbonneBookmarkSearchDispatchTest extends Bookmarks_Search 'criterias' => '', 'creation_date' => '2018-01-17 15:05:57']); - $this->dispatch('/abonne/bookmark-search', true); + $this->dispatch('/bookmarked-searches/add', true); } @@ -85,6 +85,12 @@ class Bookmarks_SearchAbonneBookmarkSearchDispatchTest extends Bookmarks_Search public function formShouldContainsLabel() { $this->assertXPath('//form//input[@type="text"][@name="label"]'); } + + + /** @test */ + public function formShouldContainsNotified() { + $this->assertXPath('//form//input[@type="checkbox"][@name="notified"]'); + } } @@ -93,7 +99,8 @@ class Bookmarks_SearchAbonneBookmarkSearchPostTest extends Bookmarks_SearchWith public function setUp() { parent::setUp(); Class_User_BookmarkedSearch::setTimeSource(new TimeSourceForTest('2018-01-17 01:01:01')); - $this->postDispatch('/abonne/bookmark-search', ['label' => 'search']); + $this->postDispatch('/bookmarked-searches/add', ['label' => 'search', + 'notified' => '1']); } @@ -119,6 +126,12 @@ class Bookmarks_SearchAbonneBookmarkSearchPostTest extends Bookmarks_SearchWith public function davisSearchShouldBeBookmarkedInUserSettings() { $this->assertEquals('Miles Davis', Class_User_BookmarkedSearch::find(1)->getUnserializedCriterias()->getParam('rech_auteurs')); } + + + /** @test */ + public function bookmarkedSearchShouldBeNotified() { + $this->assertTrue(Class_User_BookmarkedSearch::find(1)->isNotified()); + } } @@ -132,7 +145,7 @@ class Bookmarks_SearchAbonneNotLoggedTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); ZendAfi_Auth::getInstance()->clearIdentity(); - $this->dispatch('/abonne/bookmark-search', true); + $this->dispatch('/bookmarked-searches/add', true); } @@ -207,7 +220,7 @@ class Bookmarks_SearchAbonneSettingsTest extends Bookmarks_SearchWithSessionAbst /** @test */ public function tableShouldContainsDeleteButton() { - $this->assertXPath('//td//a[contains(@onclick, "return confirm")][contains(@href,"/abonne/delete-bookmarked-search/id/5")]'); + $this->assertXPath('//td//a[contains(@onclick, "return confirm")][contains(@href,"/bookmarked-searches/delete/id/5")]'); } @@ -225,13 +238,13 @@ class Bookmarks_SearchAbonneSettingsTest extends Bookmarks_SearchWithSessionAbst /** @test */ public function tableShoulContainsLinkEnableMailNotification() { - $this->assertXPath('//td//a[contains(@href, "/abonne/notify-bookmarked-search/id/5")]'); + $this->assertXPath('//td//a[contains(@href, "/bookmarked-searches/notify/id/5")]'); } /** @test */ public function tableShoulContainsLinkUnableMailNotification() { - $this->assertXPath('//td//a[contains(@href, "/abonne/unnotify-bookmarked-search/id/8")]'); + $this->assertXPath('//td//a[contains(@href, "/bookmarked-searches/unnotify/id/8")]'); } } @@ -251,7 +264,7 @@ class Bookmarks_SearchDeleteBookmarkedSearchTest extends Bookmarks_SearchWithSes 'criterias' => '', 'creation_date' => '2018-01-17 15:05:57']); - $this->dispatch('/abonne/delete-bookmarked-search/id/5', true); + $this->dispatch('/bookmarked-searches/delete/id/5', true); } @@ -263,7 +276,13 @@ class Bookmarks_SearchDeleteBookmarkedSearchTest extends Bookmarks_SearchWithSes /** @test */ public function notifyMessageShouldBeRechercheSupprimee() { - $this->assertFlashMessengerContentContains('La recherche "Miles Davis" a été supprimée.'); + $this->assertFlashMessengerContentContains('La recherche "Miles Davis" a été supprimée de mes favoris'); + } + + + /** @test */ + public function shouldRedirectToReferer() { + $this->assertRedirectTo('/'); } } @@ -282,7 +301,7 @@ class Bookmarks_SearchNotifyBookmarkedSearchTest extends Bookmarks_SearchWithSes 'criterias' => '', 'creation_date' => '2018-01-17 15:05:57']); - $this->dispatch('/abonne/notify-bookmarked-search/id/5', true); + $this->dispatch('/bookmarked-searches/notify/id/5', true); } @@ -308,7 +327,7 @@ class Bookmarks_SearchUnnotifyBookmarkedSearchTest extends Bookmarks_SearchWithS 'criterias' => '', 'creation_date' => '2018-01-17 15:05:57']); - $this->dispatch('/abonne/unnotify-bookmarked-search/id/5', true); + $this->dispatch('/bookmarked-searches/unnotify/id/5', true); } @@ -316,4 +335,50 @@ class Bookmarks_SearchUnnotifyBookmarkedSearchTest extends Bookmarks_SearchWithS public function searchMilesDavisShouldBeMarkAsUnNotified() { $this->assertFalse(Class_User_BookmarkedSearch::find(5)->isNotified()); } +} + + + + +class Bookmarks_SearchAuthorizedActionTest extends Bookmarks_SearchWithSessionAbstract { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + $this->fixture('Class_User_BookmarkedSearch', + ['id' => 5, + 'id_user' => $this->_user->getId(), + 'label' => 'Miles Davis', + 'notified' => 1, + 'criterias' => '', + 'creation_date' => '2018-01-17 15:05:57']); + ZendAfi_Auth::getInstance()->logUser($this->fixture('Class_Users', + ['id' => 78, + 'login' => 'me', + 'password' => 'you'])); + } + + + /** @test */ + public function dispatchEditActionShouldRedirectToReferer() { + $this->dispatch('/opac/bookmarked-searches/edit/id/5', true); + $this->assertRedirectTo('/'); + } + + + /** @test */ + public function dispatchIndexActionShouldRedirectToReferer() { + $this->dispatch('/opac/bookmarked-searches/index', true); + $this->assertRedirectTo('/'); + } + + + /** @test */ + public function dispatchDeleteActionShouldRedirectToReferer() { + $this->dispatch('/opac/bookmarked-searches/delete/id/5', true); + $this->assertRedirectTo('/'); + $this->assertNotNull(Class_User_BookmarkedSearch::find(5)); + $this->assertFlashMessengerContentContains('Vous n\'avez pas la permission'); + } } \ No newline at end of file -- GitLab