From cb45e061c770b613438b8b4036cfdcf1649510c4 Mon Sep 17 00:00:00 2001
From: Laurent Laffont <llaffont@afi-sa.fr>
Date: Mon, 19 Apr 2021 11:23:01 +0200
Subject: [PATCH] dev #133070 Waterbear : GetRecords service : fix locationId
 import

---
 VERSIONS_WIP/133070                           |  1 +
 .../SIGB/Nanook/GetRecordsResponseReader.php  |  4 +--
 .../Class/WebService/SIGB/Nanook/Service.php  | 12 ++++++---
 .../Waterbear/GetRecordsResponseReader.php    | 27 +++++++++++++++++++
 .../WebService/SIGB/Waterbear/Service.php     |  6 +++++
 tests/fixtures/WaterbearFixtures.php          |  4 +--
 .../Class/WebService/SIGB/WaterbearTest.php   | 12 ++++++---
 7 files changed, 54 insertions(+), 12 deletions(-)
 create mode 100644 VERSIONS_WIP/133070
 create mode 100644 library/Class/WebService/SIGB/Waterbear/GetRecordsResponseReader.php

diff --git a/VERSIONS_WIP/133070 b/VERSIONS_WIP/133070
new file mode 100644
index 00000000000..bf15db1b5e8
--- /dev/null
+++ b/VERSIONS_WIP/133070
@@ -0,0 +1 @@
+ - ticket #133070 : Waterbear : correction de la mise à jour du code annexe des exemplaires
\ No newline at end of file
diff --git a/library/Class/WebService/SIGB/Nanook/GetRecordsResponseReader.php b/library/Class/WebService/SIGB/Nanook/GetRecordsResponseReader.php
index 1a7dd600859..49b39a7439b 100644
--- a/library/Class/WebService/SIGB/Nanook/GetRecordsResponseReader.php
+++ b/library/Class/WebService/SIGB/Nanook/GetRecordsResponseReader.php
@@ -34,7 +34,7 @@ class Class_WebService_SIGB_Nanook_GetRecordsResponseReader {
    * @return Class_WebService_SIGB_Nanook_GetRecordsResponseReader
    */
   public static function newInstance() {
-    return new self();
+    return new static();
   }
 
 
@@ -182,5 +182,3 @@ class Nanook_AvailabilityMapper {
       $map[$availability]($item);
   }
 }
-
-?>
\ 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 f4f71da4e88..dfcc26c2a97 100644
--- a/library/Class/WebService/SIGB/Nanook/Service.php
+++ b/library/Class/WebService/SIGB/Nanook/Service.php
@@ -279,15 +279,19 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac
   public function getNotice($id) {
     try {
       return $this->ilsdiGetRecords($id,
-                                          Class_WebService_SIGB_Nanook_GetRecordsResponseReader::newInstance());
+                                    $this->_getRecordsResponseReader());
     } catch (Exception $e) {
       return;
     }
   }
 
 
-  public function testCommunicationStatus() {
+  protected function _getRecordsResponseReader() {
+    return Class_WebService_SIGB_Nanook_GetRecordsResponseReader::newInstance();
+  }
+
 
+  public function testCommunicationStatus() {
     return (false !== strpos($this->test(), '<?xml version="1.0"'))
       ? static::COMMUNICATION_OK
       : static::COMMUNICATION_ERROR;
@@ -302,7 +306,7 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac
     try {
       $this
         ->ilsdiGetRecords(1,
-                          Class_WebService_SIGB_Nanook_GetRecordsResponseReader::newInstance());
+                          $this->_getRecordsResponseReader());
 
       $httpClient = $this->getWebClient();
       $message = $httpClient->getLastRequest();
@@ -481,4 +485,4 @@ class PickupLocationsParamsWithSiteId extends PickupLocationsParams {
     $params['siteId'] = $item->getCodifAnnexe()->getIdOrigine();
     return $params;
   }
-}
\ No newline at end of file
+}
diff --git a/library/Class/WebService/SIGB/Waterbear/GetRecordsResponseReader.php b/library/Class/WebService/SIGB/Waterbear/GetRecordsResponseReader.php
new file mode 100644
index 00000000000..16531260e95
--- /dev/null
+++ b/library/Class/WebService/SIGB/Waterbear/GetRecordsResponseReader.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Copyright (c) 2012-2021, 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_Waterbear_GetRecordsResponseReader extends Class_WebService_SIGB_Nanook_GetRecordsResponseReader {
+  public function endLocationId($data) {
+    $this->_current_item->setCodeAnnexe(trim($data));
+  }
+}
diff --git a/library/Class/WebService/SIGB/Waterbear/Service.php b/library/Class/WebService/SIGB/Waterbear/Service.php
index b9e4c24e420..5b65b850bb2 100644
--- a/library/Class/WebService/SIGB/Waterbear/Service.php
+++ b/library/Class/WebService/SIGB/Waterbear/Service.php
@@ -37,4 +37,10 @@ class Class_Webservice_SIGB_Waterbear_Service extends Class_WebService_SIGB_Nano
   public function providesPickupLocations() {
     return false;
   }
+
+
+  protected function _getRecordsResponseReader() {
+    return Class_WebService_SIGB_Waterbear_GetRecordsResponseReader::newInstance();
+  }
+
 }
diff --git a/tests/fixtures/WaterbearFixtures.php b/tests/fixtures/WaterbearFixtures.php
index 9f4f6325dee..284a1797cc5 100644
--- a/tests/fixtures/WaterbearFixtures.php
+++ b/tests/fixtures/WaterbearFixtures.php
@@ -34,8 +34,8 @@ class WaterbearFixtures {
 <available>1</available>
 <holdable>1</holdable>
 <visible>1</visible>
-<locationLabel></locationLabel>
-<locationId></locationId>
+<locationLabel>Cran</locationLabel>
+<locationId>CRAN</locationId>
 </item>
 </items>
 </record>
diff --git a/tests/library/Class/WebService/SIGB/WaterbearTest.php b/tests/library/Class/WebService/SIGB/WaterbearTest.php
index dde2b2f032a..21ee5293033 100644
--- a/tests/library/Class/WebService/SIGB/WaterbearTest.php
+++ b/tests/library/Class/WebService/SIGB/WaterbearTest.php
@@ -77,7 +77,7 @@ abstract class WaterbearTestCase extends ModelTestCase {
     $this->fixture('Class_CodifAnnexe' , ['id' => 3,
                                           'libelle' => 'Annexe Cran-Gevrier',
                                           'id_bib' => 3,
-                                          'id_origine' => 10]);
+                                          'id_origine' => 'CRAN']);
   }
 }
 
@@ -105,7 +105,6 @@ class WaterbearGetNoticePatacheTest extends WaterbearTestCase {
                             });
     Class_WebService_SIGB_AbstractService::setLogger($logger);
 
-
     $this->_mock_web_client
       ->whenCalled('open_url')
       ->with('http://waterbear.org/bib_ws.php?module=externe/ilsdi/GetRecords&ID_notices=9842')
@@ -138,4 +137,11 @@ class WaterbearGetNoticePatacheTest extends WaterbearTestCase {
   public function firstExemplaireCodeBarreShouldBeL023869b() {
     $this->assertEquals('L-023869b', $this->_notice->exemplaireAt(0)->getCodeBarre());
   }
-}
\ No newline at end of file
+
+
+  /** @test */
+  public function firstExemplaireCodeAnnexeShouldBeCRAN() {
+    $this->assertEquals('CRAN',
+                        $this->_notice->exemplaireAt(0)->getCodeAnnexe());
+  }
+}
-- 
GitLab