From 3c3b075084b7cb98c987c6e5643fbada66187b5f Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Wed, 18 Jan 2017 17:03:21 +0100 Subject: [PATCH] hotline #52508 fix on site consult form validation --- VERSIONS_HOTLINE/52508 | 1 + .../opac/controllers/RechercheController.php | 5 +- .../controllers/OnSiteConsultationTest.php | 85 +++++++++++++++++-- 3 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 VERSIONS_HOTLINE/52508 diff --git a/VERSIONS_HOTLINE/52508 b/VERSIONS_HOTLINE/52508 new file mode 100644 index 00000000000..d7e8512d51a --- /dev/null +++ b/VERSIONS_HOTLINE/52508 @@ -0,0 +1 @@ + - ticket #52508 : Correction de la validation d'une demande de consultation sur place \ No newline at end of file diff --git a/application/modules/opac/controllers/RechercheController.php b/application/modules/opac/controllers/RechercheController.php index e309320f438..3299fce676b 100644 --- a/application/modules/opac/controllers/RechercheController.php +++ b/application/modules/opac/controllers/RechercheController.php @@ -543,6 +543,7 @@ class RechercheController extends ZendAfi_Controller_Action { public function consultationajaxAction() { if (!$this->userConnected()) return; + $title = $this->view->_('Consultation sur place'); if (!$exemplaire = Class_Exemplaire::find($this->_getParam('copy_id'))) return $this->renderPopupResult($title,$this->view->_('L\'exemplaire n\'existe pas')); @@ -653,9 +654,7 @@ class RechercheController extends ZendAfi_Controller_Action { return ; if ($this->_request->isPost()) { - $this->renderPopup($this->view->url(['action' => 'consultationajax', - 'location' => $this->_getParam('location')])); - return; + return $this->_forward('consultationajax'); } $form = new ZendAfi_Form_ConsultationPickup(); diff --git a/tests/application/modules/opac/controllers/OnSiteConsultationTest.php b/tests/application/modules/opac/controllers/OnSiteConsultationTest.php index 5378eeb3416..b82eaa81b2c 100644 --- a/tests/application/modules/opac/controllers/OnSiteConsultationTest.php +++ b/tests/application/modules/opac/controllers/OnSiteConsultationTest.php @@ -69,6 +69,7 @@ abstract class OnSiteConsultationTestCase extends AbstractControllerTestCase { 'id_notice' => 135, 'id_bib' => 99, 'id_int_bib' => 4, + 'code_barres' => 'OC2', 'zone995' => serialize([['clef' => 'r', 'valeur' => 'PATIMP']]), 'cote' => 'VOD', 'dispo' => 'Disponible']); @@ -164,9 +165,7 @@ class OnSiteConsultationExemplaireTest extends OnSiteConsultationTestCase { -class OnSiteConsultationPickupLocationTest extends OnSiteConsultationTestCase { - protected $_json; - +abstract class OnSiteConsultationPickupLocationTestCase extends OnSiteConsultationTestCase { public function setUp() { parent::setUp(); @@ -184,13 +183,24 @@ class OnSiteConsultationPickupLocationTest extends OnSiteConsultationTestCase { ->whenCalled('getAvailableItems') ->answers($locations); + } +} + + + + +class OnSiteConsultationPickupLocationTest extends OnSiteConsultationPickupLocationTestCase { + protected $_json; + + public function setUp() { + parent::setUp(); $this->dispatch('recherche/consultation-pickup-ajax/copy_id/799',true); $this->_json = json_decode($this->_response->getBody()); } /** @test */ - public function PopupTitleShouldBeLieuDeMiseADispositionDemande() { + public function popupTitleShouldBeLieuDeMiseADispositionDemande() { $this->assertEquals('Lieu de mise à disposition demandé', $this->_json->title); } @@ -205,6 +215,68 @@ class OnSiteConsultationPickupLocationTest extends OnSiteConsultationTestCase { +class OnSiteConsultationPickupLocationPostTest extends OnSiteConsultationPickupLocationTestCase { + protected $_json; + + public function setUp() { + parent::setUp(); + + $this->_mock_service + ->whenCalled('placeConsultationRequest') + ->with(79, 'OC2', 'RES_Liv', '0000007') + ->answers(true); + + $this->postDispatch('recherche/consultation-pickup-ajax/copy_id/799', + ['location' => 'RES_Liv']); + $this->_json = json_decode($this->_response->getBody()); + } + + + /** @test */ + public function titleShouldBeOnPlaceConsult() { + $this->assertEquals('Consultation sur place', $this->_json->title); + } + + + /** @test */ + public function contentShouldContainsYourBookingIsRegistered() { + $this->assertContains('Votre réservation est enregistrée', $this->_json->content); + } +} + + + + +class OnSiteConsultationPickupLocationPostErrorsTest extends OnSiteConsultationPickupLocationTestCase { + protected $_json; + + /** @test */ + public function withInexistingItemShouldDisplayError() { + $this->postDispatch('recherche/consultation-pickup-ajax/copy_id/666', + ['location' => 'RES_Liv']); + $json = json_decode($this->_response->getBody()); + $this->assertContains('L\'exemplaire n\'existe pas', $json->content); + } + + + /** @test */ + public function withErrorFromWebServiceShouldDisplayError() { + $this->_mock_service + ->whenCalled('placeConsultationRequest') + ->with(79, 'OC2', 'RES_Liv', '0000007') + ->answers(['erreur' => 'server burned']); + + $this->postDispatch('recherche/consultation-pickup-ajax/copy_id/799', + ['location' => 'RES_Liv']); + + $json = json_decode($this->_response->getBody()); + $this->assertContains('server burned', $json->content); + } +} + + + + class OnSiteConsultationNotLoggedPickupLocationTest extends OnSiteConsultationTestCase { protected $_json; @@ -411,11 +483,6 @@ class OnSiteConsultationReservationsTableTest extends OnSiteConsultationOneReser class OnSiteConsultationAbonneReservationsTest extends OnSiteConsultationTwoReservationsTest { - public function setUp() { - parent::setUp(); - } - - /** @test */ function aDivAbonneFicheShouldContainsVousAvezDeuxReservationsEnCours() { $this->dispatch('/abonne/fiche', true); -- GitLab