Skip to content
Snippets Groups Projects
Commit 278d482f authored by lbrun's avatar lbrun
Browse files

dev#25892_module_de_demande_de_consultation_sur_place: create request ws...

dev#25892_module_de_demande_de_consultation_sur_place: create request ws (getASRServicePoint / getASRItems)
parent fa471df5
Branches
Tags
8 merge requests!1553Master,!1502Master,!1501Stable,!1363Master,!1362Master,!1360Master,!1356Dev#25892 module de demande de consultation sur place,!1342Dev#25892 module de demande de consultation sur place
<?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_AvailableItem {
protected
$_barcode,
$_location,
$_service_points;
public function setBarcode($barcode) {
$this->_barcode = $barcode;
return $this;
}
public function setLocation($location) {
$this->_location = $location;
return $this;
}
public function addServicePoint($code) {
$this->_service_points[] = (new Class_WebService_SIGB_VSmart_ServicePoint())->setCode($code);
}
public function getBarcode() {
return $this->_barcode;
}
public function getLocation() {
return $this->_location;
}
public function getServicePoints() {
return $this->_service_points;
}
}
?>
\ No newline at end of file
...@@ -20,46 +20,38 @@ ...@@ -20,46 +20,38 @@
*/ */
class Class_WebService_SIGB_VSmart_ConsultableItemsReader { class Class_WebService_SIGB_VSmart_AvailableItemsReader {
protected $_barcode = ''; protected $_items = [];
protected $_location = ''; protected $_current_item;
protected $_servicepoint = '';
public static function newInstanceParse($xml) { public function getItemsFromXML($xml) {
$instance = new self();
return $instance->parse($xml);
}
public function parse($xml) {
$this->_xml_parser = Class_WebService_XMLParser::newInstance() $this->_xml_parser = Class_WebService_XMLParser::newInstance()
->setElementHandler($this) ->setElementHandler($this)
->parse($xml); ->parse($xml);
return $this; return $this->_items;
} }
public function endBarcode($data) { public function startItemResults() {
$this->_barcode = $data; $this->_current_item = new Class_WebService_SIGB_VSmart_AvailableItem();
$this->_items[] = $this->_current_item;
} }
public function endLocation($data) { public function endBarcode($data) {
$this->_location = $data; $this->_current_item->setBarcode($data);
} }
public function endServicePoint($data) { public function endLocation($data) {
$this->_servicepoint = $data; $this->_current_item->setLocation($data);
} }
public function getItems() { public function endServicePoint($data) {
return ['barcode' => $this->_barcode, $this->_current_item->addServicePoint($data);
'location' => $this->_location,
'servicepoint' => $this->_servicepoint];
} }
} }
......
...@@ -27,6 +27,7 @@ class Class_WebService_SIGB_VSmart_Service extends Class_WebService_SIGB_Abstrac ...@@ -27,6 +27,7 @@ class Class_WebService_SIGB_VSmart_Service extends Class_WebService_SIGB_Abstrac
protected $_soap_client; protected $_soap_client;
protected $_authenticate_wsdl; protected $_authenticate_wsdl;
protected $_popup_root; protected $_popup_root;
protected $_language = 'fre';
public static function newInstance() { public static function newInstance() {
return new self(); return new self();
...@@ -227,28 +228,23 @@ class Class_WebService_SIGB_VSmart_Service extends Class_WebService_SIGB_Abstrac ...@@ -227,28 +228,23 @@ class Class_WebService_SIGB_VSmart_Service extends Class_WebService_SIGB_Abstrac
} }
public function getConsultItems($id) { public function getAvailableItems($id) {
$ids = explode('/', $id); $ids = explode('/', $id);
$xml = $this->httpGet(['fu' => 'GetASRItems', $xml = $this->httpGet(['fu' => 'GetASRItems',
'database' => $ids[0], 'database' => $ids[0],
'bibrecord' => $ids[1]]); 'bibrecord' => $ids[1],
'language' => $this->_language]);
$items = Class_WebService_SIGB_VSmart_ConsultableItemsReader return (new Class_WebService_SIGB_VSmart_AvailableItemsReader())->getItemsFromXML($xml);
::newInstanceParse($xml)
->getItems();
return $items;
} }
public function getConsultServicePoints() { public function getServicePoints() {
$xml = $this->httpGet(['fu' => 'GetASRServicePoints']); $xml = $this->httpGet(['fu' => 'GetASRServicePoints',
'language' => $this->_language]);
$service_points = Class_WebService_SIGB_VSmart_ConsultableServicePointsReader
::newInstanceParse($xml)
->getServicePoints();
return $service_points; return (new Class_WebService_SIGB_VSmart_ServicePointsReader())
->getServicePointsFromXML($xml);
} }
} }
......
...@@ -20,11 +20,10 @@ ...@@ -20,11 +20,10 @@
*/ */
class Class_WebService_SIGB_Consultation_ServicePoint { class Class_WebService_SIGB_VSmart_ServicePoint {
protected
protected $_code; $_code,
protected $_label; $_label;
public function setCode($code) { public function setCode($code) {
$this->_code = $code; $this->_code = $code;
...@@ -47,5 +46,4 @@ class Class_WebService_SIGB_Consultation_ServicePoint { ...@@ -47,5 +46,4 @@ class Class_WebService_SIGB_Consultation_ServicePoint {
return $this->_label; return $this->_label;
} }
} }
?> ?>
\ No newline at end of file
...@@ -20,49 +20,34 @@ ...@@ -20,49 +20,34 @@
*/ */
class Class_WebService_SIGB_VSmart_ConsultableServicePointsReader { class Class_WebService_SIGB_VSmart_ServicePointsReader {
protected protected
$_xml_parser, $_service_points,
$_service_point, $_current_service;
$_current_item;
public static function newInstance() { public function getServicePointsFromXML($xml) {
return new self(); Class_WebService_XMLParser::newInstance()
} ->setElementHandler($this)
->parse($xml);
public function getServicePointFromXML($xml) {
$this->_xml_parser = Class_WebService_XMLParser::newInstance()
->setElementHandler($this)
->parse($xml);
return $this->_service_point; return $this->_service_points;
} }
public function startServicePoint() { public function startServicePoint() {
$_this->_current_item = new Class_WebService_SIGB_Consultation_ServicePoint(); $this->_current_service = new Class_WebService_SIGB_VSmart_ServicePoint();
} $this->_service_points[] = $this->_current_service;
public function endServicePoint($data) {
$this->_servicepoint = $data;
} }
public function endServicePointCode($data) { public function endServicePointCode($data) {
$this->_servicepoints['code'] = $data; $this->_current_service->setCode($data);
} }
public function endWording($data) { public function endWording($data) {
$this->_servicepoints['label'] = $data; $this->_current_service->setLabel($data);
}
public function getServicePoints() {
return var_dump($this->_servicepoints);
} }
} }
......
...@@ -328,7 +328,7 @@ class VSmartFixtures { ...@@ -328,7 +328,7 @@ class VSmartFixtures {
} }
public static function xmlConsultableItems() { public static function xmlAvailableItems() {
return return
'<VubisSmart> '<VubisSmart>
<Header> <Header>
...@@ -345,7 +345,7 @@ class VSmartFixtures { ...@@ -345,7 +345,7 @@ class VSmartFixtures {
} }
public static function xmlConsultableServicePoints() { public static function xmlServicePoints() {
return return
'<VubisSmart> '<VubisSmart>
<Header> <Header>
...@@ -354,7 +354,7 @@ class VSmartFixtures { ...@@ -354,7 +354,7 @@ class VSmartFixtures {
</Header> </Header>
<ServicePoint> <ServicePoint>
<ServicePointCode>RES_Liv</ServicePointCode> <ServicePointCode>RES_Liv</ServicePointCode>
<Wording>Livraison</Wording> <Wording>Salle patrimoine</Wording>
</ServicePoint> </ServicePoint>
<ServicePoint> <ServicePoint>
<ServicePointCode>RES_Mag</ServicePointCode> <ServicePointCode>RES_Mag</ServicePointCode>
......
...@@ -693,60 +693,96 @@ class VSmartServiceFunctionsTest extends Storm_Test_ModelTestCase { ...@@ -693,60 +693,96 @@ class VSmartServiceFunctionsTest extends Storm_Test_ModelTestCase {
class VSmartServiceConsultableItemsTest extends VSmartServiceTestCase { class VSmartServiceAvailableItemsTest extends VSmartServiceTestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$mock_web_client = $this->mock() $mock_web_client = $this->mock()
->whenCalled('open_url') ->whenCalled('open_url')
->with('http://46.20.169.8/production/VubisSmartHttpApi.csp?fu=GetASRItems&database=1&bibrecord=179920') ->with('http://46.20.169.8/production/VubisSmartHttpApi.csp?fu=GetASRItems&database=1&bibrecord=179920')
->answers(VSmartFixtures::xmlConsultableItems()); ->answers(VSmartFixtures::xmlAvailableItems());
$this->items = Class_WebService_SIGB_VSmart_Service::newInstance() $this->items = Class_WebService_SIGB_VSmart_Service::newInstance()
->setServerRoot('http://46.20.169.8/production') ->setServerRoot('http://46.20.169.8/production')
->setWebClient($mock_web_client) ->setWebClient($mock_web_client)
->getConsultItems('1/179920'); ->getAvailableItems('1/179920');
} }
/** @test */ /** @test */
public function getBarcodeShouldReturnMCP271095() { public function getBarcodeShouldReturnMCP271095() {
$this->assertEquals('MCP271095', $this->items['barcode']); $this->assertEquals('MCP271095', $this->items[0]->getBarcode());
} }
/** @test */ /** @test */
public function getServicePointShouldBeRES_Liv() { public function getLocationShouldBeRESMCFP() {
$this->assertEquals('RES_Liv', $this->items['servicepoint']); $this->assertEquals('RES/MCFP [MPBOU] BP-2430', $this->items[0]->getLocation());
} }
} }
class VSmartServiceConsultableServicePointsTest extends VSmartServiceTestCase { class VSmartServicePlaceRequestTest extends VSmartServiceTestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$mock_web_client = $this->mock() $mock_web_client = $this->mock()
->whenCalled('open_url') ->whenCalled('open_url')
->with('http://46.20.169.8/production/VubisSmartHttpApi.csp?fu=GetASRServicePoints') ->with('http://46.20.169.8/production/VubisSmartHttpApi.csp?fu=GetASRItems&database=1&bibrecord=179920&language=fre')
->answers(VSmartFixtures::xmlConsultableServicePoints()); ->answers(VSmartFixtures::xmlAvailableItems());
$this->servicepoints = Class_WebService_SIGB_VSmart_Service::newInstance() $this->items = Class_WebService_SIGB_VSmart_Service::newInstance()
->setServerRoot('http://46.20.169.8/production')
->setWebClient($mock_web_client)
->getAvailableItems('1/179920');
}
/** @test */
public function getBarcodeShouldReturnMCP271095() {
$this->assertEquals('MCP271095', $this->items[0]->getBarcode());
}
/** @test */
public function getLocationShouldReturnRESMCFP() {
$this->assertEquals('RES/MCFP [MPBOU] BP-2430', $this->items[0]->getLocation());
}
/** @test */
public function getFirstItemServicePointCodeShouldReturnRES_Liv() {
$this->assertEquals('RES_Liv', $this->items[0]->getServicePoints()[0]->getCode());
}
}
class VSmartServiceAvailableServicePointsTest 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&language=fre')
->answers(VSmartFixtures::xmlServicePoints());
$this->service_points = Class_WebService_SIGB_VSmart_Service::newInstance()
->setServerRoot('http://46.20.169.8/production') ->setServerRoot('http://46.20.169.8/production')
->setWebClient($mock_web_client) ->setWebClient($mock_web_client)
->getConsultServicePoints(); ->getServicePoints();
} }
/** @test */ /** @test */
public function getFirstServicePointCodeShouldReturnRES_Liv() { public function getFirstServicePointCodeShouldReturnRES_Liv() {
$this->assertEquals('RES_Liv', $this->servicepoints[0]['code']); $this->assertEquals('RES_Liv', $this->service_points[0]->getCode());
} }
/** @test */ /** @test */
public function getSecondServicePointLabelShouldBeMagasin() { public function getSecondServicePointLabelShouldBeMagasin() {
$this->assertEquals('Magasin', $this->servicepoints[1]['label']); $this->assertEquals('Magasin', $this->service_points[1]->getLabel());
} }
} }
?> ?>
\ No newline at end of file
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