From cb33dcdc60914bdba08ff377a09ce970388a0958 Mon Sep 17 00:00:00 2001
From: pbarroca <pbarroca@afi-sa.fr>
Date: Wed, 8 Jul 2015 19:00:06 +0200
Subject: [PATCH] rel #27067 : koha suggestions service work in progress

---
 cosmogramme/php/fonctions/objets_saisie.php   |   8 +
 library/Class/Entity.php                      |   1 +
 .../Class/WebService/SIGB/AbstractService.php |  10 ++
 library/Class/WebService/SIGB/Koha.php        |  12 +-
 .../WebService/SIGB/Koha/RestfulService.php   | 114 ++++++++++++++
 .../Class/WebService/SIGB/Koha/Service.php    |  58 +++++--
 .../SIGB/Koha/SuggestionsReader.php           |  75 +++++++++
 library/Class/WebService/SIGB/Suggestion.php  |  33 ++++
 .../Class/WebService/SIGB/KohaRestfulTest.php | 131 ++++++++++++++++
 .../Class/WebService/SIGB/KohaTest.php        |  26 +++-
 .../WebService/SIGB/suggestions_32007.json    | 146 ++++++++++++++++++
 11 files changed, 593 insertions(+), 21 deletions(-)
 create mode 100644 library/Class/WebService/SIGB/Koha/RestfulService.php
 create mode 100644 library/Class/WebService/SIGB/Koha/SuggestionsReader.php
 create mode 100644 library/Class/WebService/SIGB/Suggestion.php
 create mode 100644 tests/library/Class/WebService/SIGB/KohaRestfulTest.php
 create mode 100644 tests/library/Class/WebService/SIGB/suggestions_32007.json

diff --git a/cosmogramme/php/fonctions/objets_saisie.php b/cosmogramme/php/fonctions/objets_saisie.php
index edbc4c93b7e..d3a1632cefd 100644
--- a/cosmogramme/php/fonctions/objets_saisie.php
+++ b/cosmogramme/php/fonctions/objets_saisie.php
@@ -33,6 +33,11 @@ function getComboSimple($name, $valeur, $liste, $tous=false, $events='') {
 }
 
 
+function getOuiNon($name, $value) {
+	return getComboSimple($name, $value, ['' => 'Non', '1' => 'Oui']);
+}
+
+
 function getComboCodif($name, $clef, $valeur, $events='', $tous=false) {
 	$data = fetchOne('select liste from variables where clef=\''. $clef . '\'');
 	$v = array_filter(explode(chr(13) . chr(10), $data));
@@ -97,6 +102,9 @@ function getBlocsParams($id_bib, $type, $valeurs) {
 
 		if ($clef == COM_KOHA)
 			$champs_params[0] = ['url_serveur',
+													 ['restful' => function($id, $valeur) {
+															 return getOuiNon($id, $valeur);
+														 }],
 													 'Interdire_reservation_doc_dispo',
 													 ['Codification_disponibilites' => function($id, $valeur){
 															 return getTextArea($id, $valeur, 30, 20);
diff --git a/library/Class/Entity.php b/library/Class/Entity.php
index b6c8fd56172..c62a3d22494 100644
--- a/library/Class/Entity.php
+++ b/library/Class/Entity.php
@@ -49,5 +49,6 @@ class Class_Entity {
 
 	protected function _set($name, $value) {
 		$this->_attribs[$name] = $value;
+		return $this;
 	}
 }
diff --git a/library/Class/WebService/SIGB/AbstractService.php b/library/Class/WebService/SIGB/AbstractService.php
index f1a85586b30..5fc983e592f 100644
--- a/library/Class/WebService/SIGB/AbstractService.php
+++ b/library/Class/WebService/SIGB/AbstractService.php
@@ -117,6 +117,16 @@ abstract class Class_WebService_SIGB_AbstractService {
 	}
 
 
+	public function providesSuggestions() {
+		return false;
+	}
+
+
+	public function suggestionsOf($user) {
+		return [];
+	}
+
+
 	protected function _success() {
     return array('statut' => true, 'erreur' => '');
 	}
diff --git a/library/Class/WebService/SIGB/Koha.php b/library/Class/WebService/SIGB/Koha.php
index 9261b882b82..4badf4f7e27 100644
--- a/library/Class/WebService/SIGB/Koha.php
+++ b/library/Class/WebService/SIGB/Koha.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_Koha {
@@ -26,15 +26,18 @@ class Class_WebService_SIGB_Koha {
 		return md5(serialize($params));
 	}
 
+
 	public static function getService($params){
 		$key = static::makeKey($params);
 		if (!isset(static::$services[$key])) {
-			$instance = new static();
 			$params = array_merge(['Interdire_reservation_doc_dispo' => 0,
-														 'Codification_disponibilites' => ''], 
+														 'Codification_disponibilites' => '',
+														 'restful' => ''],
 														$params);
+
 			$service = Class_WebService_SIGB_Koha_Service::getService($params['url_serveur'],
-																																$params['Interdire_reservation_doc_dispo']==='1');
+																																$params['Interdire_reservation_doc_dispo']==='1',
+																																$params['restful']==='1');
 
 			$service->setCodificationDisponibilites(static::decodeCodificationDisponibilites($params['Codification_disponibilites']));
 			static::$services[$key] = $service;
@@ -63,7 +66,6 @@ class Class_WebService_SIGB_Koha {
 	public static function reset() {
 		static::$services = [];
 	}
-
 }
 
 ?>
\ No newline at end of file
diff --git a/library/Class/WebService/SIGB/Koha/RestfulService.php b/library/Class/WebService/SIGB/Koha/RestfulService.php
new file mode 100644
index 00000000000..f5f7b223d0f
--- /dev/null
+++ b/library/Class/WebService/SIGB/Koha/RestfulService.php
@@ -0,0 +1,114 @@
+<?php
+/**
+ * Copyright (c) 2012-2014, 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_Koha_RestfulService
+	extends Class_WebService_SIGB_AbstractRESTService {
+
+	protected $_ilsdi_service, $_current_action;
+
+	public static function newFromIlsdi($ilsdi_service) {
+		return new static($ilsdi_service);
+	}
+
+
+	/**
+	 * Private as it should be instanciated using newFromIlsdi
+	 */
+	private function __construct($ilsdi_service) {
+		$this->_ilsdi_service = $ilsdi_service;
+		$this->setServerRoot(str_replace('ilsdi.pl', 'rest.pl', $ilsdi_service->getServerRoot()));
+		// TODO: set server root according to ilsdi root
+	}
+
+
+	public function providesSuggestions() {
+		return true;
+	}
+
+
+	public function suggestionsOf($user) {
+		$json = $this
+			->restfulGet('suggestions', ['suggestedby' => $this->_authenticate($user)]);
+
+		return (new Class_WebService_SIGB_Koha_SuggestionsReader())
+			->parse($json);
+	}
+
+
+	public function buildQueryURL($options) {
+		return sprintf('%s/%s?%s',
+									 $this->getServerRoot(),
+									 $this->_current_action,
+									 http_build_query($options));
+	}
+
+
+	public function restfulGet($action, $params=[]) {
+		$this->_current_action = $action;
+		return $this->httpGet($params);
+	}
+
+
+	/**
+	 * Handled by ILSDI
+	 */
+
+
+	public function _authenticate($user) {
+		return $this->_forwardToIlsdi(__FUNCTION__, func_get_args());
+	}
+
+
+	public function getEmprunteur($user) {
+		return $this->_forwardToIlsdi(__FUNCTION__, func_get_args());
+	}
+
+
+	public function getUserAnnexe($user) {
+		return $this->_forwardToIlsdi(__FUNCTION__, func_get_args());
+	}
+
+
+	public function reserverExemplaire($user, $exemplaire, $code_annexe) {
+		return $this->_forwardToIlsdi(__FUNCTION__, func_get_args());
+	}
+
+
+	public function supprimerReservation($user, $reservation_id) {
+		return $this->_forwardToIlsdi(__FUNCTION__, func_get_args());
+	}
+
+
+	public function prolongerPret($user, $pret_id) {
+		return $this->_forwardToIlsdi(__FUNCTION__, func_get_args());
+	}
+
+
+	public function getNotice($id) {
+		return $this->_forwardToIlsdi(__FUNCTION__, func_get_args());
+	}
+
+
+	protected function _forwardToIlsdi($name, $params) {
+		return call_user_func_array([$this->_ilsdi_service, $name], $params);
+	}
+}
\ No newline at end of file
diff --git a/library/Class/WebService/SIGB/Koha/Service.php b/library/Class/WebService/SIGB/Koha/Service.php
index ac93502a312..5d3f648afa4 100644
--- a/library/Class/WebService/SIGB/Koha/Service.php
+++ b/library/Class/WebService/SIGB/Koha/Service.php
@@ -23,16 +23,20 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR
 
 	protected
 		$interdire_resa_doc_dispo = false,
-		$codification_disponibilites = [];
+		$restful = false,
+		$codification_disponibilites = [],
+		$restful_service = null;
 
 	public static function newInstance() {
 		return new self();
 	}
 
 
-	public static function getService($server_root,$interdire_reservation_doc_dispo=false) {
-		return self::newInstance()->setServerRoot($server_root)
-															->setInterdireResaDocDispo($interdire_reservation_doc_dispo);
+	public static function getService($server_root, $interdire_reservation_doc_dispo=false, $restful=false) {
+		return self::newInstance()
+			->setServerRoot($server_root)
+			->setInterdireResaDocDispo($interdire_reservation_doc_dispo)
+			->setRestful($restful);
 	}
 
 
@@ -40,10 +44,10 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR
 	 * @param Class_Users $user
 	 * @return int
 	 */
-	protected function _authenticate($user) {
-		$xml_auth = $this->httpGet(array('service' => 'LookupPatron',
-																		 'id' => ($user->hasIdSigb() ? $user->getIdSigb() : $user->getIdabon()),
-																		 'id_type' => 'cardnumber'));
+	public function _authenticate($user) {
+		$xml_auth = $this->httpGet(['service' => 'LookupPatron',
+																'id' => ($user->hasIdSigb() ? $user->getIdSigb() : $user->getIdabon()),
+																'id_type' => 'cardnumber']);
 
 		return $this->_getTagData($xml_auth, 'id');
 	}
@@ -64,10 +68,10 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR
 	 * @return Class_WebService_SIGB_Emprunteur
 	 */
 	public function getEmprunteur($user) {
-		return $this->ilsdiGetPatronInfo(array('patron_id' => $this->_authenticate($user),
-																					 'show_contact' => 0,
-																					 'show_loans' => 1,
-																					 'show_holds' => 1),
+		return $this->ilsdiGetPatronInfo(['patron_id' => $this->_authenticate($user),
+																			'show_contact' => 0,
+																			'show_loans' => 1,
+																			'show_holds' => 1],
 																		 Class_WebService_SIGB_Koha_PatronInfoReader::newInstance());
 	}
 
@@ -152,6 +156,36 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR
 	}
 
 
+	public function setRestful($flag) {
+		$this->restful = $flag;
+		return $this;
+	}
+
+
+	public function providesSuggestions() {
+		return $this->restful;
+	}
+
+
+	public function suggestionsOf($user) {
+		if (!$this->providesSuggestions())
+			return [];
+
+		return $this
+			->getRestfulService()
+			->suggestionsOf($user);
+	}
+
+
+	public function getRestfulService() {
+		if (!$this->restful_service) {
+			$this->restful_service = Class_WebService_SIGB_Koha_RestfulService::newFromIlsdi($this);
+		}
+
+		return $this->restful_service;
+	}
+
+
 	public function getNotice($id) {
 		return $this->ilsdiGetRecords($id,
 																	Class_WebService_SIGB_Koha_GetRecordsResponseReader::newInstance()
diff --git a/library/Class/WebService/SIGB/Koha/SuggestionsReader.php b/library/Class/WebService/SIGB/Koha/SuggestionsReader.php
new file mode 100644
index 00000000000..a7fbfe74c2f
--- /dev/null
+++ b/library/Class/WebService/SIGB/Koha/SuggestionsReader.php
@@ -0,0 +1,75 @@
+<?php
+/**
+ * Copyright (c) 2012-2014, 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_Koha_SuggestionsReader {
+	use Trait_Translator;
+
+	public function parse($json) {
+		if (!$datas = json_decode($json))
+			return [];
+
+		$suggestions = [];
+		foreach($datas as $data)
+			$suggestions[] = $this->_parseOne($data);
+
+		return $suggestions;
+	}
+
+
+	protected function _parseOne($data) {
+		$library = Class_CodifAnnexe::findFirstBy(['code' => $data->branchcode]);
+		$suggestion = new Class_WebService_SIGB_Suggestion();
+		$suggestion
+			->setTitle(trim($data->title))
+			->setAuthor(trim($data->author))
+			->setPublicationYear(in_array($data->publicationyear, ['', '0']) ?
+													 '' : $data->publicationyear)
+			->setLibrary($library ? $library->getLibelle() : '')
+			->setDate(trim($data->suggesteddate))
+			->setNote(trim($data->note))
+			->setStatus($this->_statusLabelFor($data));
+
+		return $suggestion;
+	}
+
+
+	protected function _statusLabelFor($data) {
+		$status = $this->_statusTranslated(trim($data->STATUS));
+		if ($reason = trim($data->reason))
+			$status .= ' (' . $reason . ')';
+
+		return $status;
+	}
+
+
+	public function _statusTranslated($raw_status) {
+		$know_statuses = ['ASKED' => $this->_('En attente'),
+											'CHECKED' => $this->_('Vérifiée'),
+											'ACCEPTED' => $this->_('Acceptée'),
+											'REJECTED' => $this->_('Rejetée'),
+											'ORDERED' => $this->_('Commandée'),
+											'AVAILABLE' => $this->_('Disponible')];
+
+		return array_key_exists($raw_status, $know_statuses) ?
+			$know_statuses[$raw_status] : $raw_status;
+	}
+}
\ No newline at end of file
diff --git a/library/Class/WebService/SIGB/Suggestion.php b/library/Class/WebService/SIGB/Suggestion.php
new file mode 100644
index 00000000000..e17a472cc9d
--- /dev/null
+++ b/library/Class/WebService/SIGB/Suggestion.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Copyright (c) 2012-2014, 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_Suggestion extends Class_Entity {
+	public function __construct() {
+		$this->_attribs = ['Title' => '',
+											 'Author' => '',
+											 'PublicationYear' => '',
+											 'Library' => '',
+											 'Date' => '',
+											 'Note' => '',
+											 'Status' => ''];
+	}
+}
\ No newline at end of file
diff --git a/tests/library/Class/WebService/SIGB/KohaRestfulTest.php b/tests/library/Class/WebService/SIGB/KohaRestfulTest.php
new file mode 100644
index 00000000000..6179ca874d0
--- /dev/null
+++ b/tests/library/Class/WebService/SIGB/KohaRestfulTest.php
@@ -0,0 +1,131 @@
+<?php
+/**
+ * Copyright (c) 2012-2014, 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
+ */
+
+
+abstract class KohaRestfulTestCase extends ModelTestCase {
+	const BASE_URL = 'http://cat-aficg55.biblibre.com/cgi-bin/koha/';
+	protected $_storm_default_to_volatile = true;
+	protected $mock_web_client;
+	protected $service;
+
+	public function setUp() {
+		$this->fixture('Class_AdminVar', ['id' => 'KOHA_MULTI_SITES', 'valeur' => '']);
+
+		$this->mock_web_client = $this->mock();
+
+		$params = ['url_serveur' => static::BASE_URL . 'ilsdi.pl',
+							 'restful' => '1'];
+
+		$logger = $this->mock()
+									 ->whenCalled('log')->answers(true)
+
+									 ->whenCalled('logError')
+									 ->willDo(function($url, $message) {
+															throw new RuntimeException($url . ' :: ' . $message);
+														});
+		Class_WebService_SIGB_AbstractService::setLogger($logger);
+
+		$this->service = Class_WebService_SIGB_Koha::getService($params);
+		$this->service->setWebClient($this->mock_web_client);
+		$this->service->getRestfulService()->setWebClient($this->mock_web_client);
+	}
+}
+
+
+
+class KohaRestfulSuggestionOfTest extends KohaRestfulTestCase {
+	public function setUp() {
+		parent::setUp();
+
+		$user = $this->fixture('Class_Users',
+													 ['id' => 34,
+														'login' => 'harlock',
+														'password' => 'arcadia',
+														'idabon' => 'AO989IE']);
+
+		$this->fixture('Class_CodifAnnexe',
+									 ['id' => 15,
+										'libelle' => 'Istres',
+										'code' => 'IST']);
+
+		$this->mock_web_client
+			->whenCalled('open_url')
+			->with(static::BASE_URL . 'ilsdi.pl?service=LookupPatron&id=AO989IE&id_type=cardnumber')
+			->answers('<id>32007</id>')
+
+			->whenCalled('open_url')
+			->with(static::BASE_URL . 'rest.pl/suggestions?suggestedby=32007')
+			->answers(file_get_contents(__DIR__ . '/suggestions_32007.json'));
+
+		$this->suggestions = $this->service->suggestionsOf($user);
+	}
+
+
+	/** @test */
+	public function shouldHaveThreeSuggestions() {
+		$this->assertEquals(3, count($this->suggestions));
+	}
+
+
+	public function datas() {
+		return [[0,
+						 'En piste ! : Créations en couture pour petits et grands Enfant',
+						 'Laëtitia Gheno',
+						 '',
+						 'Istres',
+						 '2013-11-14',
+						 'D.L.',
+						 'Disponible'],
+						[1,
+						 'Un été couture made in France',
+						 'Géraldine Debeauvais',
+						 '',
+						 'Istres',
+						 '2013-12-12',
+						 '',
+						 'Disponible'],
+						[2,
+						 'Couture pour enfants branchés ! Vêtements et accessoires de la naissance à 2 ans et plus',
+						 'Marie-Eve Dollat',
+						 '2012',
+						 'Istres',
+						 '2014-04-16',
+						 '',
+						 'Rejetée (Sujet largement couvert dans la collection)']];
+	}
+
+
+	/**
+	 * @test
+	 * @dataProvider datas
+	 */
+	public function datasShouldBeImported($pos, $title, $author, $publication_year,
+																				$library, $date, $note, $status) {
+		$this->assertEquals($title, $this->suggestions[$pos]->getTitle());
+		$this->assertEquals($author, $this->suggestions[$pos]->getAuthor());
+		$this->assertEquals($publication_year,
+												$this->suggestions[$pos]->getPublicationYear());
+		$this->assertEquals($library, $this->suggestions[$pos]->getLibrary());
+		$this->assertEquals($date, $this->suggestions[$pos]->getDate());
+		$this->assertEquals($note, $this->suggestions[$pos]->getNote());
+		$this->assertEquals($status, $this->suggestions[$pos]->getStatus());
+	}
+}
\ No newline at end of file
diff --git a/tests/library/Class/WebService/SIGB/KohaTest.php b/tests/library/Class/WebService/SIGB/KohaTest.php
index 86f8c714831..30261e86284 100644
--- a/tests/library/Class/WebService/SIGB/KohaTest.php
+++ b/tests/library/Class/WebService/SIGB/KohaTest.php
@@ -20,11 +20,13 @@
  */
 include_once('KohaFixtures.php');
 
-class KohaGetServiceTest extends PHPUnit_Framework_TestCase {
+class KohaGetServiceTest extends ModelTestCase {
+	protected $_storm_default_to_volatile = true;
+
 	public function setUp() {
 		Class_WebService_SIGB_Koha::reset();
 		Class_AdminVar::newInstanceWithId('KOHA_MULTI_SITES', ['valeur' => '' ]);
-		$this->service = Class_WebService_SIGB_Koha::getService(array('url_serveur' => 'http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl'));
+		$this->service = Class_WebService_SIGB_Koha::getService(['url_serveur' => 'http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl']);
 	}
 
 
@@ -41,14 +43,30 @@ class KohaGetServiceTest extends PHPUnit_Framework_TestCase {
 												$this->service->getServerRoot());
 	}
 
+
+	/** @test */
+	public function shouldNotProvideSuggestions() {
+		$this->assertFalse($this->service->providesSuggestions());
+	}
+
+
+	/** @test */
+	public function withRestfulShouldProvideSuggestions() {
+		Class_WebService_SIGB_Koha::reset();
+		$params = ['url_serveur' => 'http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl',
+							 'restful' => '1'];
+		$service = Class_WebService_SIGB_Koha::getService($params);
+		$this->assertTrue($service->providesSuggestions());
+	}
+
+
 	/** @test */
 	public function getServiceWithoutSchemeShouldAddHttpScheme() {
 		Class_WebService_SIGB_Koha::reset();
-		$this->service = Class_WebService_SIGB_Koha::getService(array('url_serveur' => 'cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl'));
+		$this->service = Class_WebService_SIGB_Koha::getService(['url_serveur' => 'cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl']);
 		$this->assertEquals('http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl',
 												$this->service->getServerRoot());
 	}
-
 }
 
 
diff --git a/tests/library/Class/WebService/SIGB/suggestions_32007.json b/tests/library/Class/WebService/SIGB/suggestions_32007.json
new file mode 100644
index 00000000000..74421ddd913
--- /dev/null
+++ b/tests/library/Class/WebService/SIGB/suggestions_32007.json
@@ -0,0 +1,146 @@
+[
+   {
+      "date" : "2014-04-01 16:08:36",
+      "STATUS" : "AVAILABLE",
+      "suggestionid" : "6197",
+      "branchcodemanagedby" : "MIR",
+      "accepteddate" : "2014-01-29",
+      "borrnummanagedby" : "811",
+      "emailmanagedby" : "mail@server.com",
+      "branchcodesuggestedby" : "IST",
+      "isbn" : "9782814101425 ",
+      "emailsuggestedby" : "mail@server.com",
+      "branchcode" : "IST",
+      "copyrightdate" : "0",
+      "budgetid" : "1557",
+      "reason" : null,
+      "AVAILABLE" : 1,
+      "total" : "0.000000",
+      "surnamemanagedby" : "TESTING",
+      "branchnamesuggestedby" : "Test",
+      "price" : "26.900000",
+      "title" : "En piste ! : Créations en couture pour petits et grands Enfant",
+      "collectiontitle" : "",
+      "publicationyear" : "0",
+      "itemtype" : "LIVR",
+      "place" : "",
+      "author" : "Laëtitia Gheno",
+      "suggesteddate" : "2013-11-14",
+      "currency" : "EUR",
+      "borrnumsuggestedby" : "32007",
+      "biblionumber" : "261517",
+      "categorycodesuggestedby" : "A",
+      "manageddate" : "2014-01-29",
+      "acceptedby" : "811",
+      "firstnamesuggestedby" : "Test",
+      "surnamesuggestedby" : "TEST",
+      "publishercode" : "",
+      "suggestedby" : "32007",
+      "rejecteddate" : null,
+      "firstnamemanagedby" : "Test",
+      "rejectedby" : null,
+      "quantity" : "0",
+      "note" : "D.L.",
+      "patronreason" : null,
+      "categorydescriptionsuggestedby" : "Adulte",
+      "volumedesc" : null,
+      "mailoverseeing" : "0",
+      "managedby" : "811"
+   },
+   {
+      "date" : "2014-05-05 15:42:42",
+      "STATUS" : "AVAILABLE",
+      "suggestionid" : "6360",
+      "branchcodemanagedby" : "MIR",
+      "accepteddate" : "2014-02-18",
+      "borrnummanagedby" : "811",
+      "emailmanagedby" : "mail@server.com",
+      "branchcodesuggestedby" : "IST",
+      "isbn" : "",
+      "emailsuggestedby" : "mail@server.com",
+      "branchcode" : "IST",
+      "copyrightdate" : "0",
+      "budgetid" : "952",
+      "reason" : null,
+      "AVAILABLE" : 1,
+      "total" : "0.000000",
+      "surnamemanagedby" : "TESTING",
+      "branchnamesuggestedby" : "Test",
+      "price" : "0.000000",
+      "title" : "Un été couture made in France",
+      "collectiontitle" : "",
+      "publicationyear" : "0",
+      "itemtype" : "LIVR",
+      "place" : "",
+      "author" : "Géraldine Debeauvais",
+      "suggesteddate" : "2013-12-12",
+      "currency" : "EUR",
+      "borrnumsuggestedby" : "32007",
+      "biblionumber" : "260846",
+      "categorycodesuggestedby" : "A",
+      "manageddate" : "2014-02-18",
+      "acceptedby" : "811",
+      "firstnamesuggestedby" : "Test",
+      "surnamesuggestedby" : "TESTING",
+      "publishercode" : "Tutti Frutti",
+      "suggestedby" : "32007",
+      "rejecteddate" : null,
+      "firstnamemanagedby" : "Test",
+      "rejectedby" : null,
+      "quantity" : "0",
+      "note" : "",
+      "patronreason" : null,
+      "categorydescriptionsuggestedby" : "Adulte",
+      "volumedesc" : null,
+      "mailoverseeing" : "0",
+      "managedby" : "811"
+   },
+   {
+      "date" : "2014-04-22 15:37:16",
+      "STATUS" : "REJECTED",
+      "suggestionid" : "7168",
+      "branchcodemanagedby" : "MIR",
+      "accepteddate" : null,
+      "borrnummanagedby" : "811",
+      "emailmanagedby" : "mail@server.com",
+      "branchcodesuggestedby" : "IST",
+      "isbn" : "",
+      "emailsuggestedby" : "mail@server.com",
+      "branchcode" : "IST",
+      "copyrightdate" : "0",
+      "budgetid" : "952",
+      "reason" : "Sujet largement couvert dans la collection",
+      "total" : "0.000000",
+      "surnamemanagedby" : "TESTING",
+      "branchnamesuggestedby" : "Test",
+      "REJECTED" : 1,
+      "price" : "0.000000",
+      "title" : "Couture pour enfants branchés ! Vêtements et accessoires de la naissance à 2 ans et plus",
+      "collectiontitle" : "",
+      "publicationyear" : "2012",
+      "itemtype" : "LIVR",
+      "place" : "",
+      "author" : " Marie-Eve Dollat",
+      "suggesteddate" : "2014-04-16",
+      "currency" : "EUR",
+      "borrnumsuggestedby" : "32007",
+      "biblionumber" : null,
+      "categorycodesuggestedby" : "A",
+      "manageddate" : "2014-04-22",
+      "acceptedby" : "0",
+      "firstnamesuggestedby" : "Test",
+      "surnamesuggestedby" : "TESTING",
+      "publishercode" : "",
+      "suggestedby" : "32007",
+      "rejecteddate" : "2014-04-22",
+      "firstnamemanagedby" : "Test",
+      "rejectedby" : "811",
+      "quantity" : "0",
+      "note" : "",
+      "patronreason" : null,
+      "categorydescriptionsuggestedby" : "Adulte",
+      "volumedesc" : null,
+      "mailoverseeing" : "0",
+      "managedby" : "811"
+   }
+]
-- 
GitLab