From 381d3a35649ea92b52685b4ade5c2d3349d6fd18 Mon Sep 17 00:00:00 2001
From: Alex Arnaud <alex.arnaud@biblibre.com>
Date: Fri, 10 Jul 2015 11:46:08 +0200
Subject: [PATCH] dev #24821 valence user notices

Implements item waiting to be pulled notification for all ILS but Aloes & VSmart
---
 .../SIGB/BiblixNet/PatronInfoReader.php       |  5 +++-
 .../LookupMyAccountInfoResponseReader.php     |  8 +++++-
 .../Microbib/InfosAbonneResponseReader.php    |  7 ++++-
 .../SIGB/Orphee/GetLstRsvResponseReader.php   | 11 ++++++--
 .../Class/WebService/SIGB/Pergame/Service.php |  8 +++++-
 .../Class/WebService/SIGB/BiblixNetTest.php   | 26 ++++++++++++++-----
 .../Class/WebService/SIGB/DynixTest.php       |  6 +++++
 .../WebService/SIGB/MicrobibServiceTest.php   |  6 +++++
 .../Class/WebService/SIGB/OrpheeFixtures.php  |  3 ++-
 .../WebService/SIGB/OrpheeServiceTest.php     |  7 ++++-
 .../Class/WebService/SIGB/PergameTest.php     | 18 +++++++++++++
 .../Class/WebService/SIGB/VSmartTest.php      |  1 +
 12 files changed, 91 insertions(+), 15 deletions(-)

diff --git a/library/Class/WebService/SIGB/BiblixNet/PatronInfoReader.php b/library/Class/WebService/SIGB/BiblixNet/PatronInfoReader.php
index ec4fabaa3a4..62c5c997fc2 100644
--- a/library/Class/WebService/SIGB/BiblixNet/PatronInfoReader.php
+++ b/library/Class/WebService/SIGB/BiblixNet/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_BiblixNet_PatronInfoReader extends Class_WebService_SIGB_AbstractILSDIPatronInfoReader{
@@ -77,6 +77,9 @@ class Class_WebService_SIGB_BiblixNet_PatronInfoReader extends Class_WebService_
 
 	public function endState($data) {
 		$this->_currentHold->setEtat($data);
+		if (trim($data)=='Disponible')
+			$this->_currentHold->setWaitingToBePulled();
+
 	}
 }
 
diff --git a/library/Class/WebService/SIGB/Dynix/LookupMyAccountInfoResponseReader.php b/library/Class/WebService/SIGB/Dynix/LookupMyAccountInfoResponseReader.php
index 476688e1c32..d4fadd28809 100644
--- a/library/Class/WebService/SIGB/Dynix/LookupMyAccountInfoResponseReader.php
+++ b/library/Class/WebService/SIGB/Dynix/LookupMyAccountInfoResponseReader.php
@@ -94,7 +94,13 @@ class Class_WebService_SIGB_Dynix_LookupMyAccountInfoResponseReader {
 
 
 	public function endAvailable($data) {
-		$this->_current_operation->setEtat($data == 'true' ? $this->_('Disponible') : $this->_('Réservé'));
+		if ($data == 'true') {
+			$this->_current_operation->setEtat($this->_('Disponible'));
+			$this->_current_operation->setWaitingToBePulled();
+		}
+		else {
+			$this->_current_operation->setEtat($this->_('Réservé'));
+		}
 	}
 
 	
diff --git a/library/Class/WebService/SIGB/Microbib/InfosAbonneResponseReader.php b/library/Class/WebService/SIGB/Microbib/InfosAbonneResponseReader.php
index 84912f88a38..38e9b6f3e46 100644
--- a/library/Class/WebService/SIGB/Microbib/InfosAbonneResponseReader.php
+++ b/library/Class/WebService/SIGB/Microbib/InfosAbonneResponseReader.php
@@ -109,7 +109,12 @@ class Class_WebService_SIGB_Microbib_InfosAbonneResponseReader {
 
 
 	public function endDisponible($data) {
-		$this->_current_operation->setEtat($data == 'true' ? 'Disponible' : 'Réservé');
+		if ($data == 'true') {
+			$this->_current_operation->setEtat('Disponible');
+			$this->_current_operation->setWaitingToBePulled();
+			return;
+		}
+		$this->_current_operation->setEtat('Réservé');
 	}
 }
 
diff --git a/library/Class/WebService/SIGB/Orphee/GetLstRsvResponseReader.php b/library/Class/WebService/SIGB/Orphee/GetLstRsvResponseReader.php
index 726630a6cb6..b5a44dd26d5 100644
--- a/library/Class/WebService/SIGB/Orphee/GetLstRsvResponseReader.php
+++ b/library/Class/WebService/SIGB/Orphee/GetLstRsvResponseReader.php
@@ -85,13 +85,20 @@ class Class_WebService_SIGB_Orphee_GetLstRsvResponseReader extends Class_WebServ
 
 
 	public function endSit($data) {
-		$this->_current_reservation->setEtat(trim($data));
+		$status = trim($data);
+		if (!is_numeric($status)) {//compatibility with Orphée WS version < version K
+			$this->_current_reservation->setEtat($status);
+		}
 
-		if (trim($data) != 'en attente')
+		if ($status == 'affectée' || $status == '2')
 			$this->_current_reservation->setWaitingToBePulled();
 	}
 
 
+	public function endLib_Sit($data) {
+		$this->_current_reservation->setEtat(trim($data));
+	}
+
 	public function endRang($data) {
 		$this->_current_reservation->setRang(trim($data));
 	}
diff --git a/library/Class/WebService/SIGB/Pergame/Service.php b/library/Class/WebService/SIGB/Pergame/Service.php
index a7a3887ee5a..490f2c1d417 100644
--- a/library/Class/WebService/SIGB/Pergame/Service.php
+++ b/library/Class/WebService/SIGB/Pergame/Service.php
@@ -98,12 +98,18 @@ class Class_WebService_SIGB_Pergame_Service extends Class_WebService_SIGB_Abstra
 		$reservations = [];
 		foreach($reservations_db as $reservation) {
 			$bib = Class_Bib::find($reservation->getIdSite());
-			$reservations []= Class_WebService_SIGB_Reservation::newInstanceWithEmptyExemplaire()
+
+			$sigb_reservation = Class_WebService_SIGB_Reservation::newInstanceWithEmptyExemplaire()
 				->setId($reservation->getId())
 				->setNoticeOPAC($reservation->getNotice())
 				->setBibliotheque($bib ? $bib->getLibelle() : '')
 				->setRang($reservation->getDynamicRank())
 				->setEtat($reservation->getEtat());
+
+			if ($sigb_reservation->getEtat() === 'Disponible')
+				$sigb_reservation->setWaitingToBePulled();
+
+			$reservations []= $sigb_reservation;
 		}
 
 		return $reservations;
diff --git a/tests/library/Class/WebService/SIGB/BiblixNetTest.php b/tests/library/Class/WebService/SIGB/BiblixNetTest.php
index 17a8007aab2..145b137db9f 100644
--- a/tests/library/Class/WebService/SIGB/BiblixNetTest.php
+++ b/tests/library/Class/WebService/SIGB/BiblixNetTest.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
  */
 
 require_once('BiblixNetFixtures.php');
@@ -70,7 +70,7 @@ abstract class BiblixNetTestCase extends Storm_Test_ModelTestCase {
 class BiblixNetGetRecordsLaCenseAuxAlouettesTest extends BiblixNetTestCase {
 	public function setUp() {
 		parent::setUp();
-		
+
 		$this->_mock_web_client
 			->whenCalled('open_url')
 			->with('http://mediathequewormhout.biblixnet.com/exporte_afi/?service=GetRecords&id=3')
@@ -154,7 +154,7 @@ class BiblixNetGetRecordsLaCenseAuxAlouettesTest extends BiblixNetTestCase {
 class BiblixNetGetPatronInfoJustinTicou extends BiblixNetTestCase {
 	public function setUp() {
 		parent::setUp();
-		
+
 		$this->_mock_web_client
 			->whenCalled('open_url')
 			->with('http://mediathequewormhout.biblixnet.com/exporte_afi/?service=GetPatronInfo&patronId=34&showLoans=1&showHolds=1')
@@ -257,10 +257,22 @@ class BiblixNetGetPatronInfoJustinTicou extends BiblixNetTestCase {
 	}
 
 
+	/** @test */
+	public function firstHoldWaitingToBePulledShouldBeFalse() {
+		$this->assertFalse($this->_emprunteur->getReservations()[0]->isWaitingToBePulled());
+	}
+
+
 	/** @test */
 	public function secondHoldEtatShouldBeDisponible() {
 		$this->assertEquals('Disponible', $this->_emprunteur->getReservations()[1]->getEtat());
 	}
+
+
+	/** @test */
+	public function secondHoldWaitingToBePulledShouldBeTrue() {
+		$this->assertTrue($this->_emprunteur->getReservations()[1]->isWaitingToBePulled());
+	}
 }
 
 
@@ -284,7 +296,7 @@ class BiblixNetOperationsTest extends BiblixNetTestCase {
 												));
 	}
 
-	
+
 	/** @test */
 	public function reserverExemplairesWithErrorShouldReturnErrorWithMessage() {
 			$this->_mock_web_client
@@ -348,7 +360,7 @@ class BiblixNetOperationsTest extends BiblixNetTestCase {
 												$this->_service->prolongerPret(
 													Class_Users::getLoader()->newInstance()->setIdSigb('4'),
 													'987'
-												));		
+												));
 	}
 
 
@@ -364,9 +376,9 @@ class BiblixNetOperationsTest extends BiblixNetTestCase {
 												$this->_service->prolongerPret(
 													Class_Users::getLoader()->newInstance()->setIdSigb('4'),
 													'987'
-												));		
+												));
 	}
-	
+
 }
 
 
diff --git a/tests/library/Class/WebService/SIGB/DynixTest.php b/tests/library/Class/WebService/SIGB/DynixTest.php
index 730dccffc2f..631263faa53 100644
--- a/tests/library/Class/WebService/SIGB/DynixTest.php
+++ b/tests/library/Class/WebService/SIGB/DynixTest.php
@@ -375,6 +375,12 @@ class DynixGetEmprunteurManuLarcinetTest extends DynixTestCase {
 	}
 
 
+	/** @test */
+	public function nbOfHoldWaitingToBePulledShouldBeOne() {
+		$this->assertCount(1, $this->_manu->getHoldsWaitingToBePulled());
+	}
+
+
 	/** @test */
 	public function sessionShouldBeClosed() {
 		$this->assertTrue($this->_mock_web_client
diff --git a/tests/library/Class/WebService/SIGB/MicrobibServiceTest.php b/tests/library/Class/WebService/SIGB/MicrobibServiceTest.php
index c44b2a0c591..34664dcd857 100644
--- a/tests/library/Class/WebService/SIGB/MicrobibServiceTest.php
+++ b/tests/library/Class/WebService/SIGB/MicrobibServiceTest.php
@@ -243,6 +243,12 @@ class MicrobibServiceTestInfosAbonne extends MicrobibServiceTestCase {
 	}
 
 
+	/** @test */
+	public function nbOfHoldsWaitingToBePulledShouldBeOne() {
+		$this->assertCount(1, $this->emprunteur->getHoldsWaitingToBePulled());
+	}
+
+
 	/** @test */
 	public function firstReservationAuteurShouldBeBIGART() {
 		$this->assertEquals('BIGART T.P.', array_first($this->emprunteur->getReservations())->getAuteur());
diff --git a/tests/library/Class/WebService/SIGB/OrpheeFixtures.php b/tests/library/Class/WebService/SIGB/OrpheeFixtures.php
index 4015b314c73..ea379cc4007 100644
--- a/tests/library/Class/WebService/SIGB/OrpheeFixtures.php
+++ b/tests/library/Class/WebService/SIGB/OrpheeFixtures.php
@@ -395,7 +395,8 @@ renouvellement -->
       <tit><![CDATA[Le singe bleu]]></tit>
       <auteur><![CDATA[Steinbeck, John (1902-1968)]]></auteur>
       <editeur><![CDATA[Gallimard]]></editeur>
-      <sit><![CDATA[????????]]></sit>
+      <lib_sit><![CDATA[affectée]]></lib_sit>
+      <sit><![CDATA[2]]></sit>
       <date_crea><![CDATA[09/06/2008]]></date_crea>
       <date_fin></date_fin>
       <rang>1</rang>
diff --git a/tests/library/Class/WebService/SIGB/OrpheeServiceTest.php b/tests/library/Class/WebService/SIGB/OrpheeServiceTest.php
index 9ed3999e537..5949ab70c05 100644
--- a/tests/library/Class/WebService/SIGB/OrpheeServiceTest.php
+++ b/tests/library/Class/WebService/SIGB/OrpheeServiceTest.php
@@ -730,7 +730,6 @@ class OrpheeServiceGetInfoUserCarteHenryDupontTest extends OrpheeServiceTestCase
 		$this->assertNotEmpty($this->emprunteur);
 	}
 
-
 	/** @test */
 	public function nbOfHoldsWaitingToBePulledShouldBeOne() {
 		$this->assertCount(1, $this->emprunteur->getHoldsWaitingToBePulled());
@@ -984,6 +983,12 @@ class OrpheeServiceGetInfoUserCarteHenryDupontTest extends OrpheeServiceTestCase
 	}
 
 
+	/** @test */
+	public function fourthHoldGetEtatShouldReturnAffectee() {
+		$this->assertEquals('affectée', $this->emprunteur->getReservations()[3]->getEtat());
+	}
+
+
 	/**
 	 * @test
 	 * @depends firstReservationShouldNotBeEmpty
diff --git a/tests/library/Class/WebService/SIGB/PergameTest.php b/tests/library/Class/WebService/SIGB/PergameTest.php
index 8bfd7ce0344..2361b033021 100644
--- a/tests/library/Class/WebService/SIGB/PergameTest.php
+++ b/tests/library/Class/WebService/SIGB/PergameTest.php
@@ -229,6 +229,24 @@ class PergameServiceGetEmprunteurTest extends PergameTestCase {
 	}
 
 
+	/** @test */
+	public function firstReservationWaitingToBePulledShouldBeFalse() {
+		$this->assertFalse($this->_first_reservation->isWaitingToBePulled());
+	}
+
+	/** @test */
+	public function secondReservationEtatShouldBeDisponible() {
+		$this->assertEquals('Disponible',
+												$this->emprunteur_jc->getReservations()[1]->getEtat());
+	}
+
+
+	/** @test */
+	public function secondReservationWaitingToBePulledShouldBeTrue() {
+		$this->assertTrue($this->emprunteur_jc->getReservations()[1]->isWaitingToBePulled());
+	}
+
+
 	/** @test */
 	public function firstReservationBibliothequeShouldBeCranGevrier() {
 		$this->assertEquals('Cran-Gevrier', $this->_first_reservation->getBibliotheque());
diff --git a/tests/library/Class/WebService/SIGB/VSmartTest.php b/tests/library/Class/WebService/SIGB/VSmartTest.php
index a3e981e9c1d..f506f722517 100644
--- a/tests/library/Class/WebService/SIGB/VSmartTest.php
+++ b/tests/library/Class/WebService/SIGB/VSmartTest.php
@@ -58,6 +58,7 @@ class VSmartServiceDummyFunctionsTest extends Storm_Test_ModelTestCase {
 }
 
 
+
 class VSmartGetServiceTest extends Storm_Test_ModelTestCase {
 	public function setUp() {
 		Class_WebService_SIGB_VSmart::reset();
-- 
GitLab