From 957a1fcf3e585857edb5560709f0634f36b9be43 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Thu, 1 Mar 2018 11:21:18 +0100 Subject: [PATCH] dev #62394 fix rt comments --- .../WebService/SIGB/AbstractRESTService.php | 21 ++++++++++++------- .../Class/WebService/SIGB/Koha/Service.php | 10 +++------ .../Class/WebService/SIGB/Nanook/Service.php | 2 +- .../Class/WebService/SIGB/KohaTest.php | 19 ++++------------- .../Class/WebService/SIGB/NanookTest.php | 7 +++++++ 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/library/Class/WebService/SIGB/AbstractRESTService.php b/library/Class/WebService/SIGB/AbstractRESTService.php index 265f634ded8..5fd75ff2e1f 100644 --- a/library/Class/WebService/SIGB/AbstractRESTService.php +++ b/library/Class/WebService/SIGB/AbstractRESTService.php @@ -249,15 +249,22 @@ abstract class Class_WebService_SIGB_AbstractRESTService extends Class_WebServic public function ilsdiCheckXml($xml, $error_tag, $error_message) { + return ($error = $this->_getErrorMessage($xml, $error_tag, $error_message)) + ? $this->_error($error) + : $this->_success(); + } + + + protected function _getErrorMessage($xml, $tag, $message) { if (!$xml) - return $this->_getNetworkError(); - if (0 === strpos($xml, '<html>')) - return $this->_getNetworkError(); + return $this->_getNetworkErrorLabel(); - if ($error_code = $this->_findErrorTagInXml($xml, $error_tag)) - return $this->_getErrorFromCode($error_code, $error_message); + if (0 === strpos($xml, '<html>')) + return $this->_getNetworkErrorLabel(); - return $this->_success(); + return ($error = $this->_findErrorTagInXml($xml, $tag)) + ? $this->_getErrorFromCode($error, $message) + : null; } @@ -281,6 +288,6 @@ abstract class Class_WebService_SIGB_AbstractRESTService extends Class_WebServic protected function _getErrorFromCode($error_code, $default_message) { - return $this->_error($default_message); + return $default_message; } } \ No newline at end of file diff --git a/library/Class/WebService/SIGB/Koha/Service.php b/library/Class/WebService/SIGB/Koha/Service.php index eeb65f86203..1890f779e5a 100644 --- a/library/Class/WebService/SIGB/Koha/Service.php +++ b/library/Class/WebService/SIGB/Koha/Service.php @@ -41,12 +41,7 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR } - protected function _getErrorFromCode($error_code, $default_message) { - return parent::_getErrorFromCode($error_code, $this->_getErrorMessage($error_code,$default_message)); - } - - - protected function _getErrorMessage($code, $default_message) { + protected function _getErrorFromCode($code, $default_message) { $error_messages = [ 'ageRestricted' => $this->_('limitation sur l\'âge'), 'damaged' => $this->_('exemplaire endommagé'), @@ -72,11 +67,12 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR protected function _findErrorTagInXml($xml,$tag) { - if ($error = $this->_getTagData($xml,$tag)) + if ($error = $this->_getTagData($xml, $tag)) return $error; if ($success = $this->_getTagData($xml,'success')) return 0 == $success; + return false !== strpos($xml, $tag) ; } diff --git a/library/Class/WebService/SIGB/Nanook/Service.php b/library/Class/WebService/SIGB/Nanook/Service.php index 5e8b3096d61..56acf358b34 100644 --- a/library/Class/WebService/SIGB/Nanook/Service.php +++ b/library/Class/WebService/SIGB/Nanook/Service.php @@ -352,7 +352,7 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac protected function _getErrorFromCode($error_code, $message) { if(array_key_exists($error_code, $this->_error_codes)) $message = $this->_getErrorLabel($error_code); - return $this->_error($message); + return $message; } diff --git a/tests/library/Class/WebService/SIGB/KohaTest.php b/tests/library/Class/WebService/SIGB/KohaTest.php index 132b06adbb3..6b578a8e9f2 100644 --- a/tests/library/Class/WebService/SIGB/KohaTest.php +++ b/tests/library/Class/WebService/SIGB/KohaTest.php @@ -1104,7 +1104,7 @@ class KohaServicePatroninfoReaderWithNoLibTest extends KohaTestCase { ->setLogin('lafond') ->setPassword('afi') ->setIdabon('012345')); - } + } /** @test */ @@ -1196,7 +1196,6 @@ class KohaAuthenticateWSTest extends KohaTestCase { class KohaErrorMessagesOperationTest extends KohaTestCase { public function setUp() { parent::setUp(); - $this->_lafond = $this->fixture('Class_Users', ['id' => 67, 'login' => 'lafond', @@ -1207,7 +1206,6 @@ class KohaErrorMessagesOperationTest extends KohaTestCase { $this->_exemplaire_mireille_abeille = $this->fixture('Class_Exemplaire', ['id' => 123, 'id_origine' => '89863']); - Class_TextReplacements::reset(); } @@ -1218,7 +1216,6 @@ class KohaErrorMessagesOperationTest extends KohaTestCase { } - public function getHoldTitleErrors() { return [ ['ageRestricted' , 'limitation sur l\'âge'], @@ -1239,7 +1236,6 @@ class KohaErrorMessagesOperationTest extends KohaTestCase { * @test */ public function holdTitleErrorsShouldBeAsExpected($code, $message) { - $this->mock_web_client ->whenCalled('open_url') ->with('http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl?service=HoldTitle&patron_id=572&bib_id=89863&request_location=127.0.0.1') @@ -1249,11 +1245,9 @@ class KohaErrorMessagesOperationTest extends KohaTestCase { $this->assertEquals(array('statut' => false, 'erreur' => 'Réservation impossible : '.$message), $this->service->reserverExemplaire($this->_lafond, $this->_exemplaire_mireille_abeille, '')); - - - } + public function getRenewTitleErrors() { return [ ['on_reserve' , 'document réservé par un autre lecteur'], @@ -1262,7 +1256,7 @@ class KohaErrorMessagesOperationTest extends KohaTestCase { ['restriction' , 'limitation sur l\'âge'], ['overdue' , 'documents en retard'], ['too_soon' , 'trop tôt pour renouveler'] - ]; + ]; } @@ -1281,12 +1275,7 @@ class KohaErrorMessagesOperationTest extends KohaTestCase { <date_due>2009-06-22</date_due> </RenewLoan>'); - $this->assertEquals(array('statut' => false, 'erreur' => 'Prolongation impossible : '.$message), $this->service->prolongerPret($this->_lafond, '24426')); - - } - - -} +} \ 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 35384220089..fe09561ced3 100644 --- a/tests/library/Class/WebService/SIGB/NanookTest.php +++ b/tests/library/Class/WebService/SIGB/NanookTest.php @@ -100,6 +100,13 @@ abstract class NanookTestCase extends ModelTestCase { 'id_bib' => 5, 'id_origine' => 8]); } + + + public function tearDown() { + $this->_mock_web_client = null; + $this->_service = null; + parent::tearDown(); + } } -- GitLab