From a18dc3ef0890944d9335a0a72a818f1dfc9f4e62 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Thu, 23 Aug 2012 09:31:01 +0000
Subject: [PATCH] =?UTF-8?q?Opsys:=20v=C3=A9rifie=20si=20l'authentification?=
 =?UTF-8?q?=20est=20valide=20ou=20non?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../Class/WebService/SIGB/Opsys/Service.php   | 10 +++++--
 .../WebService/SIGB/OpsysServiceTest.php      | 29 +++++++++++++++++++
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/library/Class/WebService/SIGB/Opsys/Service.php b/library/Class/WebService/SIGB/Opsys/Service.php
index b9ddf4bfb7d..20a0055e313 100644
--- a/library/Class/WebService/SIGB/Opsys/Service.php
+++ b/library/Class/WebService/SIGB/Opsys/Service.php
@@ -933,12 +933,16 @@ class EmprAuthentifierResponse {
 		$emprunteur = new Class_WebService_SIGB_Emprunteur(
 																 $this->EmprAuthentifierResult->IDEmprunteur,
 																 $this->EmprAuthentifierResult->IdentiteEmpr);
-		return $emprunteur
+		$emprunteur
 			->setEmail($this->EmprAuthentifierResult->EmailEmpr)
 			->setNbReservations($this->EmprAuthentifierResult->NombreReservations)
 			->setNbEmprunts($this->EmprAuthentifierResult->NombrePrets)
-			->setNbPretsEnRetard($this->EmprAuthentifierResult->NombreRetards)
-			->beValid();
+			->setNbPretsEnRetard($this->EmprAuthentifierResult->NombreRetards);
+
+		if ($this->EmprAuthentifierResult->IDEmprunteur)
+			$emprunteur->beValid();
+
+		return $emprunteur;
 	}
 }
 
diff --git a/tests/library/Class/WebService/SIGB/OpsysServiceTest.php b/tests/library/Class/WebService/SIGB/OpsysServiceTest.php
index f9771a78e4c..438a55f26f0 100644
--- a/tests/library/Class/WebService/SIGB/OpsysServiceTest.php
+++ b/tests/library/Class/WebService/SIGB/OpsysServiceTest.php
@@ -400,6 +400,35 @@ abstract class OpsysServiceWithSessionTestCase extends Storm_Test_ModelTestCase
 }
 
 
+
+class EmprAuthentifierErreurTestCreateEmprunteur extends OpsysServiceWithSessionTestCase {
+	public function setUp() {
+		parent::setUp();
+
+
+		$auth_response_error = new EmprAuthentifierResponse();
+		$auth_response_error->EmprAuthentifierResult = new RspEmprAuthentifier();
+		$auth_response_error->ErreurService = new WebSrvErreur();
+		$auth_response_error->ErreurService->CodeErreur = '1';
+
+		$this->search_client			
+			->whenCalled('EmprAuthentifier')->answers($auth_response_error);
+
+		$this->emprunteur = $this->opsys->getEmprunteur(
+													Class_Users::getLoader()->newInstance()
+														->setLogin('tintin')
+														->setPassword('1234'));
+	}
+
+
+	public function testEmprunteurIsNotValid() {
+		$this->assertFalse($this->emprunteur->isValid());
+	}
+}
+
+
+
+
 class EmprAuthentifierTestCreateEmprunteur extends OpsysServiceWithSessionTestCase {
 	public function setUp() {
 		parent::setUp();
-- 
GitLab