diff --git a/application/modules/admin/controllers/ModoController.php b/application/modules/admin/controllers/ModoController.php index cf619e40354d692ff6b63440df11bb36ff34a03c..d1800e04513d64cfc52a0cb9747f24ba21093d09 100644 --- a/application/modules/admin/controllers/ModoController.php +++ b/application/modules/admin/controllers/ModoController.php @@ -18,6 +18,8 @@ * along with BOKEH; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + + class Admin_ModoController extends ZendAfi_Controller_Action { private $_count = 10; @@ -291,89 +293,6 @@ class Admin_ModoController extends ZendAfi_Controller_Action { } - public function membreviewAction() { - $this->view->titre = $this->_('Demandes d\'inscription'); - $this->view->registrations = Class_UsersNonValid::findAllByLoggedUser(); - } - - - public function rejectRegistrationAction() { - $registration = Class_UsersNonValid::find($this->_getParam('id')); - - if ($registration->hasUser()) { - $registration->getUser()->delete(); - $this->_helper->notify($this->_('Le compte "%s" a été supprimé', - $registration->getLogin())); - } - - $registration->delete(); - $this->_helper->notify($this->_('La demande d\'inscription pour "%s" a été supprimée', - $registration->getLogin())); - - $this->_redirect('admin/modo/membreview'); - } - - - public function deleteRegistrationAction() { - $this->_redirect('admin/modo/membreview'); - - if ((!$id = $this->_getParam('id', null)) - || (!$registration = Class_UsersNonValid::find($id))) { - return $this->_helper->notify($this->_('Aucune inscription supprimée')); - } - - $registration->delete(); - $this->_helper->notify($this->_('Inscription de "%s" supprimée', $registration->getLogin())); - } - - - public function validateRegistrationAction() { - if(!$id = $this->_getParam('id', null)) { - $this->_helper->notify($this->_('Aucune inscription validée')); - return $this->_redirect('admin/modo/membreview'); - } - - if(!$registration = Class_UsersNonValid::find($id)) { - $this->_helper->notify($this->_('Aucune inscription validée')); - return $this->_redirect('admin/modo/membreview'); - } - - if($registration->activate()) { - $this->_helper->notify($this->_('Inscription de "%s" validée', $registration->getLogin())); - return $this->_redirect('admin/modo/membreview'); - } - - $this->_helper->notify($this->_('Impossible de valider l\'inscription de "%s"', $registration->getLogin())); - return $this->_redirect('admin/modo/membreview'); - } - - - public function deleteExpiredRegistrationsAction() { - foreach(Class_UsersNonValid::findAll() as $user) - if($user->isExpired()) - $user->delete(); - - return $this->_redirect('admin/modo/membreview'); - } - - - public function updatemembreAction() { - $class_modo = new Class_Moderer(); - $items = $this->_getParam('user', []); - if (0 == count($items)) { - $this->_redirect('admin/modo/tagnotice'); - return; - } - - foreach ($items as $item) { - $elems = explode('_', $item); - $class_modo->modererUserNonValid($elems[0], $elems[1]); - } - - $this->_redirect('admin/modo/membreview'); - } - - public function suggestionAchatAction() { $this->view->subview = $this->view->partial('modo/suggestion-achat.phtml', ['suggestions' => Class_SuggestionAchat::findAllBy(['order' => 'date_creation'])]); @@ -913,16 +832,4 @@ class Admin_ModoController extends ZendAfi_Controller_Action { } return $avis; } - - - protected function _buildAvisForm($avis, $back_url='') { - - - return $form; - } - - - } - -?> \ No newline at end of file diff --git a/application/modules/admin/controllers/RegistrationController.php b/application/modules/admin/controllers/RegistrationController.php new file mode 100644 index 0000000000000000000000000000000000000000..23b4f40a1cb66e29281838517cd1bbe418a19443 --- /dev/null +++ b/application/modules/admin/controllers/RegistrationController.php @@ -0,0 +1,83 @@ +<?php +/** + * Copyright (c) 2012, 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 Admin_RegistrationController extends ZendAfi_Controller_Action { + public function indexAction() { + $this->view->titre = $this->_('Demandes d\'inscription'); + $this->view->registrations = Class_UsersNonValid::findAllByLoggedUser(); + } + + + public function rejectAction() { + $registration = Class_UsersNonValid::find($this->_getParam('id')); + + if ($registration->hasUser()) { + $registration->getUser()->delete(); + $this->_helper->notify($this->_('Le compte "%s" a été supprimé', + $registration->getLogin())); + } + + $registration->delete(); + $this->_helper->notify($this->_('La demande d\'inscription pour "%s" a été supprimée', + $registration->getLogin())); + + $this->_redirectToIndex(); + } + + + public function deleteAction() { + $this->_redirectToIndex(); + + if ((!$id = $this->_getParam('id', null)) + || (!$registration = Class_UsersNonValid::find($id))) { + return $this->_helper->notify($this->_('Aucune demande d\'inscription supprimée')); + } + + $registration->delete(); + $this->_helper->notify($this->_('Demande d\'inscription de "%s" supprimée', $registration->getLogin())); + } + + + public function validateAction() { + $this->_redirectToIndex(); + + if ((!$id = $this->_getParam('id', null)) + || (!$registration = Class_UsersNonValid::find($id))) + return $this->_helper->notify($this->_('Aucune inscription validée')); + + $message = $registration->activate() + ? $this->_('Inscription de "%s" validée', $registration->getLogin()) + : $this->_('Impossible de valider l\'inscription de "%s"', $registration->getLogin()); + + $this->_helper->notify($message); + } + + + public function deleteExpiredAction() { + foreach(Class_UsersNonValid::findAllByLoggedUser() as $user) + if ($user->isExpired()) + $user->delete(); + + $this->_helper->notify($this->_('Demandes expirées supprimées')); + $this->_redirectToIndex(); + } +} diff --git a/application/modules/admin/views/scripts/modo/membreview.phtml b/application/modules/admin/views/scripts/modo/membreview.phtml deleted file mode 100644 index f0edec8ea37f8fcf85e27e6599daf490a2bb768e..0000000000000000000000000000000000000000 --- a/application/modules/admin/views/scripts/modo/membreview.phtml +++ /dev/null @@ -1,55 +0,0 @@ -<?php -if(empty($this->registrations)) { - echo $this->tag('p', $this->_('Aucune demande d\'inscription')); - return; -} - -$description = (new Class_TableDescription('registration')) - ->addColumn($this->_('Identifiant'), 'login') - ->addColumn($this->_('Email'), function($registration) {return $registration->getMail();}) - ->addColumn($this->_('Bibliothèque'), function($registration) {return $registration->getBibLibelle();}) - ->addColumn($this->_('Date'), function($registration) {return $registration->getDate();}) - ->addColumn($this->_('Expirée'), function($registration) {return $registration->isExpired() ? $this->_('Oui') : $this->_('Non');}) - ->addRowAction( - function($model) - { - return $this->renderModelActions($model, - [['url' => ['action' => 'reject-registration', - 'id' => $model->getId()], - 'icon' => 'delete', - 'label' => $this->_('Rejeter la demande d\'inscription de "%s"', $model->getLogin()), - 'anchorOptions' => ['onclick' => sprintf('return confirm(\'%s\')', - $this->_('Etes-vous sûr de vouloir rejeter cette inscription ?')) ]], - - - ['url' => ['action' => 'validate-registration', - 'id' => $model->getId()], - 'icon' => 'add_user', - 'condition' => function($model) {return !$model->hasUser();}, - 'label' => $this->_('Valider la demande d\'inscription de "%s"', $model->getLogin())], - - - ['url' => ['controller' => 'users', - 'action' => 'edit', - 'id' => $model->getBibUserId()], - 'icon' => 'user', - 'condition' => 'hasUser', - 'label' => $this->_('Visualiser les informations du compte "%s"', $model->getLogin())], - - - ['url' => ['action' => 'delete-registration', - 'id' => $model->getId()], - 'icon' => 'validate', - 'condition' => 'hasUser', - 'label' => $this->_('Confirmer l\'inscription de "%s"', $model->getLogin())], - - - ]); - }); - -echo $this->renderTable($description, $this->registrations); - -echo $this->button( - (new Class_Entity())->setText($this->_('Supprimer les demandes expirées')) - ->setUrl($this->url(['action' => 'delete-expired-registrations'])) - ->setImage($this->tagImg(Class_Admin_Skin::current()->getIconUrl('buttons', 'delete')))); diff --git a/application/modules/admin/views/scripts/registration/index.phtml b/application/modules/admin/views/scripts/registration/index.phtml new file mode 100644 index 0000000000000000000000000000000000000000..9050944759cc23420d256b4361cb90e19d85daae --- /dev/null +++ b/application/modules/admin/views/scripts/registration/index.phtml @@ -0,0 +1,60 @@ +<?php +if (empty($this->registrations)) { + echo $this->tag('p', $this->_('Aucune demande d\'inscription')); + return; +} + +$has_one_expired = false; + +$description = (new Class_TableDescription('registration')) + ->addColumn($this->_('Identifiant'), 'login') + ->addColumn($this->_('Email'), 'mail') + ->addColumn($this->_('Bibliothèque'), 'bib_libelle') + ->addColumn($this->_('Date'), 'date') + ->addColumn($this->_('Expirée'), function($model) use(&$has_one_expired) + { + $has_one_expired = $has_one_expired || $model->isExpired(); + return $model->isExpired() ? $this->_('Oui') : $this->_('Non'); + }) + ->addRowAction( + function($model) + { + return $this->renderModelActions($model, + [['url' => ['action' => 'reject', + 'id' => $model->getId()], + 'icon' => 'delete', + 'label' => $this->_('Rejeter la demande d\'inscription de "%s"', $model->getLogin()), + 'anchorOptions' => ['onclick' => sprintf('return confirm(\'%s\')', + $this->_('Etes-vous sûr de vouloir rejeter cette inscription ?')) ]], + + + ['url' => ['action' => 'validate', + 'id' => $model->getId()], + 'icon' => 'add_user', + 'condition' => function($model) {return !$model->hasUser();}, + 'label' => $this->_('Valider la demande d\'inscription de "%s"', $model->getLogin())], + + + ['url' => ['controller' => 'users', + 'action' => 'edit', + 'id' => $model->getBibUserId()], + 'icon' => 'user', + 'condition' => 'hasUser', + 'label' => $this->_('Visualiser les informations du compte "%s"', $model->getLogin())], + + + ['url' => ['action' => 'delete', + 'id' => $model->getId()], + 'icon' => 'validate', + 'condition' => 'hasUser', + 'label' => $this->_('Confirmer l\'inscription de "%s"', $model->getLogin())], + ]); + }); + +echo $this->renderTable($description, $this->registrations); + +if ($has_one_expired) + echo $this->button( + (new Class_Entity())->setText($this->_('Supprimer les demandes expirées')) + ->setUrl($this->url(['action' => 'delete-expired'])) + ->setImage($this->tagImg(Class_Admin_Skin::current()->getIconUrl('buttons', 'delete')))); diff --git a/library/Class/Moderer.php b/library/Class/Moderer.php index e96cdb39bcbfb16e04546a5f8478e593ce0bb08c..ef8fd8e5d895e3689a43d3dfbd00215efcfb6c60 100644 --- a/library/Class/Moderer.php +++ b/library/Class/Moderer.php @@ -33,12 +33,6 @@ class Class_Moderer { } - public function modererUserNonValid($action, $id_user) { - if ('2' == $action) - sqlExecute('delete from bib_admin_users_non_valid where ID_USER=' . $id_user); - } - - public function getAllTagsAModerer() { $tags = []; foreach (Class_CodifTags::findAllBy(['where' => 'a_moderer > \'\'']) as $tag) diff --git a/library/Class/TableDescription.php b/library/Class/TableDescription.php index 2711238ae546c32c74d4b354273ec49f828b1151..a760d950495a60f56fef733a4c99d51f3159fd3d 100644 --- a/library/Class/TableDescription.php +++ b/library/Class/TableDescription.php @@ -123,6 +123,9 @@ class Class_TableDescription { if (is_callable($description)) $description = ['callback' => $description]; + if ($description instanceof Closure) + $description = ['callback' => $description]; + if (is_string($description)) $description = ['attribute' => $description]; diff --git a/library/Class/User/ILSSubscription.php b/library/Class/User/ILSSubscription.php index 4f89e69a8409554cb166b65982b21b3ad8809647..a69b868328dbe0929ee8e3f9d4bcdbdd765d3914 100644 --- a/library/Class/User/ILSSubscription.php +++ b/library/Class/User/ILSSubscription.php @@ -67,6 +67,16 @@ class Class_User_ILSSubscription { } + public function beValidUntilNextYear() { + $this->_user->beAbonneSIGB(); + + $date = new DateTime($this->getTimeSource()->dateYmd()); + $date->modify('+1 year'); + + return $this->_user->setDateFin($date->format('Y-m-d')); + } + + public function registerNotificationsOn($notifiable) { if(($user = Class_Users::getIdentity()) && $this->_user->getId() == $user->getId()) return $this->registerNotificationsForMeOn($notifiable); diff --git a/library/Class/Users.php b/library/Class/Users.php index 20d1d01ddcef109cbda26254877aeed4546eae5c..398a8b7ff2c1fa68f020e115e04d4e8595204e63 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -712,6 +712,16 @@ class Class_Users extends Storm_Model_Abstract { } + /** + * @return object + */ + public function beAbonneSIGBUntilNextYear() { + (new Class_User_ILSSubscription($this)) + ->beValidUntilNextYear(); + return $this; + } + + /** * Retourne la Date au format YYYY/MM/DD * @return string @@ -741,7 +751,7 @@ class Class_Users extends Storm_Model_Abstract { /** * @return string */ - public function getToday(){ + public function getToday() { if ($today=$this->today) return $today; return date('Y/m/d'); diff --git a/library/Class/UsersNonValid.php b/library/Class/UsersNonValid.php index 0cebc9ce924fd7f85d2dd9b430306abcc0ef2fa4..e7afd42dcce7da4eb861e014953e4964941d3fc9 100644 --- a/library/Class/UsersNonValid.php +++ b/library/Class/UsersNonValid.php @@ -133,7 +133,7 @@ class Class_UsersNonValid extends Storm_Model_Abstract { if (($bib = $this->getBib()) && $bib->shouldEscalateRegistrationRole()){ $this->_user - ->beAbonneSIGB() + ->beAbonneSIGBUntilNextYear() ->save(); } } diff --git a/library/ZendAfi/Acl/AdminControllerRoles.php b/library/ZendAfi/Acl/AdminControllerRoles.php index 81b8e75e205b6f5c2fcdb2df7505c161667f847f..cec80af3f2bae4e35348dd6c3e45461788d9aabe 100644 --- a/library/ZendAfi/Acl/AdminControllerRoles.php +++ b/library/ZendAfi/Acl/AdminControllerRoles.php @@ -55,6 +55,7 @@ class ZendAfi_Acl_AdminControllerRoles extends Zend_Acl { $this->add(new Zend_Acl_Resource('data')); $this->add(new Zend_Acl_Resource('error')); $this->add(new Zend_Acl_Resource('modo')); + $this->add(new Zend_Acl_Resource('registration')); $this->add(new Zend_Acl_Resource('nouveaute')); $this->add(new Zend_Acl_Resource('panier')); $this->add(new Zend_Acl_Resource('rss')); @@ -161,6 +162,7 @@ class ZendAfi_Acl_AdminControllerRoles extends Zend_Acl { $this->allow('admin_bib','album'); $this->allow('admin_bib','oai'); $this->allow('admin_bib','frbr-link'); + $this->allow('admin_bib','registration'); $this->allow('admin_bib','users'); $this->allow('admin_bib','bib'); $this->allow('admin_bib','print'); @@ -189,6 +191,7 @@ class ZendAfi_Acl_AdminControllerRoles extends Zend_Acl { $this->deny('modo_portail','print'); $this->deny('modo_portail','zone'); $this->deny('modo_portail','bib'); + $this->deny('modo_portail','registration'); $this->deny('modo_portail','users'); $this->deny('modo_portail','usergroup'); $this->deny('modo_portail','systeme'); diff --git a/library/ZendAfi/View/Helper/Admin/ContentNav.php b/library/ZendAfi/View/Helper/Admin/ContentNav.php index ea1d6c10e3c6788606ade9e57f42bb3ecc51552b..d01682438739dd5daad42ad7e4f83cb35dc3cf43 100644 --- a/library/ZendAfi/View/Helper/Admin/ContentNav.php +++ b/library/ZendAfi/View/Helper/Admin/ContentNav.php @@ -63,7 +63,7 @@ class ZendAfi_View_Helper_Admin_ContentNav extends ZendAfi_View_Helper_BaseHelpe ['agendas', $this->_('Agendas externes'), '/admin/external-agendas'], ['moderation', $this->_('Modération'), '/admin/modo', ['extra_infos' => $nb_moderations]], - ['subscription_requests', $this->_("Demandes d'inscription"), '/admin/modo/membreview', + ['users', $this->_("Demandes d'inscription"), '/admin/registration', ['extra_infos' => $demandes_inscription]], ['newsletters', $this->_("Lettres d'information"), '/admin/newsletter'], ['trainings', $this->_('Activités'), '/admin/activity'], diff --git a/tests/application/modules/admin/controllers/AdminAuthControllerTest.php b/tests/application/modules/admin/controllers/AdminAuthControllerTest.php index d3e4bdf6799e0799d4f9c43c8c62b76efd35cdf8..c3b925a2fcaf03bc34513a4a2d26c5ed2ded94cd 100644 --- a/tests/application/modules/admin/controllers/AdminAuthControllerTest.php +++ b/tests/application/modules/admin/controllers/AdminAuthControllerTest.php @@ -241,43 +241,6 @@ class AdminAuthControllerCatalogueAuthorizedByGroupTest extends Admin_AbstractCo -class AdminAuthControllerModoMembreviewAuthorizedByGroupTest extends Admin_AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; - - public function setUp() { - parent::setUp(); - - $group = $this->fixture('Class_UserGroup', ['id' => 74]) - ->addRight(Class_UserGroup::RIGHT_USER_INSCRIPTIONS); - - Class_Users::getIdentity() - ->setRoleLevel(ZendAfi_Acl_AdminControllerRoles::MODO_BIB) - ->addUserGroup($group); - - $this->dispatch('/admin/modo/membreview', true); - } - - - /** @test */ - public function shouldNotRedirect() { - $this->assertNotRedirect(); - } - - - /** @test */ - public function controllerShouldBeAlbum() { - $this->assertEquals('modo', $this->_request->getControllerName()); - } - - - /** @test */ - public function actionShouldBeMembreview() { - $this->assertEquals('membreview', $this->_request->getActionName()); - } -} - - - class AdminAuthControllerModoForbiddenByGroupTest extends Admin_AbstractControllerTestCase { protected $_storm_default_to_volatile = true; diff --git a/tests/application/modules/admin/controllers/ModoControllerTest.php b/tests/application/modules/admin/controllers/ModoControllerTest.php index 0ef32bd1384dbb0c15054bc2888f03844852af8f..91df915f932228b6fcfa8af3afa2cfa65ea3dc70 100644 --- a/tests/application/modules/admin/controllers/ModoControllerTest.php +++ b/tests/application/modules/admin/controllers/ModoControllerTest.php @@ -134,13 +134,13 @@ class ModoControllerIndexActionTest extends ModoControllerIndexActionTestCase { /** @test */ public function linkToModerateMembershipShouldBePresent() { - $this->assertXPath('//a[contains(@href, "/modo/membreview")]'); + $this->assertXPath('//a[contains(@href, "/registration")]'); } /** @test */ public function numberOfModerateMembreshipShouldBeTwo() { - $this->assertXPathContentContains('//span[@class="menu_info"][preceding::a[contains(@href, "/modo/membreview")]]', '2'); + $this->assertXPathContentContains('//span[@class="menu_info"][preceding::a[contains(@href, "/registration")]]', '2'); } @@ -877,388 +877,4 @@ class ModoControllerArchivedReviewsActionTest extends ModoControllerIndexActionT $this->dispatch('admin/modo/visibleavisnotice/id/223', true); $this->assertEquals(0,Class_AvisNotice::find(223)->getFlags()); } -} - - - - -abstract class ModoControllerRegistrationsTestCase extends Admin_AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; - - - public function setUp() { - parent::setUp(); - $this->fixture('Class_UsersNonValid', - ['id' => 1, - 'login' => 'pwd', - 'password' => 'pwd', - 'date' => '2018-16-01', - 'mail' => 'pwd@afi-sa.fr']); - - $this->fixture('Class_UsersNonValid', - ['id' => 2, - 'login' => 'chewe', - 'password' => 'ehhhhhh', - 'bib'=> $this->fixture('Class_Bib', - ['id' => 3, - 'libelle' => 'Tatoine']), - 'date' => '2019-16-01', - 'mail' => 'chewe@afi-sa.fr'])->activate();; - } -} - - - - -class ModoControllerMembreviewAsAdminTatoineTest extends ModoControllerRegistrationsTestCase { - public function setUp() { - parent::setUp(); - - Class_Users::getIdentity() - ->beAdminBib() - ->setPassword('secret') - ->setBib(Class_Bib::find(3)) - ->assertSave(); - - $this->dispatch('/admin/modo/membreview', true); - } - - - /** @test */ - public function pageShouldNotContainsRegistrationPwd() { - $this->assertNotXPathContentContains('//td', 'pwd'); - } - - - /** @test */ - public function pageShouldContainsRegistrationChewe() { - $this->assertXPathContentContains('//td', 'chewe'); - } - - - /** @test */ - public function leftMenuRegistrationCountShouldBeOne() { - $this->assertXPath('//ul[@class="menuAdmin"]//a[contains(@href, "/modo/membreview")][following-sibling::span[@class="menu_info"][text()="1"]]'); - } -} - - - - -class ModoControllerMembreviewDispatchTest extends ModoControllerRegistrationsTestCase { - public function setUp() { - parent::setUp(); - $this->dispatch('/admin/modo/membreview', true); - } - - - /** @test */ - public function loginPwdShouldBeDisplay() { - $this->assertXPathContentContains('//td', 'pwd'); - } - - - /** @test */ - public function libraryNameShouldBeDisplay() { - $this->assertXPathContentContains('//td', 'Tatoine'); - } - - - /** @test */ - public function pageShouldContainsRejectRegistrationLinkForPwd() { - $this->assertXPath('//a[contains(@href, "admin/modo/reject-registration/id/1")]'); - } - - - /** @test */ - public function pageShouldContainsRejectRegistrationLinkForChewee() { - $this->assertXPath('//a[contains(@href, "admin/modo/reject-registration/id/2")]'); - } - - - /** @test */ - public function pageShouldNotContainsDeleteRegistrationLinkForPwd() { - $this->assertNotXPath('//a[contains(@href, "admin/modo/delete-registration/id/1")]'); - } - - - /** @test */ - public function pageShouldContainsDeleteRegistrationLinkForChewee() { - $this->assertXPath('//a[contains(@href, "admin/modo/reject-registration/id/2")]'); - } - - - /** @test */ - public function pageShouldContainsLinkToValidateRegistrationForInexistingUserPwd() { - $this->assertXPath('//tbody/tr[1]//a[contains(@href, "admin/modo/validate-registration/id/")]'); - } - - - /** @test */ - public function pageShouldNotContainsLinkToValidateRegistrationForUserChewe() { - $this->assertNotXPath('//tbody/tr[2]//a[contains(@href, "admin/modo/validate-registration/id/")]'); - } - - - /** @test */ - public function pageShouldNotContainsLinkToEditInexistingUserPwd() { - $this->assertNotXPath('//tbody/tr[1]//a[contains(@href, "admin/users/edit/id/")]'); - } - - - /** @test */ - public function pageShouldContainsLinkToEditUserChewe() { - $this->assertXPath(sprintf('//a[contains(@href, "admin/users/edit/id/%d")]', - Class_UsersNonValid::find(2)->getUser()->getId())); - } - - - /** @test */ - public function pageShouldBeHTML5Valid() { - $this->assertHTML5(); - } -} - - - - -class ModoControllerMembreViewRejectCheweeRegistrationTest extends ModoControllerRegistrationsTestCase { - public function setUp() { - parent::setUp(); - $this->dispatch('/admin/modo/reject-registration/id/2', true); - } - - - /** @test */ - public function cheweeRegistrationShouldHaveBeenDeleted() { - $this->assertNull(Class_UsersNonValid::find(2)); - } - - - /** @test */ - public function userCheweeShouldHaveBeenDeleted() { - $this->assertNull(Class_Users::findFirstBy(['login' => 'chewe'])); - } - - - /** @test */ - public function responseShouldRedirectToModoMembreView() { - $this->assertRedirectTo('/admin/modo/membreview'); - } - - - /** @test */ - public function responseShouldNotifyRegistrationHasBeenDeleted() { - $this->assertFlashMessengerContentContains('La demande d\'inscription pour "chewe" a été supprimée'); - } - - - /** @test */ - public function responseShouldNotifyCheweeHasBeenDeleted() { - $this->assertFlashMessengerContentContains('Le compte "chewe" a été supprimé'); - } -} - - - - -class ModoControllerMembreViewRejectPwdRegistrationTest extends ModoControllerRegistrationsTestCase { - public function setUp() { - parent::setUp(); - $this->dispatch('/admin/modo/reject-registration/id/1', true); - } - - - /** @test */ - public function registrationPwdShouldHaveBeenDeleted() { - $this->assertNull(Class_UsersNonValid::find(1)); - } - - - /** @test */ - public function responseShouldNotifyRegistrationHasBeenDeleted() { - $this->assertFlashMessengerContentContains('La demande d\'inscription pour "pwd" a été supprimée'); - } -} - - - - -class ModoControllerDeleteRegistrationTest extends ModoControllerRegistrationsTestCase { - public function setUp() { - parent::setUp(); - $this->dispatch('/admin/modo/delete-registration/id/2', true); - } - - - /** @test */ - public function registrationCheweShouldHaveBeenDeleted() { - $this->assertNull(Class_UsersNonValid::find(2)); - } - - - /** @test */ - public function userCheweShouldNotHaveBeenDeleted() { - $this->assertNotNull(Class_Users::findFirstBy(['login' => 'chewe'])); - } - - - /** @test */ - public function shouldRedirect() { - $this->assertRedirect(); - } -} - - - - -class ModoControllerValidateRegistrationTest extends Admin_AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; - - - public function setUp() { - parent::setUp(); - $this->fixture('Class_UsersNonValid', - ['id' => 1, - 'login' => 'pwd', - 'password' => 'pwd', - 'date' => '2018-16-01', - 'mail' => 'pwd@afi-sa.fr']); - - $this->dispatch('/admin/modo/validate-registration/id/1', true); - } - - - /** @test */ - public function shouldRedirect() { - $this->assertRedirect(); - } - - - /** @test */ - public function registrationShouldHaveAUser() { - $registration = Class_UsersNonValid::find(1); - $this->assertNotNull($registration->hasUser()); - return $registration->getUser(); - } - - - /** - * @test - * @depends registrationShouldHaveAUser - */ - public function createdUserLoginShouldBePwd($user) { - $this->assertEquals('pwd', $user->getLogin()); - } -} - - - -class ModoControllerMembreviewEmptyDispatchTest extends Admin_AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; - - - public function setUp() { - parent::setUp(); - $this->dispatch('/admin/modo/membreview', true); - } - - - /** @test */ - public function noRegistrationRequestMessageShouldBeDisplay() { - $this->assertXPathContentContains('//p', 'Aucune demande d\'inscription'); - } -} - - - - -class ModoControllerExpiredRegistrationsTest extends Admin_AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; - - - public function setUp() { - parent::setUp(); - $this->fixture('Class_UsersNonValid', - ['id' => 1, - 'login' => 'pwd', - 'password' => 'pwd', - 'date' => '2018-16-01', - 'mail' => 'pwd@afi-sa.fr']); - - $this->fixture('Class_UsersNonValid', - ['id' => 2, - 'login' => 'log', - 'password' => 'log', - 'date' => '2018-01-01', - 'mail' => 'log@afi-sa.fr']); - - $this->fixture('Class_AdminVar', - ['id' => 'MAX_DAY_INVALID_MEMBRE', - 'valeur' => 2]); - - $this->dispatch('/admin/modo/membreview', true); - } - - - /** @test */ - public function logShouldBeExpired() { - $this->assertXpathContentContains('//td', 'Oui'); - } - - - /** @test */ - public function deleteAllExpiredRegistrationButtonShouldBePresent() { - $this->assertXpathContentContains('//button[contains(@onclick,"/admin/modo/delete-expired-registrations")]', 'Supprimer les demandes expirées', $this->_response->getBody()); - } -} - - - - - -class ModoControllerDeleteExpiredRegistrationsTest extends Admin_AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; - - - public function setUp() { - parent::setUp(); - $this->fixture('Class_UsersNonValid', - ['id' => 1, - 'login' => 'pwd', - 'password' => 'pwd', - 'date' => '2048-12-01', - 'mail' => 'pwd@afi-sa.fr']); - - $this->fixture('Class_UsersNonValid', - ['id' => 2, - 'login' => 'log', - 'password' => 'log', - 'date' => '2018-01-01', - 'mail' => 'log@afi-sa.fr']); - - $this->fixture('Class_AdminVar', - ['id' => 'MAX_DAY_INVALID_MEMBRE', - 'valeur' => 2]); - - $this->dispatch('/admin/modo/delete-expired-registrations', true); - } - - - /** @test */ - public function shouldRedirect() { - $this->assertRedirect(); - } - - - /** @test */ - public function logRegistrationShouldHaveBeenDeleted() { - $this->assertNull(Class_UsersNonValid::find(2)); - } - - - /** @test */ - public function onlyOneRegistrationShouldRemain() { - $this->assertEquals(1, count(Class_UsersNonValid::findAll())); - } -} +} \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/ReferentPortailControllerTest.php b/tests/application/modules/admin/controllers/ReferentPortailControllerTest.php index c91cb8c5cdc770063b7aea7454528f8223122be8..803957955e85adb6904f19f6cfd9ba3b6e6b5ab4 100644 --- a/tests/application/modules/admin/controllers/ReferentPortailControllerTest.php +++ b/tests/application/modules/admin/controllers/ReferentPortailControllerTest.php @@ -77,12 +77,6 @@ class ReferentPortailControllerIndexActionTest extends ReferentPortailController } - /** @test */ - function menuGaucheShouldContainsDemandeDinscription() { - $this->assertXPathContentContains('//li//a','Demandes d\'inscription',$this->_response->getBody()); - } - - /** @test */ function menuGaucheShouldContainsCollections() { $this->assertXPathContentContains('//li//a','Collections',$this->_response->getBody()); diff --git a/tests/application/modules/admin/controllers/RegistrationControllerTest.php b/tests/application/modules/admin/controllers/RegistrationControllerTest.php new file mode 100644 index 0000000000000000000000000000000000000000..756408339a242e5a9b4cefad689403189b937a58 --- /dev/null +++ b/tests/application/modules/admin/controllers/RegistrationControllerTest.php @@ -0,0 +1,394 @@ +<?php +/** + * Copyright (c) 2019, 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 RegistrationControllerTestCase extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + $this->fixture('Class_UsersNonValid', + ['id' => 1, + 'login' => 'pwd', + 'password' => 'pwd', + 'date' => '2018-16-01', + 'mail' => 'pwd@afi-sa.fr']); + + $this->fixture('Class_UsersNonValid', + ['id' => 2, + 'login' => 'chewe', + 'password' => 'ehhhhhh', + 'bib'=> $this->fixture('Class_Bib', + ['id' => 3, + 'libelle' => 'Tatoine']), + 'date' => '2019-16-01', + 'mail' => 'chewe@afi-sa.fr'])->activate();; + } +} + + + + +class RegistrationControllerIndexAsAdminTatoineTest extends RegistrationControllerTestCase { + public function setUp() { + parent::setUp(); + + Class_Users::getIdentity() + ->beAdminBib() + ->setPassword('secret') + ->setBib(Class_Bib::find(3)) + ->assertSave(); + + $this->dispatch('/admin/registration'); + } + + + /** @test */ + public function pageShouldNotContainsRegistrationPwd() { + $this->assertNotXPathContentContains('//td', 'pwd'); + } + + + /** @test */ + public function pageShouldContainsRegistrationChewe() { + $this->assertXPathContentContains('//td', 'chewe'); + } + + + /** @test */ + public function leftMenuRegistrationCountShouldBeOne() { + $this->assertXPath('//ul[@class="menuAdmin"]//a[contains(@href, "/admin/registration")][following-sibling::span[@class="menu_info"][text()="1"]]'); + } +} + + + + +class RegistrationControllerIndexTest extends RegistrationControllerTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/admin/registration'); + } + + + /** @test */ + public function loginPwdShouldBeDisplay() { + $this->assertXPathContentContains('//td', 'pwd'); + } + + + /** @test */ + public function libraryNameShouldBeDisplay() { + $this->assertXPathContentContains('//td', 'Tatoine'); + } + + + /** @test */ + public function pageShouldContainsRejectRegistrationLinkForPwd() { + $this->assertXPath('//a[contains(@href, "admin/registration/reject/id/1")]'); + } + + + /** @test */ + public function pageShouldContainsRejectRegistrationLinkForChewee() { + $this->assertXPath('//a[contains(@href, "admin/registration/reject/id/2")]'); + } + + + /** @test */ + public function pageShouldNotContainsDeleteRegistrationLinkForPwd() { + $this->assertNotXPath('//a[contains(@href, "admin/registration/delete/id/1")]'); + } + + + public function pageShouldContainsDeleteRegistrationLinkForChewee() { + $this->assertXPath('//a[contains(@href, "admin/registration/delete/id/2")]'); + } + + + /** @test */ + public function pageShouldContainsLinkToValidateRegistrationForInexistingUserPwd() { + $this->assertXPath('//tbody/tr[1]//a[contains(@href, "admin/registration/validate/id/")]'); + } + + + /** @test */ + public function pageShouldNotContainsLinkToValidateRegistrationForUserChewe() { + $this->assertNotXPath('//tbody/tr[2]//a[contains(@href, "admin/registration/validate/id/")]'); + } + + + /** @test */ + public function pageShouldNotContainsLinkToEditInexistingUserPwd() { + $this->assertNotXPath('//tbody/tr[1]//a[contains(@href, "admin/users/edit/id/")]'); + } + + + /** @test */ + public function pageShouldContainsLinkToEditUserChewe() { + $this->assertXPath(sprintf('//a[contains(@href, "admin/users/edit/id/%d")]', + Class_UsersNonValid::find(2)->getUser()->getId())); + } + + + /** @test */ + public function pageShouldBeHTML5Valid() { + $this->assertHTML5(); + } +} + + + + +class RegistrationControllerRejectCheweeTest extends RegistrationControllerTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/admin/registration/reject/id/2'); + } + + + /** @test */ + public function cheweeRegistrationShouldHaveBeenDeleted() { + $this->assertNull(Class_UsersNonValid::find(2)); + } + + + /** @test */ + public function userCheweeShouldHaveBeenDeleted() { + $this->assertNull(Class_Users::findFirstBy(['login' => 'chewe'])); + } + + + /** @test */ + public function responseShouldRedirectToModoMembreView() { + $this->assertRedirectTo('/admin/registration/index'); + } + + + /** @test */ + public function responseShouldNotifyRegistrationHasBeenDeleted() { + $this->assertFlashMessengerContentContains('La demande d\'inscription pour "chewe" a été supprimée'); + } + + + /** @test */ + public function responseShouldNotifyCheweeHasBeenDeleted() { + $this->assertFlashMessengerContentContains('Le compte "chewe" a été supprimé'); + } +} + + + + +class RegistrationControllerRejectPwdTest extends RegistrationControllerTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/admin/registration/reject/id/1'); + } + + + /** @test */ + public function registrationPwdShouldHaveBeenDeleted() { + $this->assertNull(Class_UsersNonValid::find(1)); + } + + + /** @test */ + public function responseShouldNotifyRegistrationHasBeenDeleted() { + $this->assertFlashMessengerContentContains('La demande d\'inscription pour "pwd" a été supprimée'); + } +} + + + + +class RegistrationControllerDeleteTest extends RegistrationControllerTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/admin/registration/delete/id/2'); + } + + + /** @test */ + public function registrationCheweShouldHaveBeenDeleted() { + $this->assertNull(Class_UsersNonValid::find(2)); + } + + + /** @test */ + public function userCheweShouldNotHaveBeenDeleted() { + $this->assertNotNull(Class_Users::findFirstBy(['login' => 'chewe'])); + } + + + /** @test */ + public function shouldRedirect() { + $this->assertRedirect(); + } +} + + + + +class RegistrationControllerValidateTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + $this->fixture('Class_UsersNonValid', + ['id' => 1, + 'login' => 'pwd', + 'password' => 'pwd', + 'date' => '2018-16-01', + 'mail' => 'pwd@afi-sa.fr']); + + $this->dispatch('/admin/registration/validate/id/1'); + } + + + /** @test */ + public function shouldRedirect() { + $this->assertRedirect(); + } + + + /** @test */ + public function registrationShouldHaveAUser() { + $registration = Class_UsersNonValid::find(1); + $this->assertNotNull($registration->hasUser()); + return $registration->getUser(); + } + + + /** + * @test + * @depends registrationShouldHaveAUser + */ + public function createdUserLoginShouldBePwd($user) { + $this->assertEquals('pwd', $user->getLogin()); + } +} + + + +class ModoControllerMembreviewEmptyDispatchTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + /** @test */ + public function noRegistrationRequestMessageShouldBeDisplay() { + $this->dispatch('/admin/registration'); + $this->assertXPathContentContains('//p', 'Aucune demande d\'inscription'); + } +} + + + + +class RegistrationControllerExpiredTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + $this->fixture('Class_UsersNonValid', + ['id' => 1, + 'login' => 'pwd', + 'password' => 'pwd', + 'date' => '2018-16-01', + 'mail' => 'pwd@afi-sa.fr']); + + $this->fixture('Class_UsersNonValid', + ['id' => 2, + 'login' => 'log', + 'password' => 'log', + 'date' => '2018-01-01', + 'mail' => 'log@afi-sa.fr']); + + $this->fixture('Class_AdminVar', + ['id' => 'MAX_DAY_INVALID_MEMBRE', + 'valeur' => 2]); + + $this->dispatch('/admin/registration'); + } + + + /** @test */ + public function logShouldBeExpired() { + $this->assertXpathContentContains('//td', 'Oui'); + } + + + /** @test */ + public function deleteAllExpiredRegistrationButtonShouldBePresent() { + $this->assertXpathContentContains('//button[contains(@onclick,"/admin/registration/delete-expired")]', + 'Supprimer les demandes expirées'); + } +} + + + + +class RegistrationControllerDeleteExpiredTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + $this->fixture('Class_UsersNonValid', + ['id' => 1, + 'login' => 'pwd', + 'password' => 'pwd', + 'date' => '2048-12-01', + 'mail' => 'pwd@afi-sa.fr']); + + $this->fixture('Class_UsersNonValid', + ['id' => 2, + 'login' => 'log', + 'password' => 'log', + 'date' => '2018-01-01', + 'mail' => 'log@afi-sa.fr']); + + $this->fixture('Class_AdminVar', + ['id' => 'MAX_DAY_INVALID_MEMBRE', + 'valeur' => 2]); + + $this->dispatch('/admin/registration/delete-expired'); + } + + + /** @test */ + public function shouldRedirect() { + $this->assertRedirect(); + } + + + /** @test */ + public function logRegistrationShouldHaveBeenDeleted() { + $this->assertNull(Class_UsersNonValid::find(2)); + } + + + /** @test */ + public function onlyOneRegistrationShouldRemain() { + $this->assertEquals(1, count(Class_UsersNonValid::findAll())); + } +} diff --git a/tests/library/Class/UsersNonValidTest.php b/tests/library/Class/UsersNonValidTest.php index 7026663645cc7bd6dfa0fef8b1f44fb1b4ca57b0..812e6bc70241dbc40387fbc699b5486ba161e7c2 100644 --- a/tests/library/Class/UsersNonValidTest.php +++ b/tests/library/Class/UsersNonValidTest.php @@ -27,6 +27,7 @@ class Class_UsersNonValidActivateTest extends ModelTestCase { public function setUp() { parent::setUp(); + $this ->fixture('Class_UsersNonValid', ['id' => 3, @@ -34,7 +35,7 @@ class Class_UsersNonValidActivateTest extends ModelTestCase { 'lastname' => 'brown', 'firstname' => 'james', 'idabon' => '123', - 'id_site' => '3', + 'id_site' => 3, 'mail' => 'jb@sexmach.ne', 'password' => 'ifeelgood']) ->activate(); @@ -72,3 +73,62 @@ class Class_UsersNonValidActivateTest extends ModelTestCase { $this->assertTrue($this->_new_user->verifyPassword('ifeelgood')); } } + +class Class_UsersNonValidActivateWithConnectionToSIGBTest extends ModelTestCase { + protected + $_storm_default_to_volatile = true, + $_new_user; + + public function setUp() { + parent::setUp(); + + + $int_bib =$this->fixture('Class_IntBib', + ['id' => 3 + ]) + ->beKoha() + ->beCommKoha() + ->setCommParams(['use_card_number'=>'12414C12']); + $int_bib->assertSave(); + + $bib= $this->fixture('Class_Bib', + ['id' => 3, + 'libelle' => 'Tatoine', + 'int_bib' => $int_bib + ]); + + Class_User_ILSSubscription::setTimeSource(new TimeSourceForTest('2019-02-12 11:25:31')); + + $this + ->fixture('Class_UsersNonValid', + ['id' => 3, + 'login' => 'jb', + 'lastname' => 'brown', + 'firstname' => 'james', + 'idabon' => '123', + 'id_site' => 3, + 'mail' => 'jb@sexmach.ne', + 'password' => 'ifeelgood']) + ->activate(); + + $this->_new_user = Class_Users::find(1); + } + + + public function tearDown() { + Class_User_ILSSubscription::setTimeSource(null); + parent::tearDown(); + } + + + /** @test */ + public function userRoleShouldBeAbonneSIGB() { + $this->assertTrue( $this->_new_user->isAbonne()); + } + + + /** @test */ + public function userDateFinShouldBesetToNextyear() { + $this->assertEquals('2020-02-12', $this->_new_user->getDateFin()); + } +} diff --git a/tests/library/ZendAfi/View/Helper/Admin/MenuGaucheAdminTest.php b/tests/library/ZendAfi/View/Helper/Admin/MenuGaucheAdminTest.php index 64c32e9924bbfe346f4bc2191d0c820a1425a602..37d408d930bf2be52770f7c53138e2a6a1a493ff 100644 --- a/tests/library/ZendAfi/View/Helper/Admin/MenuGaucheAdminTest.php +++ b/tests/library/ZendAfi/View/Helper/Admin/MenuGaucheAdminTest.php @@ -208,7 +208,7 @@ Trait MenuGaucheAdminRolesDefinition { 'sito', 'external-agendas', 'modo', - 'modo/membreview', + 'registration', 'newsletter', 'activity', 'lieu', @@ -260,7 +260,7 @@ Trait MenuGaucheAdminRolesDefinition { 'sito', 'external-agendas', 'modo', - 'modo/membreview', + 'registration', 'newsletter', 'activity', 'lieu', @@ -297,7 +297,6 @@ Trait MenuGaucheAdminRolesDefinition { 'cms', 'sito', 'modo', - 'modo/membreview', 'newsletter', 'stat/rechercheinfructueuse', 'file-manager' @@ -311,7 +310,7 @@ Trait MenuGaucheAdminRolesDefinition { 'sito', 'external-agendas', 'modo', - 'modo/membreview', + 'registration', 'newsletter', 'activity', 'lieu', @@ -336,7 +335,6 @@ Trait MenuGaucheAdminRolesDefinition { 'cms', 'sito', 'modo', - 'modo/membreview', 'stat/rechercheinfructueuse', 'file-manager', ] ]