diff --git a/.gitattributes b/.gitattributes index 02915183dcb3adbf7f95c89faf7b6a0a323e1263..754c6f7db60ac6884f8a431558d66a4d00891b8b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -644,6 +644,7 @@ application/modules/telephone/views/scripts/abonne/fiche.phtml -text application/modules/telephone/views/scripts/abonne/prets.phtml -text application/modules/telephone/views/scripts/abonne/reservations.phtml -text application/modules/telephone/views/scripts/auth/boitelogin.phtml -text +application/modules/telephone/views/scripts/auth/login-reservation.phtml -text application/modules/telephone/views/scripts/bib-numerique/view-album.phtml -text application/modules/telephone/views/scripts/bib-numerique/view-categorie.phtml -text application/modules/telephone/views/scripts/blog/viewauteur.phtml -text @@ -1899,6 +1900,7 @@ library/ZendAfi/Filters/Post.php -text library/ZendAfi/Filters/ReadSql.php -text library/ZendAfi/Filters/Serialize.php -text library/ZendAfi/Filters/WriteSql.php -text +library/ZendAfi/Form.php -text library/ZendAfi/Form/Decorator/Ckeditor.php -text library/ZendAfi/Form/Decorator/CochesSuggestion.php -text library/ZendAfi/Form/Decorator/DatePicker.php -text @@ -1914,6 +1916,7 @@ library/ZendAfi/Form/Element/File.php -text library/ZendAfi/Form/Element/Image.php -text library/ZendAfi/Form/Element/ImageDelete.php -text library/ZendAfi/Form/Element/ListeSuggestion.php -text +library/ZendAfi/Form/Login.php -text library/ZendAfi/Translate.php -text library/ZendAfi/Validate/Url.php -text library/ZendAfi/View/Helper/AbsoluteUrl.php -text diff --git a/application/modules/telephone/controllers/AuthController.php b/application/modules/telephone/controllers/AuthController.php index 95b3337c9dd030517a910be38b160958a46f3675..b2d8dfc0bbea9bdc4f391604ef0ded8395ad886f 100644 --- a/application/modules/telephone/controllers/AuthController.php +++ b/application/modules/telephone/controllers/AuthController.php @@ -22,11 +22,32 @@ require_once ROOT_PATH.'application/modules/opac/controllers/AuthController.php'; class Telephone_AuthController extends AuthController { - function boiteloginAction() { + public function boiteloginAction() { if ($this->_request->isPost()) $this->_authenticate(); $this->_redirect('/telephone/index'); } -} + + public function loginReservationAction() { + $form = $this->_getForm(); + if ($this->_request->isPost() + && !($this->view->error = $this->_authenticate())) { + $this->_redirect('/recherche/reservation'); + return; + } + + $this->view->id_notice = $this->_getParam('id'); + $this->view->form = $form; + } + + + protected function _getForm() { + $form = new ZendAfi_Form_Login(); + $form->getElement('username')->setAttrib('placeholder', $this->view->_('Identifiant')); + $form->getElement('password')->setAttrib('placeholder', $this->view->_('Mot de passe')); + $form->getElement('login')->setLabel($this->view->_('Se connecter')); + return $form; + } +} ?> \ No newline at end of file diff --git a/application/modules/telephone/controllers/RechercheController.php b/application/modules/telephone/controllers/RechercheController.php index 498a298d14adf1fabc108cf4ca650a9703b2c20f..49357f45988635e2ef865e73a630b7d279c8ef44 100644 --- a/application/modules/telephone/controllers/RechercheController.php +++ b/application/modules/telephone/controllers/RechercheController.php @@ -31,91 +31,90 @@ class Telephone_RechercheController extends RechercheController { $this->view->_('Biographies') => array('action' => 'biographie'), $this->view->_('Notices similaires') => array('action' => 'similaires'), $this->view->_('Ressources numériques') => array('action' => 'ressourcesnumeriques'), - ); - } + ); + } - public function grandeimageAction() { - $this->view->notice = Class_Notice::getLoader()->find($this->_getParam('id')); - } + public function grandeimageAction() { + $this->view->notice = Class_Notice::getLoader()->find($this->_getParam('id')); + } - public function exemplairesAction() { - $this->view->notice = Class_Notice::getLoader()->find($this->_getParam('id')); - } + public function exemplairesAction() { + $this->view->notice = Class_Notice::getLoader()->find($this->_getParam('id')); + } - public function avisAction() { - $this->view->notice = Class_Notice::getLoader()->find($this->_getParam('id')); - } + public function avisAction() { + $this->view->notice = Class_Notice::getLoader()->find($this->_getParam('id')); + } - public function detailAction() { - $this->view->notice = Class_Notice::getLoader()->find($this->_getParam('id')); - } + public function detailAction() { + $this->view->notice = Class_Notice::getLoader()->find($this->_getParam('id')); + } - public function reservationAction() { - if (!Class_Users::getLoader()->getIdentity()) { - Zend_Registry::get('session')->lastReservationParams = array('b' => $this->_getParam('b'), - 'e' => $this->_getParam('e'), - 'a' => $this->_getParam('a')); - $this->_redirect('/auth/login-reservation'); - return; - } - - if (Class_CosmoVar::isSiteRetraitResaEnabled() - && !$this->_getParam('pickup')) { - $this->_redirect(sprintf('/recherche/pickup-location/b/%s/e/%s/a/%s', - urlencode($this->_getParam('b')), - urlencode($this->_getParam('e')), - urlencode($this->_getParam('a')))); - return; - } + public function reservationAction() { + if (!Class_Users::getLoader()->getIdentity()) { + $this->_setLastReservationParamsAndGotoLogin(); + return; + } - $ret = Class_CommSigb::getInstance() - ->reserverExemplaire($this->_getParam('b'), - $this->_getParam('e'), - ($this->_getParam('pickup')) ? $this->_getParam('pickup') : $this->_getParam('a')); + $this->_loadReservationParamsFromSession(); - if (isset($ret["erreur"])) { - $this->_loadUrlRetourForExemplaire($this->_getParam('e')); - $this->view->message = $ret['erreur']; - return; - } + if (Class_CosmoVar::isSiteRetraitResaEnabled() + && !$this->_getParam('pickup')) { + $this->_redirect(sprintf('/recherche/pickup-location/b/%s/e/%s/a/%s', + urlencode($this->_getParam('b')), + urlencode($this->_getParam('e')), + urlencode($this->_getParam('a')))); + return; + } - if (isset($ret["popup"])) { - $this->_loadUrlRetourForExemplaire($this->_getParam('e')); - $this->view->message = $this->view->_('Réservation en ligne non supportée pour cette bibliothèque.'); - return; - } + $ret = Class_CommSigb::getInstance() + ->reserverExemplaire($this->_getParam('b'), + $this->_getParam('e'), + ($this->_getParam('pickup')) ? $this->_getParam('pickup') : $this->_getParam('a')); - $this->_redirect('/abonne/fiche'); - } + if (isset($ret["erreur"])) { + $this->_loadUrlRetourForExemplaire($this->_getParam('e')); + $this->view->message = $ret['erreur']; + return; + } + if (isset($ret["popup"])) { + $this->_loadUrlRetourForExemplaire($this->_getParam('e')); + $this->view->message = $this->view->_('Réservation en ligne non supportée pour cette bibliothèque.'); + return; + } - public function pickupLocationAction() { - $this->_loadUrlRetourForExemplaire($this->_getParam('e')); - $this->view->annexes = Class_CodifAnnexe::findAllByPickup(); - } + $this->_redirect('/abonne/fiche'); + } - public function resumeAction() { - $this->view->notice = Class_Notice::getLoader()->find($this->_getParam('id')); - } + public function pickupLocationAction() { + $this->_loadUrlRetourForExemplaire($this->_getParam('e')); + $this->view->annexes = Class_CodifAnnexe::findAllByPickup(); + } - public function tagsAction() { - $notice = Class_Notice::getLoader()->find($this->_getParam('id')); - $notice_html = new Class_NoticeHtml(); - $this->view->tags = $notice_html->getTags($notice->getTags(), $notice->getId()); - $this->view->notice = $notice; - } + public function resumeAction() { + $this->view->notice = Class_Notice::getLoader()->find($this->_getParam('id')); + } - public function biographieAction() { - $this->view->notice = Class_Notice::getLoader()->find($this->_getParam('id')); - } + public function tagsAction() { + $notice = Class_Notice::getLoader()->find($this->_getParam('id')); + $notice_html = new Class_NoticeHtml(); + $this->view->tags = $notice_html->getTags($notice->getTags(), $notice->getId()); + $this->view->notice = $notice; + } + + + public function biographieAction() { + $this->view->notice = Class_Notice::getLoader()->find($this->_getParam('id')); + } public function similairesAction() { @@ -133,4 +132,24 @@ class Telephone_RechercheController extends RechercheController { 'id' => $exemplaire->getNotice()->getId()), null, true); } + + + protected function _setLastReservationParamsAndGotoLogin() { + $exemplaire = Class_Exemplaire::getLoader()->find($this->_getParam('e')); + Zend_Registry::get('session')->lastReservationParams = array('b' => $this->_getParam('b'), + 'e' => $this->_getParam('e'), + 'a' => $this->_getParam('a')); + $this->_redirect('/auth/login-reservation/id/' . urlencode($exemplaire->getNotice()->getId())); + } + + + protected function _loadReservationParamsFromSession() { + if (!$params = Zend_Registry::get('session')->lastReservationParams) + return; + + $this->_request + ->setParam('b', $params['b']) + ->setParam('e', $params['e']) + ->setParam('a', $params['a']); + } } diff --git a/application/modules/telephone/views/scripts/auth/boitelogin.phtml b/application/modules/telephone/views/scripts/auth/boitelogin.phtml index cc640c74ba12dc7d487d031d3a88b3b621b88769..3e78e8b879169ee1fe9e6bb5c5a3e6f740402c5f 100644 --- a/application/modules/telephone/views/scripts/auth/boitelogin.phtml +++ b/application/modules/telephone/views/scripts/auth/boitelogin.phtml @@ -16,22 +16,21 @@ if($user = Class_Users::getLoader()->getIdentity()) { $user->getNbReservations()); } else { - echo $this->newForm(array('autocomplete' => 'off', - 'decorators' => array('FormElements', 'Form'))) - ->setAction($this->url(array('controller' => 'auth', - 'action' => 'boitelogin', - 'id_module' => $this->id_module))) - ->addElement('text', 'username', array('label' => $this->preferences['identifiant'], - 'placeholder' => $this->preferences['identifiant_exemple'], - 'size' => 15)) - ->addElement('password', 'password', array('label' => $this->preferences['mot_de_passe'], - 'placeholder' => $this->preferences['mot_de_passe_exemple'], - 'size' => 15)) - ->setElementDecorators(array('ViewHelper', 'Label')) - ->addElement('submit', 'login', array('label' => $this->preferences['lien_connexion'], - 'decorators' => array('ViewHelper'))); + $form = new ZendAfi_Form_Login(); + $form->setAction($this->url(array('controller' => 'auth', + 'action' => 'boitelogin', + 'id_module' => $this->id_module))); + + $form->getElement('username') + ->setLabel($this->preferences['identifiant']) + ->setAttrib('placeholder', $this->preferences['identifiant_exemple']); + $form->getElement('password') + ->setLabel($this->preferences['mot_de_passe']) + ->setAttrib('placeholder', $this->preferences['mot_de_passe_exemple']); + $form->getElement('login') + ->setLabel($this->preferences['lien_connexion']); + echo $form; } ?> - <div class="clear"></div> \ No newline at end of file diff --git a/application/modules/telephone/views/scripts/auth/login-reservation.phtml b/application/modules/telephone/views/scripts/auth/login-reservation.phtml new file mode 100644 index 0000000000000000000000000000000000000000..cd7595dbc9826807e80f97e18578b6dea808f4f3 --- /dev/null +++ b/application/modules/telephone/views/scripts/auth/login-reservation.phtml @@ -0,0 +1,13 @@ +<?php +echo $this->toolbar($this->_("Identification"), + array('controller' => 'recherche', + 'action' => 'exemplaires', + 'id' => $this->id_notice), + false); +?> +<div class="pave"> +<?php +echo $this->form; +?> +<?php if ($this->error) echo '<strong style="color:red">' . $this->error . '</strong>';?> +</div> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Action/Helper/View.php b/library/ZendAfi/Controller/Action/Helper/View.php index 0331e6efcb8a8c744a47a57803c85a91d5d1bb4d..857cedf4cd69a011d5038618e48de12eeab2eb2e 100644 --- a/library/ZendAfi/Controller/Action/Helper/View.php +++ b/library/ZendAfi/Controller/Action/Helper/View.php @@ -209,16 +209,7 @@ class ZendAfi_Controller_Action_Helper_View extends Zend_View public function newForm($options = null) { - $form = new Zend_Form($options); - $form - ->getPluginLoader(Zend_Form::ELEMENT) - ->addPrefixPath('ZendAfi_Form_Element', 'ZendAfi/Form/Element'); - $form - ->getPluginLoader(Zend_Form::DECORATOR) - ->addPrefixPath('ZendAfi_Form_Decorator', 'ZendAfi/Form/Decorator'); - $form - ->addElementPrefixPath('ZendAfi_Validate', 'ZendAfi/Validate', 'validate'); - return $form; + return ZendAfi_Form::newWithOptions($options); } diff --git a/library/ZendAfi/Form.php b/library/ZendAfi/Form.php new file mode 100644 index 0000000000000000000000000000000000000000..527b286767da6748e960112eba896d4aa520454a --- /dev/null +++ b/library/ZendAfi/Form.php @@ -0,0 +1,40 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class ZendAfi_Form extends Zend_Form { + public static function newWithOptions($options = null) { + $instance = new self($options); + return $instance; + } + + + public function init() { + parent::init(); + $this + ->getPluginLoader(Zend_Form::ELEMENT) + ->addPrefixPath('ZendAfi_Form_Element', 'ZendAfi/Form/Element'); + $this + ->getPluginLoader(Zend_Form::DECORATOR) + ->addPrefixPath('ZendAfi_Form_Decorator', 'ZendAfi/Form/Decorator'); + $this + ->addElementPrefixPath('ZendAfi_Validate', 'ZendAfi/Validate', 'validate'); + } +} \ No newline at end of file diff --git a/library/ZendAfi/Form/Login.php b/library/ZendAfi/Form/Login.php new file mode 100644 index 0000000000000000000000000000000000000000..a10f5e6f27935673e64513618ecda80c97da00fc --- /dev/null +++ b/library/ZendAfi/Form/Login.php @@ -0,0 +1,38 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class ZendAfi_Form_Login extends ZendAfi_Form { + public function init() { + parent::init(); + $this + ->setMethod(Zend_Form::METHOD_POST) + ->setAttrib('autocomplete', 'off') + ->setDecorators(array('FormElements', 'Form')) + ->addElement('text', 'username', array('size' => 15, + 'required' => true, + 'allowEmpty' => false)) + ->addElement('password', 'password', array('size' => 15, + 'required' => true, + 'allowEmpty' => false)) + ->setElementDecorators(array('ViewHelper', 'Label')) + ->addElement('submit', 'login', array('decorators' => array('ViewHelper'))); + } +} \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/AuthControllerTest.php b/tests/application/modules/opac/controllers/AuthControllerTest.php index 5197aa8c597e2e9125a50a41432b78964f6a8fce..c5ffc3cd9ca03f2bc9872c7cce636bd7166e72e7 100644 --- a/tests/application/modules/opac/controllers/AuthControllerTest.php +++ b/tests/application/modules/opac/controllers/AuthControllerTest.php @@ -321,7 +321,10 @@ class AuthControllerPostTest extends AuthControllerNobodyLoggedTestCase { } - /** @test */ + /** + * @test + * @group integration + */ public function validAuthenticationShouldRedirect() { $user = Class_Users::getLoader()->findFirstBy(array()); diff --git a/tests/application/modules/telephone/controllers/AuthControllerTest.php b/tests/application/modules/telephone/controllers/AuthControllerTest.php index 9dae696b937d6e79b6d954e7c8cb3cf0db91fb62..4b7fd87521b9cc6132cdb6d6d2435708545481f3 100644 --- a/tests/application/modules/telephone/controllers/AuthControllerTest.php +++ b/tests/application/modules/telephone/controllers/AuthControllerTest.php @@ -22,7 +22,7 @@ require_once 'TelephoneAbstractControllerTestCase.php'; class AuthControllerTelephoneLoginTest extends TelephoneAbstractControllerTestCase { - protected function _loginHook($account) { + protected function _loginHook($account) { $account->ROLE = ""; $account->ROLE_LEVEL = 0; $account->ID_USER = ""; @@ -45,8 +45,80 @@ class AuthControllerTelephoneLoginTest extends TelephoneAbstractControllerTestCa public function responseShouldRedirectToIndex() { $this->assertRedirectTo('/telephone/index'); } - - +} + + + +class AuthControllerTelephoneLoginReservationTest extends TelephoneAbstractControllerTestCase { + public function setUp() { + parent::setUp(); + Class_Profil::getCurrentProfil() + ->setCfgAccueil(array()); + + $this->dispatch('auth/login-reservation/id/45324', true); + } + + + /** @test */ + public function pageShouldContainsLoginInput() { + $this->assertXPath('//form//input[@name="username"]'); + } + + + /** @test */ + public function pageShouldContainsPassInput() { + $this->assertXPath('//form//input[@name="password"]'); + } + + + /** @test */ + public function titleShouldBeIdentification() { + $this->assertXPathContentContains('//h1', 'Identification'); + } + + + /** @test */ + public function backLinkToExemplairesShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/recherche/exemplaires/id/45324")]'); + } +} + + + +class AuthControllerTelephoneLoginReservationInvalidPostTest extends TelephoneAbstractControllerTestCase { + public function setUp() { + parent::setUp(); + $this->postDispatch('auth/login-reservation/id/45324', array()); + } + + + /** @test */ + public function pageShouldContainsErrorMessage() { + $this->assertXPathContentContains('//strong', 'Entrez votre identifiant'); + } +} + + + +class AuthControllerTelephoneLoginReservationValidPostTest extends TelephoneAbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + Class_Profil::getCurrentProfil() + ->setCfgAccueil(array()); + + $user = Class_Users::getLoader()->findFirstBy(array()); + + $this->postDispatch('auth/login-reservation/id/45324', + array('username' => $user->getLogin(), + 'password' => $user->getPassword())); + } + + + /** @test */ + public function shouldRedirectToReservation() { + $this->assertRedirectTo('/recherche/reservation'); + } } ?> \ No newline at end of file diff --git a/tests/application/modules/telephone/controllers/RechercheControllerHarryPotterTest.php b/tests/application/modules/telephone/controllers/RechercheControllerHarryPotterTest.php index 5c85c4a1ed025cb69b017a705ef654378471e7ac..a34a2579d03dd0b908371a8cb7f9a554c079f200 100644 --- a/tests/application/modules/telephone/controllers/RechercheControllerHarryPotterTest.php +++ b/tests/application/modules/telephone/controllers/RechercheControllerHarryPotterTest.php @@ -420,13 +420,18 @@ class Telephone_RechercheControllerHarryPotterReservationNotLogged extends Telep ->whenCalled('getIdentity') ->answers(false); + Class_Exemplaire::getLoader() + ->newInstanceWithId(33) + ->setCote('JRROW') + ->setNotice(Class_Notice::getLoader()->find(4)); + $this->dispatch('/recherche/reservation/b/1/e/33/a/MOUL'); } /** @test */ public function shouldRedirectToAuth() { - $this->assertRedirectTo('/auth/login-reservation'); + $this->assertRedirectTo('/auth/login-reservation/id/4'); } @@ -457,6 +462,11 @@ class Telephone_RechercheControllerHarryPotterReservationWithEnabledPickup exten ->newInstanceWithId('site_retrait_resa') ->setValeur(1); + Class_Exemplaire::getLoader() + ->newInstanceWithId(33) + ->setCote('JRROW') + ->setNotice(Class_Notice::getLoader()->find(4)); + $this->dispatch('/recherche/reservation/b/1/e/33/a/MOUL'); } @@ -469,6 +479,40 @@ class Telephone_RechercheControllerHarryPotterReservationWithEnabledPickup exten } + +class Telephone_RechercheControllerHarryPotterReservationBackFromLoginWithEnabledPickup extends Telephone_RechercheControllerHarryPotterTestCase { + public function setUp() { + parent::setUp(); + Class_CosmoVar::getLoader() + ->newInstanceWithId('site_retrait_resa') + ->setValeur(1); + + Class_Exemplaire::getLoader() + ->newInstanceWithId(33) + ->setCote('JRROW') + ->setNotice(Class_Notice::getLoader()->find(4)); + + Zend_Registry::get('session')->lastReservationParams = array('b' => 1, + 'e' => 33, + 'a' => 'MOUL'); + $this->dispatch('/recherche/reservation'); + } + + + public function tearDown() { + unset(Zend_Registry::get('session')->lastReservationParams); + } + + + /** @test */ + public function shouldRedirectToPickupChoice() { + $this->assertRedirectTo('/recherche/pickup-location/b/1/e/33/a/MOUL'); + } + +} + + + class Telephone_RechercheControllerHarryPotterExemplairePickupChoiceTest extends Telephone_RechercheControllerHarryPotterTestCase { public function setUp() { parent::setUp();