From e4fbc64ed7c60cc9188938fcce4c12eda8e5b3cb Mon Sep 17 00:00:00 2001 From: pbarroca <pbarroca@git-test.afi-sa.fr> Date: Thu, 24 May 2012 17:25:33 +0000 Subject: [PATCH] =?UTF-8?q?T=C3=A9l=C3=A9phone:=20workflow=20de=20r=C3=A9s?= =?UTF-8?q?ervation=20sauf=20=C3=A9cran=20d=C3=A9di=C3=A9=20de=20login=20i?= =?UTF-8?q?nterm=C3=A9diaire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 2 + .../controllers/RechercheController.php | 55 ++++- .../scripts/recherche/pickup-location.phtml | 13 ++ .../views/scripts/recherche/reservation.phtml | 8 + library/Class/CommSigb.php | 14 ++ .../RechercheControllerHarryPotterTest.php | 194 ++++++++++++++++++ 6 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 application/modules/telephone/views/scripts/recherche/pickup-location.phtml create mode 100644 application/modules/telephone/views/scripts/recherche/reservation.phtml diff --git a/.gitattributes b/.gitattributes index e79297890d5..02915183dcb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -661,7 +661,9 @@ application/modules/telephone/views/scripts/recherche/detail.phtml -text application/modules/telephone/views/scripts/recherche/exemplaires.phtml -text application/modules/telephone/views/scripts/recherche/grandeimage.phtml -text application/modules/telephone/views/scripts/recherche/index.phtml -text +application/modules/telephone/views/scripts/recherche/pickup-location.phtml -text application/modules/telephone/views/scripts/recherche/rebond.phtml -text +application/modules/telephone/views/scripts/recherche/reservation.phtml -text application/modules/telephone/views/scripts/recherche/resume.phtml -text application/modules/telephone/views/scripts/recherche/similaires.phtml -text application/modules/telephone/views/scripts/recherche/simple.phtml -text diff --git a/application/modules/telephone/controllers/RechercheController.php b/application/modules/telephone/controllers/RechercheController.php index 0bb8f4226c2..b0cdea835be 100644 --- a/application/modules/telephone/controllers/RechercheController.php +++ b/application/modules/telephone/controllers/RechercheController.php @@ -55,6 +55,51 @@ class Telephone_RechercheController extends RechercheController { } + 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; + } + + $ret = Class_CommSigb::getInstance() + ->reserverExemplaire($this->_getParam('b'), + $this->_getParam('e'), + ($this->_getParam('pickup')) ? $this->_getParam('pickup') : $this->_getParam('a')); + + 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; + } + + $this->_redirect('/abonne/fiche'); + } + + + public function pickupLocationAction() { + $this->_loadUrlRetourForExemplaire($this->_getParam('e')); + $this->view->annexes = Class_CodifAnnexe::findAllByPickup(); + } + + public function resumeAction() { $this->view->notice = Class_Notice::getLoader()->find($this->_getParam('id')); } @@ -72,4 +117,12 @@ class Telephone_RechercheController extends RechercheController { $this->view->notice = Class_Notice::getLoader()->find($this->_getParam('id')); } -} \ No newline at end of file + + protected function _loadUrlRetourForExemplaire($id_exemplaire) { + $exemplaire = Class_Exemplaire::getLoader()->find($id_exemplaire); + $this->view->url_retour = $this->view->url(array('controller' => 'recherche', + 'action' => 'exemplaires', + 'id' => $exemplaire->getNotice()->getId()), + null, true); + } +} diff --git a/application/modules/telephone/views/scripts/recherche/pickup-location.phtml b/application/modules/telephone/views/scripts/recherche/pickup-location.phtml new file mode 100644 index 00000000000..0ad29c7bf4f --- /dev/null +++ b/application/modules/telephone/views/scripts/recherche/pickup-location.phtml @@ -0,0 +1,13 @@ +<?php +echo $this->toolbar($this->_("Site de retrait"), + $this->url_retour, +false); ?> +<div class="pave"> + <?php foreach ($this->annexes as $annexe) { ?> + <div class="fonction"> + <a href="<?php + echo $this->url(array('action' => 'reservation', 'pickup' => $annexe->getCode())); + ?>" style="display:block;"><?php echo $this->escape($annexe->getLibelle());?></a> + </div> + <?php } ?> +</div> \ No newline at end of file diff --git a/application/modules/telephone/views/scripts/recherche/reservation.phtml b/application/modules/telephone/views/scripts/recherche/reservation.phtml new file mode 100644 index 00000000000..90cbea3e278 --- /dev/null +++ b/application/modules/telephone/views/scripts/recherche/reservation.phtml @@ -0,0 +1,8 @@ +<?php +echo $this->toolbar($this->_("Réservation"), + $this->url_retour, + false); +?> +<div class="pave"> + <?php echo $this->escape($this->message);?> +</div> \ No newline at end of file diff --git a/library/Class/CommSigb.php b/library/Class/CommSigb.php index 1a87b031366..9e7da4f1382 100644 --- a/library/Class/CommSigb.php +++ b/library/Class/CommSigb.php @@ -28,6 +28,8 @@ class Class_CommSigb { const COM_ORPHEE = 8; const COM_MICROBIB = 9; + protected static $_instance; + private $COM_CLASSES = array(self::COM_PERGAME => 'Class_WebService_SIGB_Pergame', self::COM_OPSYS => 'Class_WebService_SIGB_Opsys', self::COM_VSMART => 'Class_WebService_SIGB_VSmart', @@ -42,6 +44,18 @@ class Class_CommSigb { private $_translate; + public static function getInstance() { + if (null != self::$_instance) + return self::$_instance; + return new self(); + } + + + public static function setInstance($instance) { + self::$_instance = $instance; + } + + public function exemplaireFor($exemplaire) { $mode_comm = $this->getModeComm($exemplaire->getBib()->getId()); if ($sigb = $this->getSIGBComm($mode_comm)) diff --git a/tests/application/modules/telephone/controllers/RechercheControllerHarryPotterTest.php b/tests/application/modules/telephone/controllers/RechercheControllerHarryPotterTest.php index eb1525142d6..d2b714a871e 100644 --- a/tests/application/modules/telephone/controllers/RechercheControllerHarryPotterTest.php +++ b/tests/application/modules/telephone/controllers/RechercheControllerHarryPotterTest.php @@ -390,6 +390,200 @@ class Telephone_RechercheControllerHarryPotterExemplaireReservableTest extends T +class Telephone_RechercheControllerHarryPotterReservationNotLogged extends Telephone_RechercheControllerHarryPotterTestCase { + public function setUp() { + parent::setUp(); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('getIdentity') + ->answers(false); + + $this->dispatch('/recherche/reservation/b/1/e/33/a/MOUL'); + } + + + /** @test */ + public function shouldRedirectToAuth() { + $this->assertRedirectTo('/auth/login-reservation'); + } + + + /** @test */ + public function shouldHaveSetReservationBibParam() { + $this->assertEquals(1, Zend_Registry::get('session')->lastReservationParams['b']); + } + + + /** @test */ + public function shouldHaveSetReservationExemplaireParam() { + $this->assertEquals(33, Zend_Registry::get('session')->lastReservationParams['e']); + } + + + /** @test */ + public function shouldHaveSetReservationAnnexeParam() { + $this->assertEquals('MOUL', Zend_Registry::get('session')->lastReservationParams['a']); + } +} + + + +class Telephone_RechercheControllerHarryPotterReservationWithEnabledPickup extends Telephone_RechercheControllerHarryPotterTestCase { + public function setUp() { + parent::setUp(); + Class_CosmoVar::getLoader() + ->newInstanceWithId('site_retrait_resa') + ->setValeur(1); + + $this->dispatch('/recherche/reservation/b/1/e/33/a/MOUL'); + } + + + /** @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(); + Class_Exemplaire::getLoader() + ->newInstanceWithId(33) + ->setCote('JRROW') + ->setNotice(Class_Notice::getLoader()->find(4)); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_CodifAnnexe') + ->whenCalled('findAllBy') + ->with(array('no_pickup' => '0', + 'order' => 'libelle')) + ->answers(array(Class_CodifAnnexe::getLoader()->newInstanceWithId(2) + ->setLibelle('Annecy') + ->setCode('ANN'), + Class_CodifAnnexe::getLoader()->newInstanceWithId(3) + ->setLibelle('Cran') + ->setCode('CRN'))); + $this->dispatch('/recherche/pickup-location/b/1/e/33/a/MOUL', true); + } + + + /** @test */ + public function titreShouldBeSiteDeRetrait() { + $this->assertXPathContentContains('//h1', 'Site de retrait'); + } + + + /** @test */ + public function pageShouldContainsAnnecyChoice() { + $this->assertXPathContentContains('//a[contains(@href, "/recherche/reservation/b/1/e/33/a/MOUL/pickup/ANN")]', + 'Annecy'); + } +} + + + +class Telephone_RechercheControllerHarryPotterReservationSuccessTest extends Telephone_RechercheControllerHarryPotterTestCase { + public function setUp() { + parent::setUp(); + Class_CosmoVar::getLoader() + ->newInstanceWithId('site_retrait_resa') + ->setValeur(0); + + Class_CommSigb::setInstance(Storm_Test_ObjectWrapper::mock() + ->whenCalled('reserverExemplaire') + ->answers(array())); + $this->dispatch('/recherche/reservation/b/1/e/33/a/MOUL', true); + } + + + /** @test */ + public function shouldRedirectToFicheAbonne() { + $this->assertRedirectTo('/abonne/fiche'); + } +} + + + +class Telephone_RechercheControllerHarryPotterReservationErrorTest extends Telephone_RechercheControllerHarryPotterTestCase { + public function setUp() { + parent::setUp(); + Class_CosmoVar::getLoader() + ->newInstanceWithId('site_retrait_resa') + ->setValeur(0); + + Class_CommSigb::setInstance(Storm_Test_ObjectWrapper::mock() + ->whenCalled('reserverExemplaire') + ->answers(array('erreur' => 'A marche pas'))); + + Class_Exemplaire::getLoader() + ->newInstanceWithId(33) + ->setCote('JRROW') + ->setNotice(Class_Notice::getLoader()->find(4)); + + $this->dispatch('/recherche/reservation/b/1/e/33/a/MOUL', true); + } + + + /** @test */ + public function titreShouldBeReservation() { + $this->assertXPathContentContains('//h1', 'Réservation'); + } + + + /** @test */ + public function pageShouldContainsErrorMessage() { + $this->assertXPathContentContains('//div', 'A marche pas'); + } + + + /** @test */ + public function backLinkToExemplairesShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/recherche/exemplaires/id/4")]'); + } + +} + + + +class Telephone_RechercheControllerHarryPotterReservationWithPopupTest extends Telephone_RechercheControllerHarryPotterTestCase { + public function setUp() { + parent::setUp(); + Class_CosmoVar::getLoader() + ->newInstanceWithId('site_retrait_resa') + ->setValeur(0); + + Class_CommSigb::setInstance(Storm_Test_ObjectWrapper::mock() + ->whenCalled('reserverExemplaire') + ->answers(array('popup' => 'http://url.de/la-popup'))); + + Class_Exemplaire::getLoader() + ->newInstanceWithId(33) + ->setCote('JRROW') + ->setNotice(Class_Notice::getLoader()->find(4)); + + $this->dispatch('/recherche/reservation/b/1/e/33/a/MOUL', true); + } + + + /** @test */ + public function titreShouldBeReservation() { + $this->assertXPathContentContains('//h1', 'Réservation'); + } + + + public function pageShouldContainsErrorMessage() { + $this->assertXPathContentContains('//div', 'non supportée'); + } + + + /** @test */ + public function backLinkToExemplairesShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/recherche/exemplaires/id/4")]'); + } +} + + class Telephone_RechercheControllerHarryPotterAvisTest extends Telephone_RechercheControllerHarryPotterTestCase { public function setUp() { -- GitLab