Skip to content
Snippets Groups Projects
Commit c106b5b1 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

Merge branch...

Merge branch 'dev#60523_contractuel_circulation_documents_entre_certains_sites_commande_bresles_maritime' into 'master'

Dev#60523 contractuel circulation documents entre certains sites commande bresles maritime

See merge request !2206
parents 9b913f72 d8292293
Branches
Tags
2 merge requests!2334Master,!2206Dev#60523 contractuel circulation documents entre certains sites commande bresles maritime
Pipeline #1787 failed with stage
in 11 minutes and 27 seconds
- 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
......@@ -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']);
}
......
<?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;
}
}
......@@ -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
......@@ -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
......@@ -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));
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment