From 9705c72d4b842e8d0488fe45df5d547e3d3c02c0 Mon Sep 17 00:00:00 2001
From: Laurent Laffont <llaffont@afi-sa.fr>
Date: Mon, 11 Dec 2017 15:14:37 +0100
Subject: [PATCH] dev #13615  implement nanook providesLoanHistory tests

---
 .../Class/WebService/SIGB/Nanook/Service.php  | 10 +++++++-
 .../Class/WebService/SIGB/NanookTest.php      | 23 +++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/library/Class/WebService/SIGB/Nanook/Service.php b/library/Class/WebService/SIGB/Nanook/Service.php
index b5c4932ff44..d514dea03f2 100644
--- a/library/Class/WebService/SIGB/Nanook/Service.php
+++ b/library/Class/WebService/SIGB/Nanook/Service.php
@@ -22,6 +22,7 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac
   protected
     $_provide_suggest = false,
     $_provide_pickup_locations = null,
+    $_provide_loans_history = null,
     $_pickup_locations_params = null,
     $_error_codes = [];
 
@@ -136,7 +137,14 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac
   }
 
   public function providesLoansHistory() {
-    return true;
+    if (null !== $this->_provide_loans_history)
+      return $this->_provide_loans_history;
+
+    $result = $this->ilsdiAction('GetLoanHistory',
+                                 ['patronId' => 1],
+                                 'error',
+                                 '');
+    return $this->_provide_loans_history = !$this->_isNetworkError($result);
   }
 
 
diff --git a/tests/library/Class/WebService/SIGB/NanookTest.php b/tests/library/Class/WebService/SIGB/NanookTest.php
index 7406e86d0a4..35384220089 100644
--- a/tests/library/Class/WebService/SIGB/NanookTest.php
+++ b/tests/library/Class/WebService/SIGB/NanookTest.php
@@ -1306,6 +1306,17 @@ class NanookLoanHistoryTest extends NanookTestCase {
   }
 
 
+  /** @test */
+  public function providesLoanHistoryShouldAnswersTrue() {
+    $this->_mock_web_client
+      ->whenCalled('open_url')
+      ->with('http://localhost:8080/afi_Nanook/ilsdi/service/GetLoanHistory/patronId/1')
+      ->answers('<GetLoanHistory><error><PatronNotFound</error></GetLoanHistory>');
+
+    $this->assertTrue($this->_service->providesLoansHistory());
+  }
+
+
   /** @test */
   public function userShouldHaveThreeLoans() {
     $this->assertEquals(3, $this->loans_history->totalCount());
@@ -1365,4 +1376,16 @@ class NanookLoanHistoryTest extends NanookTestCase {
     $this->assertCount(3, $history->getLoans());
   }
 
+
+  /** @test */
+  public function withNanookWithoutLoanHistoryProvidesLoanHistoryShouldAnswerFalse() {
+    $this->_mock_web_client
+      ->whenCalled('open_url')
+      ->with('http://localhost:8080/afi_Nanook/ilsdi/service/GetLoanHistory/patronId/1')
+      ->answers('');
+
+    $this->assertFalse($this->_service->providesLoansHistory());
+  }
+
+
 }
\ No newline at end of file
-- 
GitLab