From e72d0af263196262fc322c7fc667c61405ae3371 Mon Sep 17 00:00:00 2001 From: Ghislain Loas <ghislo@sandbox.pergame.net> Date: Wed, 14 Oct 2015 17:30:00 +0200 Subject: [PATCH] dev #30918 start implementing webservice calls --- VERSIONS_WIP/30918 | 1 + library/Class/WebService/SIGB/Nanook.php | 2 +- .../SIGB/Nanook/PatronInfoReader.php | 44 +++--- .../Class/WebService/SIGB/Nanook/Service.php | 36 +++++ ...nneControllerSuggestionAchatNanookTest.php | 130 ++++++++++++++++++ tests/fixtures/NanookFixtures.php | 84 +++++++++++ 6 files changed, 278 insertions(+), 19 deletions(-) create mode 100644 VERSIONS_WIP/30918 create mode 100644 tests/application/modules/opac/controllers/AbonneControllerSuggestionAchatNanookTest.php create mode 100644 tests/fixtures/NanookFixtures.php diff --git a/VERSIONS_WIP/30918 b/VERSIONS_WIP/30918 new file mode 100644 index 00000000000..fdd283f3633 --- /dev/null +++ b/VERSIONS_WIP/30918 @@ -0,0 +1 @@ + - ticket #30918 : Développer l'interface suggestion d'achat vers WS Nanook : réalisation \ No newline at end of file diff --git a/library/Class/WebService/SIGB/Nanook.php b/library/Class/WebService/SIGB/Nanook.php index 9dcb7d5d1a6..50993f34468 100644 --- a/library/Class/WebService/SIGB/Nanook.php +++ b/library/Class/WebService/SIGB/Nanook.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 Class_WebService_SIGB_Nanook extends Class_WebService_SIGB_Abstract {} ?> \ No newline at end of file diff --git a/library/Class/WebService/SIGB/Nanook/PatronInfoReader.php b/library/Class/WebService/SIGB/Nanook/PatronInfoReader.php index 57d9203bcaa..0ca3bb7abaa 100644 --- a/library/Class/WebService/SIGB/Nanook/PatronInfoReader.php +++ b/library/Class/WebService/SIGB/Nanook/PatronInfoReader.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 Class_WebService_SIGB_Nanook_PatronInfoReader extends Class_WebService_SIGB_AbstractILSDIPatronInfoReader{ /** @@ -52,62 +52,62 @@ class Class_WebService_SIGB_Nanook_PatronInfoReader extends Class_WebService_SIG } - /** - * @param string $data + /** + * @param string $data */ public function endBarcode($data) { $this->_emprunteur->setCodeBarres($data); } - /** - * @param string $data + /** + * @param string $data */ public function endAddress($data) { $this->_emprunteur->setAdresse($data); } - /** - * @param string $data + /** + * @param string $data */ public function endTown($data) { $this->_emprunteur->setVille($data); } - /** - * @param string $data + /** + * @param string $data */ public function endZipCode($data) { $this->_emprunteur->setCodePostal($data); } - /** - * @param string $data + /** + * @param string $data */ public function endPhoneNumber($data) { $this->_emprunteur->setTelephone($data); } - /** - * @param string $data + /** + * @param string $data */ public function endDisplayOrder($data) { $this->_emprunteur->setOrdre($data); } - /** - * @param string $data + /** + * @param string $data */ public function endBirthDate($data) { $this->_emprunteur->setDateNaissance($data); } - + /** * @param string $data */ @@ -143,8 +143,8 @@ class Class_WebService_SIGB_Nanook_PatronInfoReader extends Class_WebService_SIG } - /** - * @param string $data + /** + * @param string $data */ public function endAvailable($data) { if (1 == (int)$data) { @@ -161,5 +161,13 @@ class Class_WebService_SIGB_Nanook_PatronInfoReader extends Class_WebService_SIG if ('' != $data) $this->_currentHold->setEtat('Pas disponible avant le ' . $data); } + + + + + + public function getSuggestions() { + return []; + } } ?> \ No newline at end of file diff --git a/library/Class/WebService/SIGB/Nanook/Service.php b/library/Class/WebService/SIGB/Nanook/Service.php index b15b4d2d4f3..f6ff2550f80 100644 --- a/library/Class/WebService/SIGB/Nanook/Service.php +++ b/library/Class/WebService/SIGB/Nanook/Service.php @@ -160,5 +160,41 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac return $this->getServerRoot() . implode('/', $parts); } + + + public function providesSuggestions() { + return true; + } + + + public function suggestionsOf($user) { + if (!$this->ilsdiAuthenticatePatron($user)) + return $this->_error($this->_('Échec de l\'authentification par le webservice')); + + return $this->getSuggestionsFromilsdiPatronInfo(['patronId' => $user->getIdSigb()], + Class_WebService_SIGB_Nanook_PatronInfoReader::newInstance()); + + } + + + protected function getSuggestionsFromilsdiPatronInfo($params, $reader, $error_tag='error') { + $emprunteur = Class_WebService_SIGB_Emprunteur::newInstance()->setService($this); + $params = array_merge(['service' => 'GetPatronInfo'], + $params); + + $xml = $this->httpGet($params); + + if (0 === strpos($xml, '<html>')) + return []; + + if ($this->_getTagData($xml, $error_tag)) + return []; + + return $reader + ->setEmprunteur($emprunteur) + ->parseXML($xml) + ->getSuggestions(); + + } } ?> \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/AbonneControllerSuggestionAchatNanookTest.php b/tests/application/modules/opac/controllers/AbonneControllerSuggestionAchatNanookTest.php new file mode 100644 index 00000000000..7e97f8698ac --- /dev/null +++ b/tests/application/modules/opac/controllers/AbonneControllerSuggestionAchatNanookTest.php @@ -0,0 +1,130 @@ +<?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 + */ + +require_once 'tests/fixtures/NanookFixtures.php'; + +abstract class AbstractAbonneControllerSuggestionAchatNanookTestCase extends AbstractControllerTestCase { + protected + $_storm_default_to_volatile = true, + $_francis; + + public function setUp() { + parent::setUp(); + + $logger = $this->mock() + ->whenCalled('log')->answers(true) + + ->whenCalled('logError') + ->willDo( + function($url, $message) { + throw new RuntimeException($url . ' :: ' . $message); + }); + + Class_WebService_SIGB_AbstractService::setLogger($logger); + + + $sigb_conf = $this->fixture('Class_IntBib', + ['id' => 3, + 'comm_params' => ['url_serveur' => ''], + 'comm_sigb' => Class_IntBib::COM_NANOOK]); + + $this->fixture('Class_Bib', ['id' => 12, + 'libelle' => 'Tatim bib', + 'int_bib' => $sigb_conf]); + + $this->_francis = $this->fixture('Class_Users', ['id' => 3, + 'login' => 'francis', + 'password' => 'test', + 'int_bib' => $sigb_conf]); + + ZendAfi_Auth::getInstance()->logUser($this->_francis); + + $this->mock_web_client = $this->mock(); + $this->mock_web_client + ->whenCalled('open_url') + ->with('http:///service/AuthenticatePatron/username/francis/password/test') + ->answers(NanookFixtures::authenticatePatronResponse()) + + ->whenCalled('open_url') + ->with('http:///service/GetPatronInfo/patronId/187') + ->answers(NanookFixtures::patronInfoResponse()) + + ->beStrict(); + + $sigb_comm = Class_IntBib::find(3)->getSIGBComm(); + $sigb_comm->setWebClient($this->mock_web_client); + + } +} + + + +class AbonneControllerSuggestionAchatNanookListTest extends AbstractAbonneControllerSuggestionAchatNanookTestCase { + + public function setUp() { + parent::setUp(); + $this->dispatch('/opac/abonne/suggestion-achat', true); + } + + + /** @test */ + public function pageShouldContainsSuggestionFromNanook() { + $this->assertXPathContentContains('//div', 'some suggestions', $this->_response->getBody()); + } +} + + + +class AbonneControllerSuggestionAchatNanookAddTest extends AbstractAbonneControllerSuggestionAchatNanookTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + $this->dispatch('/opac/abonne/suggestion-achat-add', true); + } + + + /** @test */ + public function formShouldContainsNanookElement() { + $this->assertXPathContentContains('//div', 'some suggestions', $this->_response->getBody()); + } +} + + + +class AbonneControllerSuggestionAchatNanookAddPostTest extends AbstractAbonneControllerSuggestionAchatNanookTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + $this->postDispatch('/opac/abonne/suggestion-achat-add', ['titre' => 'fu', + 'auteur' => 'mf', + 'isbn' => '2-07-0541 27_4', + 'description_url' => 'bokeh-kibrary-portail.org', + 'commentaire' => 'no']); + } + + + /** @test */ + public function suggestionShouldHaveBeenSend() { + $this->assertContains(['suggestion'], $this->_francis->getSuggestionAchat()); + } +} diff --git a/tests/fixtures/NanookFixtures.php b/tests/fixtures/NanookFixtures.php new file mode 100644 index 00000000000..7e7210cb893 --- /dev/null +++ b/tests/fixtures/NanookFixtures.php @@ -0,0 +1,84 @@ +<?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 NanookFixtures { + + public static function patronInfoResponse() { + return ' + <getpatroninfo> + <patronid> + 3358 + </patronid> + <barcode> + 01 + </barcode> + <lastname> + ALBATOR + </lastname> + <firstname> + Lucien + </firstname> + <displayorder> + 1 + </displayorder> + <birthdate> + 1950-01-01 + </birthdate> + <phonenumber></phonenumber> + <town></town> + <zipcode></zipcode> + <address></address> + <enddate> + 2020-10-05 + </enddate> + <mail></mail> + <loans></loans> + <holds></holds> + <suggests> + <suggest> + <site> + 2 + </site> + <status> + En attente + </status> + <title> + test + </title> + <author> + test + </author> + <isbnean></isbnean> + <desclink></desclink> + <comment></comment> + </suggest> + </suggests> + </getpatroninfo> +'; + } + + + public static function authenticatePatronResponse() { + return '<AuthenticatePatron><patronId>187</patronId></AuthenticatePatron>'; + } +} +?> \ No newline at end of file -- GitLab