From 79fbe8e49efc095b95ebecdb75a3d7e1d51d4bdc Mon Sep 17 00:00:00 2001
From: llaffont <laurent.laffont@gmail.com>
Date: Mon, 10 Mar 2014 16:32:09 +0100
Subject: [PATCH] =?UTF-8?q?rel=20#12482=20Orph=C3=A9e:=20Add=20serial=20nu?=
 =?UTF-8?q?mber=20on=20hold=20webservice?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 library/Class/Exemplaire.php                  | 10 ++++
 .../Class/WebService/SIGB/Orphee/Service.php  | 13 +++--
 .../WebService/SIGB/OrpheeServiceTest.php     | 58 ++++++++++++++++---
 3 files changed, 68 insertions(+), 13 deletions(-)

diff --git a/library/Class/Exemplaire.php b/library/Class/Exemplaire.php
index 08393715f00..3ed523809ac 100644
--- a/library/Class/Exemplaire.php
+++ b/library/Class/Exemplaire.php
@@ -72,6 +72,16 @@ class Class_Exemplaire extends Storm_Model_Abstract {
 	}
 
 
+	public function isPeriodique() {
+		return $this->getNotice()->isPeriodique();
+	}
+
+
+	public function getTomeAlpha() {
+		return $this->getNotice()->getTomeAlpha();
+	}
+
+
 	public function getSigbExemplaire() {
 		if (!isset($this->_sigb_exemplaire))
 			$this->_sigb_exemplaire = $this->getBib()->getSigbExemplaire($this->getIdOrigine(), 
diff --git a/library/Class/WebService/SIGB/Orphee/Service.php b/library/Class/WebService/SIGB/Orphee/Service.php
index 61de8722787..54af59201c5 100644
--- a/library/Class/WebService/SIGB/Orphee/Service.php
+++ b/library/Class/WebService/SIGB/Orphee/Service.php
@@ -196,14 +196,19 @@ class Class_WebService_SIGB_Orphee_Service extends Class_WebService_SIGB_Abstrac
 
 	public function reserverExemplaire($user, $exemplaire, $code_annexe) {
 		$notice_id = $this->removeOrpheeNoticePrefix($exemplaire->getIdOrigine());
+	
+		$tome = $exemplaire->isPeriodique() 
+			? $exemplaire->getTomeAlpha()
+			: 0;
+
 		return $this->withUserDo(
 			$user, $notice_id, 
-			function ($id, $emprunteur) use ($code_annexe) {
+			function ($id, $emprunteur) use ($code_annexe, $tome) {
 				if ($this->hasSetAdhDispoAnx())
 					$this->getSearchClient()
 						->setAdhDispoAnx(setAdhDispoAnx::with($code_annexe));
 				return $this->getSearchClient()
-					->RsvNtcAdh(RsvNtcAdh::withNoticeUserNo($id, $emprunteur->getId()));
+					->RsvNtcAdh(RsvNtcAdh::withNoticeUserNo($id, $emprunteur->getId(), $tome));
 			},
 			function ($result) {
 				$datas = simplexml_load_string($result->getXml());
@@ -450,11 +455,11 @@ class RsvNtcAdh {
 	public $fas; // int
 	public $adh; // int
 
-	public static function withNoticeUserNo($ntc, $adh) {
+	public static function withNoticeUserNo($ntc, $adh, $fas) {
 		$instance = new self();
 		$instance->ntc = $ntc;
 		$instance->adh = $adh;
-		$instance->fas = 0;
+		$instance->fas = $fas;
 		return $instance;
 	}
 }
diff --git a/tests/library/Class/WebService/SIGB/OrpheeServiceTest.php b/tests/library/Class/WebService/SIGB/OrpheeServiceTest.php
index dfaafae314e..7888cc94cbf 100644
--- a/tests/library/Class/WebService/SIGB/OrpheeServiceTest.php
+++ b/tests/library/Class/WebService/SIGB/OrpheeServiceTest.php
@@ -506,6 +506,8 @@ class OrpheeServiceGetLstDmtResponseTest extends PHPUnit_Framework_TestCase {
 }
 
 
+
+
 class OrpheeServiceGetInfoUserCarteHenryDupontWithErrorTest extends OrpheeServiceTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -552,6 +554,8 @@ class OrpheeServiceGetInfoUserCarteHenryDupontWithErrorTest extends OrpheeServic
 }
 
 
+
+
 class OrpheeServiceGetInfoUserCarteHenryDupontActionErrorTest extends OrpheeServiceTestCase {
 	public function setUp() {
 		parent::setUp();
@@ -970,14 +974,44 @@ class OrpheeServiceReservationTest extends OrpheeServiceTestCase {
 			->answers(GetInfoUserCarteResponse::withResult(OrpheeFixtures::xmlGetInfoUserCarteHenryDupont()))
 
 			->whenCalled('RsvNtcAdh')
-			->with(RsvNtcAdh::withNoticeUserNo('1301700727', 100753))
+			->with(RsvNtcAdh::withNoticeUserNo('1301700727', 100753, 0))
+			->answers(RsvNtcAdhResponse::withResult('<datas><msg><code><![CDATA[1]]></code><libelle><![CDATA[Réservation mise en attente]]></libelle></msg></datas>'));
+
+		$result = $this->_orphee
+			->reserverExemplaire($this->_henry_dupont,
+													 $this->fixture('Class_Exemplaire', 
+																					['id' => 234,
+																					 'id_origine' => 'frOr1301700727',
+																					 'notice' => $this->fixture('Class_Notice',
+																																			['id' => 988,
+																																			 'tome_alpha' => 2,
+																																			 'type_doc' => Class_TypeDoc::LIVRE])]),
+													 '');
+		$this->assertEquals(['statut' => true, 'erreur' => ''], $result);
+	}
+
+
+
+	/** @test */
+	public function testReservationPeriodiqueSuccessful() {
+		$this->_search_client
+			->whenCalled('GetInfoUserCarte')
+			->with(GetInfoUserCarte::withNo('10900000753'))
+			->answers(GetInfoUserCarteResponse::withResult(OrpheeFixtures::xmlGetInfoUserCarteHenryDupont()))
+
+			->whenCalled('RsvNtcAdh')
+			->with(RsvNtcAdh::withNoticeUserNo('1301700727', 100753, 345))
 			->answers(RsvNtcAdhResponse::withResult('<datas><msg><code><![CDATA[1]]></code><libelle><![CDATA[Réservation mise en attente]]></libelle></msg></datas>'));
 
 		$result = $this->_orphee
 			->reserverExemplaire($this->_henry_dupont,
 													 $this->fixture('Class_Exemplaire', 
 																					['id' => 234,
-																					 'id_origine' => 'frOr1301700727']),
+																					 'id_origine' => 'frOr1301700727',
+																					 'notice' => $this->fixture('Class_Notice',
+																																			['id' => 988,
+																																			 'tome_alpha' => 345,
+																																			 'type_doc' => Class_TypeDoc::PERIODIQUE])]),
 													 '');
 		$this->assertEquals(['statut' => true, 'erreur' => ''], $result);
 	}
@@ -991,14 +1025,17 @@ class OrpheeServiceReservationTest extends OrpheeServiceTestCase {
 			->answers(GetInfoUserCarteResponse::withResult(OrpheeFixtures::xmlGetInfoUserCarteHenryDupont()))
 
 			->whenCalled('RsvNtcAdh')
-			->with(RsvNtcAdh::withNoticeUserNo('401700727', 100753))
+			->with(RsvNtcAdh::withNoticeUserNo('401700727', 100753, 0))
 			->answers(RsvNtcAdhResponse::withResult('<datas><msg><code><![CDATA[0]]></code><libelle><![CDATA[Réservation refusée]]></libelle></msg></datas>'));
 
-		$this->assertSame(array('statut' => false, 'erreur' => 'Réservation refusée'), 
+		$this->assertSame(['statut' => false, 'erreur' => 'Réservation refusée'], 
 											$this->_orphee->reserverExemplaire($this->_henry_dupont, 
-																												 Class_Exemplaire::getLoader()
-																												 ->newInstanceWithId(234)
-																												 ->setIdOrigine('frOr401700727'), 
+																												 $this->fixture('Class_Exemplaire', 
+																																				['id' => 234,
+																																				 'id_origine' => 'frOr401700727',
+																																				 'notice' => $this->fixture('Class_Notice',
+																																																		['id' => 988,
+																																																		 'type_doc' => Class_TypeDoc::LIVRE])]),
 																												 ''));
 	}
 
@@ -1014,14 +1051,17 @@ class OrpheeServiceReservationTest extends OrpheeServiceTestCase {
 			->answers(GetInfoUserCarteResponse::withResult(OrpheeFixtures::xmlGetInfoUserCarteHenryDupont()))
 
 			->whenCalled('RsvNtcAdh')
-			->with(RsvNtcAdh::withNoticeUserNo('1301700727', 100753))
+			->with(RsvNtcAdh::withNoticeUserNo('1301700727', 100753, 0))
 			->answers(RsvNtcAdhResponse::withResult('<datas><msg><code><![CDATA[1]]></code><libelle><![CDATA[Réservation mise en attente]]></libelle></msg></datas>'));
 
 		$result = $this->_orphee
 			->reserverExemplaire($this->_henry_dupont,
 													 $this->fixture('Class_Exemplaire', 
 																					['id' => 234,
-																					 'id_origine' => 'frOr1301700727']),
+																					 'id_origine' => 'frOr1301700727',
+																					 'notice' => $this->fixture('Class_Notice',
+																																			['id' => 988,
+																																			 'type_doc' => Class_TypeDoc::LIVRE])]),
 													 'Testing Anx');
 
 		$this->assertEquals(['statut' => true, 'erreur' => ''], $result);
-- 
GitLab