diff --git a/VERSIONS_WIP/60523 b/VERSIONS_WIP/60523 new file mode 100644 index 0000000000000000000000000000000000000000..a86d6721c299946fb98ea3e85440d8abe7270b10 --- /dev/null +++ b/VERSIONS_WIP/60523 @@ -0,0 +1 @@ + - ticket #60523 : SIGB Nanook : les sites de retraits proposés lors de la réservations suivent les règles de circulations définies dans le SIBG \ No newline at end of file diff --git a/library/Class/WebService/SIGB/AbstractRESTService.php b/library/Class/WebService/SIGB/AbstractRESTService.php index d7415cddd5dd016aec4832bc49916fb5387db89a..a485b4b9bf046f37d2375b1d3e2f2409fdde15a9 100644 --- a/library/Class/WebService/SIGB/AbstractRESTService.php +++ b/library/Class/WebService/SIGB/AbstractRESTService.php @@ -259,7 +259,18 @@ abstract class Class_WebService_SIGB_AbstractRESTService extends Class_WebServic * @return array */ protected function _getNetworkError() { - return $this->_error($this->_('Service indisponible')); + return $this->_error($this->_getNetworkErrorLabel()); + } + + + protected function _getNetworkErrorLabel() { + return $this->_('Service indisponible'); + } + + + protected function _isNetworkError($result) { + return (false === $result['statut']) + && ($this->_getNetworkErrorLabel() == $result['erreur']); } diff --git a/library/Class/WebService/SIGB/Nanook/PickupLocationsReader.php b/library/Class/WebService/SIGB/Nanook/PickupLocationsReader.php new file mode 100644 index 0000000000000000000000000000000000000000..dc5269e6a486adced199f33c89967fcd03ec3e6f --- /dev/null +++ b/library/Class/WebService/SIGB/Nanook/PickupLocationsReader.php @@ -0,0 +1,65 @@ +<?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 Class_WebService_SIGB_Nanook_PickupLocationsReader { + protected + $_locations, + $_current_location; + + public function read($xml) { + $this->_locations=[]; + + (new Class_WebService_FasterXMLParser()) + ->setElementHandler($this) + ->parse($xml); + + return $this; + } + + + public function startpickup_location($attributes) { + $this->_current_location = new Class_Entity(); + } + + + public function endpickup_location($data) { + if (($id = $this->_current_location->getId()) + && ($label = $this->_current_location->getLabel())) + + $this->_locations[$id] = $label; + } + + + public function endpickup_location_label($data) { + $this->_current_location->setLabel($data); + } + + + public function endpickup_location_id($data) { + $this->_current_location->setId($data); + } + + + public function getLocations() { + return $this->_locations; + } +} diff --git a/library/Class/WebService/SIGB/Nanook/Service.php b/library/Class/WebService/SIGB/Nanook/Service.php index 7c38e2365de84bb67e375b18f7ff02963e6de69c..9f043538d5b19bb93e21ffb85c182597e1d9f5d4 100644 --- a/library/Class/WebService/SIGB/Nanook/Service.php +++ b/library/Class/WebService/SIGB/Nanook/Service.php @@ -21,6 +21,7 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_AbstractRESTService { protected $_provide_suggest = false, + $_provide_pickup_locations = null, $_error_codes = []; @@ -28,8 +29,7 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac $this->_error_codes = ['MaxHoldsOnRecordReached' => $this->_('Réservation impossible, nombre maximum de réservataires par exemplaire atteint.'), 'PatronNoSubscription' => $this->_('Réservation impossible, abonnement échu.'), 'PatronHoldRecordForbidden' => $this->_('Pas de droit de réservation pour ce document.'), - 'PatronMaxHoldsReached' => $this->_('Qutotas atteint pour ce type de document.'), - + 'PatronMaxHoldsReached' => $this->_('Quotas atteint pour ce type de document.'), 'PatronHoldNoveltyRecordForbidden' => $this->_('Pas de droit de réservation pour cette nouveauté.'), 'PatronMaxHoldsNoveltyReached' => $this->_('(quotas max pour les nouveautés)'), 'OpacAvailableItemNotHoldable' => $this->_('Document disponible : Pas de droit de réservation d\'un document disponible depuis l\'Opac.'), @@ -38,7 +38,10 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac 'RenewMaxDateReached' => $this->_('Prolongation impossible, le délai est dépassé.'), 'RenewNoSubscription' => $this->_('Prolongation impossible, votre abonnement est échu.'), 'RenewRecordForbidden' => $this->_('Prolongation interdite pour ce type de document.'), - 'MaxRenewReached' => $this->_('Prolongation impossible, le nombre maximum de prolongations est atteint.')]; + 'MaxRenewReached' => $this->_('Prolongation impossible, le nombre maximum de prolongations est atteint.'), + 'RecordNotFound' => $this->_('Notice non trouvée'), + 'PatronNotFound' => $this->_('Abonné non trouvé'), + 'HoldLocationOrderNotFound' => $this->_('Erreur paramétrage priorité site de retrait')]; } @@ -329,4 +332,34 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac protected function _getErrorLabel($code) { return $this->_error_codes[$code]; } + + + public function providesPickupLocations() { + if (null !== $this->_provide_pickup_locations) + return $this->_provide_pickup_locations; + + $result = $this->ilsdiAction('GetPickupLocation', + ['bibId' => 0, 'patronId' => 0], + 'error', ''); + + return $this->_provide_pickup_locations = !$this->_isNetworkError($result); + } + + + public function pickupLocationsFor($user, $item) { + if (!$this->providesPickupLocations() || !$user | !$item) + return parent::pickupLocationsFor($user, $item); + + $params = ['service' => 'GetPickupLocation', + 'bibId' => $item->getIdOrigine(), + 'patronId' => $user->getIdSigb()]; + + $xml = $this->httpGet($params); + if ($this->_getTagData($xml, 'error')) + return []; + + return (new Class_WebService_SIGB_Nanook_PickupLocationsReader()) + ->read($xml) + ->getLocations(); + } } \ No newline at end of file diff --git a/tests/fixtures/NanookFixtures.php b/tests/fixtures/NanookFixtures.php index 3311a44cb41315b6e077adbdad83676ede77ffd5..3edca036e7e880db0d0c13386240c90380225bd6 100644 --- a/tests/fixtures/NanookFixtures.php +++ b/tests/fixtures/NanookFixtures.php @@ -556,5 +556,35 @@ class NanookFixtures { public static function createSuggestFuError() { return '<CreateSuggest><error>CreateSuggestError</error></CreateSuggest>'; } -} -?> \ No newline at end of file + + + public static function pickupLocationsPingAnswer() { + return '<?xml version="1.0" encoding="UTF-8"?> + <GetPickupLocation> + <error>RecordNotFound</error> + </GetPickupLocation>'; + } + + + public static function pickupLocationsOkAnswer() { + return '<?xml version="1.0" encoding="UTF-8"?> + <pickup_locations> + <pickup_location> + <pickup_location_label>First library</pickup_location_label> + <pickup_location_id>1</pickup_location_id> + </pickup_location> + <pickup_location> + <pickup_location_label>Second library</pickup_location_label> + <pickup_location_id>2</pickup_location_id> + </pickup_location> + </pickup_locations>'; + } + + + public static function pickupLocationsErrorAnswer() { + return '<?xml version="1.0" encoding="UTF-8"?> + <GetPickupLocation> + <error>PatronNotFound</error> + </GetPickupLocation>'; + } +} \ No newline at end of file diff --git a/tests/library/Class/WebService/SIGB/NanookTest.php b/tests/library/Class/WebService/SIGB/NanookTest.php index eecc7b15e0191cb188a47b9b487960a5334fefc7..8f85be61f62f187e4f0d698f8a2332cec509ebf4 100644 --- a/tests/library/Class/WebService/SIGB/NanookTest.php +++ b/tests/library/Class/WebService/SIGB/NanookTest.php @@ -21,7 +21,7 @@ include_once 'tests/fixtures/NanookFixtures.php'; -class NanookGetServiceTest extends Storm_Test_ModelTestCase { +class NanookGetServiceTest extends ModelTestCase { public function setUp() { Class_WebService_SIGB_Nanook::reset(); $this->service = Class_WebService_SIGB_Nanook::getService(array('url_serveur' => 'http://localhost:8080/afi_Nanook/ilsdi/')); @@ -61,7 +61,7 @@ class NanookGetServiceTest extends Storm_Test_ModelTestCase { -abstract class NanookTestCase extends Storm_Test_ModelTestCase { +abstract class NanookTestCase extends ModelTestCase { /** @var PHPUnit_Framework_MockObject_MockObject */ protected $_mock_web_client; @@ -1138,7 +1138,6 @@ class NanookSaveEmprunteurRecordNotFoundTest extends NanookTestCase { class NanookSaveEmprunteurUpdatePatronErrorTest extends NanookTestCase { - public function setup() { parent::setup(); $this->_mock_web_client @@ -1158,9 +1157,65 @@ class NanookSaveEmprunteurUpdatePatronErrorTest extends NanookTestCase { $this->_emprunteur = $this->_service->saveEmprunteur($this->_crystel); } + /** @test **/ public function christelDelPeyrouxShoudlNotBeValidWithUpdatePatron() { $this->assertFalse($this->_emprunteur->isValid()); } +} + + + +class NanookPickupLocationsInactiveTest extends NanookTestCase { + /** @test */ + public function shouldNotProvidePickupLocations() { + $this->assertFalse($this->_service->providesPickupLocations()); + } +} + + + +class NanookPickupLocationsActiveTest extends NanookTestCase { + public function setUp() { + parent::setUp(); + $this->_mock_web_client + ->whenCalled('open_url') + ->with('http://localhost:8080/afi_Nanook/ilsdi/service/GetPickupLocation/bibId/0/patronId/0') + ->answers(NanookFixtures::pickupLocationsPingAnswer()) + + ->whenCalled('open_url') + ->with('http://localhost:8080/afi_Nanook/ilsdi/service/GetPickupLocation/bibId/2/patronId/9') + ->answers(NanookFixtures::pickupLocationsOkAnswer()) + + ->whenCalled('open_url') + ->with('http://localhost:8080/afi_Nanook/ilsdi/service/GetPickupLocation/bibId/999/patronId/9') + ->answers(NanookFixtures::pickupLocationsErrorAnswer()) + + ->beStrict(); + } + + + /** @test */ + public function shouldProvidePickupLocations() { + $this->assertTrue($this->_service->providesPickupLocations()); + } + + /** @test */ + public function locationsForRecord2AndPatron9ShouldBeFirstAndSecondLibrary() { + $user = (new Class_Entity)->setIdSigb(9); + $item = (new Class_Entity)->setIdOrigine(2); + + $this->assertEquals([1 => 'First library', 2 => 'Second library'], + $this->_service->pickupLocationsFor($user, $item)); + } + + + /** @test */ + public function locationsForRecord999AndPatron9ShouldBeEmpty() { + $user = (new Class_Entity)->setIdSigb(9); + $item = (new Class_Entity)->setIdOrigine(999); + + $this->assertEquals([], $this->_service->pickupLocationsFor($user, $item)); + } }