diff --git a/library/Class/WebService/SIGB/Consultation/ServicePoint.php b/library/Class/WebService/SIGB/Consultation/ServicePoint.php new file mode 100644 index 0000000000000000000000000000000000000000..9cd3c342e0e6aded6cb9c10b4eb440fd89ba27d8 --- /dev/null +++ b/library/Class/WebService/SIGB/Consultation/ServicePoint.php @@ -0,0 +1,51 @@ +<?php +/** + * Copyright (c) 2012-2014, 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_Consultation_ServicePoint { + + protected $_code; + protected $_label; + + + public function setCode($code) { + $this->_code = $code; + return $this; + } + + + public function setLabel($label) { + $this->_label = $label; + return $this; + } + + + public function getCode() { + return $this->_code; + } + + + public function getLabel() { + return $this->_label; + } +} + +?> \ No newline at end of file diff --git a/library/Class/WebService/SIGB/VSmart/ConsultableItemsReader.php b/library/Class/WebService/SIGB/VSmart/ConsultableItemsReader.php new file mode 100644 index 0000000000000000000000000000000000000000..2030e6a101dd50c76e3c63031fef4a6dbab44303 --- /dev/null +++ b/library/Class/WebService/SIGB/VSmart/ConsultableItemsReader.php @@ -0,0 +1,66 @@ +<?php +/** + * Copyright (c) 2012-2014, 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_VSmart_ConsultableItemsReader { + protected $_barcode = ''; + protected $_location = ''; + protected $_servicepoint = ''; + + + public static function newInstanceParse($xml) { + $instance = new self(); + return $instance->parse($xml); + } + + + public function parse($xml) { + $this->_xml_parser = Class_WebService_XMLParser::newInstance() + ->setElementHandler($this) + ->parse($xml); + + return $this; + } + + + public function endBarcode($data) { + $this->_barcode = $data; + } + + + public function endLocation($data) { + $this->_location = $data; + } + + + public function endServicePoint($data) { + $this->_servicepoint = $data; + } + + + public function getItems() { + return ['barcode' => $this->_barcode, + 'location' => $this->_location, + 'servicepoint' => $this->_servicepoint]; + } +} + +?> \ No newline at end of file diff --git a/library/Class/WebService/SIGB/VSmart/ConsultableServicePointsReader.php b/library/Class/WebService/SIGB/VSmart/ConsultableServicePointsReader.php new file mode 100644 index 0000000000000000000000000000000000000000..f759a5ea22503fc4999b625db9103cb96cc3fe4b --- /dev/null +++ b/library/Class/WebService/SIGB/VSmart/ConsultableServicePointsReader.php @@ -0,0 +1,69 @@ +<?php +/** + * Copyright (c) 2012-2014, 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_VSmart_ConsultableServicePointsReader { + protected + $_xml_parser, + $_service_point, + $_current_item; + + + public static function newInstance() { + return new self(); + } + + + public function getServicePointFromXML($xml) { + $this->_xml_parser = Class_WebService_XMLParser::newInstance() + ->setElementHandler($this) + ->parse($xml); + + return $this->_service_point; + } + + + public function startServicePoint() { + $_this->_current_item = new Class_WebService_SIGB_Consultation_ServicePoint(); + } + + + public function endServicePoint($data) { + $this->_servicepoint = $data; + } + + + public function endServicePointCode($data) { + $this->_servicepoints['code'] = $data; + } + + + public function endWording($data) { + $this->_servicepoints['label'] = $data; + } + + + public function getServicePoints() { + return var_dump($this->_servicepoints); + } +} + +?> \ No newline at end of file diff --git a/library/Class/WebService/SIGB/VSmart/Service.php b/library/Class/WebService/SIGB/VSmart/Service.php index a3ad03fe41bb9778f23aa6c5101eb572b2ee5d98..fd192b29a552c9d4c623d92bf28155fd36a1bcc5 100644 --- a/library/Class/WebService/SIGB/VSmart/Service.php +++ b/library/Class/WebService/SIGB/VSmart/Service.php @@ -225,6 +225,31 @@ class Class_WebService_SIGB_VSmart_Service extends Class_WebService_SIGB_Abstrac 'BorrowerId' => $user->getLogin(), 'ItemId' => $pret_id)); } + + + public function getConsultItems($id) { + $ids = explode('/', $id); + $xml = $this->httpGet(['fu' => 'GetASRItems', + 'database' => $ids[0], + 'bibrecord' => $ids[1]]); + + $items = Class_WebService_SIGB_VSmart_ConsultableItemsReader + ::newInstanceParse($xml) + ->getItems(); + + return $items; + } + + + public function getConsultServicePoints() { + $xml = $this->httpGet(['fu' => 'GetASRServicePoints']); + + $service_points = Class_WebService_SIGB_VSmart_ConsultableServicePointsReader + ::newInstanceParse($xml) + ->getServicePoints(); + + return $service_points; + } } diff --git a/tests/library/Class/WebService/SIGB/VSmartFixtures.php b/tests/library/Class/WebService/SIGB/VSmartFixtures.php index 5dce65080cb2eddc909fb42b9375baf294bfb790..24a5a5ee0f719ee62b67ea2016ec00a2c81b374a 100644 --- a/tests/library/Class/WebService/SIGB/VSmartFixtures.php +++ b/tests/library/Class/WebService/SIGB/VSmartFixtures.php @@ -16,7 +16,7 @@ * * 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 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class VSmartFixtures { @@ -326,4 +326,40 @@ class VSmartFixtures { </zs:records> </zs:searchRetrieveResponse>'; } -} + + + public static function xmlConsultableItems() { + return + '<VubisSmart> + <Header> + <Function>GetASRItems</Function> + <ErrorCode>0</ErrorCode> + </Header> + <ItemResults> + <Barcode>MCP271095</Barcode> + <Location>RES/MCFP [MPBOU] BP-2430</Location> + <ServicePoints><ServicePoint>RES_Liv</ServicePoint> + </ServicePoints> + </ItemResults> + </VubisSmart>'; + } + + + public static function xmlConsultableServicePoints() { + return + '<VubisSmart> + <Header> + <Function>GetASRServicePoints</Function> + <ErrorCode>0</ErrorCode> + </Header> + <ServicePoint> + <ServicePointCode>RES_Liv</ServicePointCode> + <Wording>Livraison</Wording> + </ServicePoint> + <ServicePoint> + <ServicePointCode>RES_Mag</ServicePointCode> + <Wording>Magasin</Wording> + </ServicePoint> + </VubisSmart>'; + } +} \ No newline at end of file diff --git a/tests/library/Class/WebService/SIGB/VSmartTest.php b/tests/library/Class/WebService/SIGB/VSmartTest.php index 0a03a19521927308d9eb97f9398233b0582e62ac..f1015ebf1f3f9c8d9a15bdcc318506ba5b179ef0 100644 --- a/tests/library/Class/WebService/SIGB/VSmartTest.php +++ b/tests/library/Class/WebService/SIGB/VSmartTest.php @@ -688,8 +688,65 @@ class VSmartServiceFunctionsTest extends Storm_Test_ModelTestCase { $this->assertFalse($this->service->getExemplaire('2/234', '987')->isValid()); } +} + + + + +class VSmartServiceConsultableItemsTest extends VSmartServiceTestCase { + public function setUp() { + parent::setUp(); + $mock_web_client = $this->mock() + ->whenCalled('open_url') + ->with('http://46.20.169.8/production/VubisSmartHttpApi.csp?fu=GetASRItems&database=1&bibrecord=179920') + ->answers(VSmartFixtures::xmlConsultableItems()); + + $this->items = Class_WebService_SIGB_VSmart_Service::newInstance() + ->setServerRoot('http://46.20.169.8/production') + ->setWebClient($mock_web_client) + ->getConsultItems('1/179920'); + } + + + /** @test */ + public function getBarcodeShouldReturnMCP271095() { + $this->assertEquals('MCP271095', $this->items['barcode']); + } + + /** @test */ + public function getServicePointShouldBeRES_Liv() { + $this->assertEquals('RES_Liv', $this->items['servicepoint']); + } } + + +class VSmartServiceConsultableServicePointsTest extends VSmartServiceTestCase { + public function setUp() { + parent::setUp(); + $mock_web_client = $this->mock() + ->whenCalled('open_url') + ->with('http://46.20.169.8/production/VubisSmartHttpApi.csp?fu=GetASRServicePoints') + ->answers(VSmartFixtures::xmlConsultableServicePoints()); + + $this->servicepoints = Class_WebService_SIGB_VSmart_Service::newInstance() + ->setServerRoot('http://46.20.169.8/production') + ->setWebClient($mock_web_client) + ->getConsultServicePoints(); + } + + + /** @test */ + public function getFirstServicePointCodeShouldReturnRES_Liv() { + $this->assertEquals('RES_Liv', $this->servicepoints[0]['code']); + } + + + /** @test */ + public function getSecondServicePointLabelShouldBeMagasin() { + $this->assertEquals('Magasin', $this->servicepoints[1]['label']); + } +} ?> \ No newline at end of file