From e5e62e8c37d7e5d75755fe2170273c6c5ce9aac1 Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Mon, 16 Dec 2013 15:46:03 +0000 Subject: [PATCH] =?UTF-8?q?WS=20Koha:=20prise=20en=20compte=20de=20la=20co?= =?UTF-8?q?dification=20des=20disponibilit=C3=A9s=20de=20cosmogramme=20dan?= =?UTF-8?q?s=20le=20statut=20de=20l'exemplaire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/Class/WebService/SIGB/Koha.php | 21 +++++++++- .../SIGB/Koha/GetRecordsResponseReader.php | 7 ++++ .../Class/WebService/SIGB/Koha/Service.php | 16 ++++++- .../Class/WebService/SIGB/KohaTest.php | 42 ++++++++++++++++--- 4 files changed, 77 insertions(+), 9 deletions(-) diff --git a/library/Class/WebService/SIGB/Koha.php b/library/Class/WebService/SIGB/Koha.php index 2486b7148c9..24b2c8be8df 100644 --- a/library/Class/WebService/SIGB/Koha.php +++ b/library/Class/WebService/SIGB/Koha.php @@ -30,14 +30,31 @@ class Class_WebService_SIGB_Koha { $key = static::makeKey($params); if (!isset(static::$services[$key])) { $instance = new static(); - $params = array_merge(['Interdire_reservation_doc_dispo' => 0],$params); - static::$services[$key] = Class_WebService_SIGB_Koha_Service::getService($params['url_serveur'],$params['Interdire_reservation_doc_dispo']==='1'); + $params = array_merge(['Interdire_reservation_doc_dispo' => 0, + 'Codification_disponibilites' => ''], + $params); + $service = Class_WebService_SIGB_Koha_Service::getService($params['url_serveur'], + $params['Interdire_reservation_doc_dispo']==='1'); + + $service->setCodificationDisponibilites(static::decodeCodificationDisponibilites($params['Codification_disponibilites'])); + static::$services[$key] = $service; } return static::$services[$key]; } + public static function decodeCodificationDisponibilites($str_codif) { + $codifs = []; + $lines = array_filter(explode("\n", trim($str_codif))); + foreach($lines as $line) { + $code_libelle = explode(':', $line); + $codifs[trim($code_libelle[0])] = trim($code_libelle[1]); + } + return $codifs; + } + + public static function setService($params, $service) { static::$services[static::makeKey($params)] = $service; } diff --git a/library/Class/WebService/SIGB/Koha/GetRecordsResponseReader.php b/library/Class/WebService/SIGB/Koha/GetRecordsResponseReader.php index 4af9c908de5..3454128630f 100644 --- a/library/Class/WebService/SIGB/Koha/GetRecordsResponseReader.php +++ b/library/Class/WebService/SIGB/Koha/GetRecordsResponseReader.php @@ -47,6 +47,13 @@ class Class_WebService_SIGB_Koha_GetRecordsResponseReader { return $this; } + + public function setCodificationDisponibilites($codif) { + foreach($codif as $status => $libelle) + $this->_not_for_loan_status[$status] = $libelle; + return $this; + } + public function getNoticeFromXML($xml) { $this->_xml_parser = Class_WebService_XMLParser::newInstance(); $this->_xml_parser diff --git a/library/Class/WebService/SIGB/Koha/Service.php b/library/Class/WebService/SIGB/Koha/Service.php index 8a72fa66c4e..757e5ba1a1d 100644 --- a/library/Class/WebService/SIGB/Koha/Service.php +++ b/library/Class/WebService/SIGB/Koha/Service.php @@ -21,7 +21,9 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractRESTService { - protected $interdire_resa_doc_dispo = false; + protected + $interdire_resa_doc_dispo = false, + $codification_disponibilites = []; public static function newInstance() { return new self(); @@ -29,7 +31,6 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR public static function getService($server_root,$interdire_reservation_doc_dispo=false) { - return self::newInstance()->setServerRoot($server_root) ->setInterdireResaDocDispo($interdire_reservation_doc_dispo); } @@ -48,6 +49,16 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR } + + /** + * @param array $codification + * @return Class_WebService_SIGB_Koha_Service + */ + public function setCodificationDisponibilites($codif) { + $this->codification_disponibilites = $codif; + } + + /** * @param Class_Users $user * @return Class_WebService_SIGB_Emprunteur @@ -119,6 +130,7 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR public function getNotice($id) { return $this->ilsdiGetRecords($id, Class_WebService_SIGB_Koha_GetRecordsResponseReader::newInstance() + ->setCodificationDisponibilites($this->codification_disponibilites) ->setInterdireResaDocDispo($this->interdire_resa_doc_dispo)); } } diff --git a/tests/library/Class/WebService/SIGB/KohaTest.php b/tests/library/Class/WebService/SIGB/KohaTest.php index 63c054355b7..ba04f5424e3 100644 --- a/tests/library/Class/WebService/SIGB/KohaTest.php +++ b/tests/library/Class/WebService/SIGB/KohaTest.php @@ -61,9 +61,8 @@ abstract class KohaTestCase extends PHPUnit_Framework_TestCase { $this->mock_web_client = $this->getMock('Class_WebService_SimpleWebClient'); - $this->service = Class_WebService_SIGB_Koha_Service::newInstance() - ->setServerRoot('http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl') - ->setWebClient($this->mock_web_client); + $this->service = Class_WebService_SIGB_Koha::getService(['url_serveur' => 'http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl']); + $this->service->setWebClient($this->mock_web_client); } } @@ -113,7 +112,7 @@ class KohaServiceGetNoticeJardinEnfantTest extends KohaTestCase { -class KohaServiceGetNoticeHarryPotterTest extends KohaTestCase { +abstract class KohaServiceGetNoticeHarryPotterTestCase extends KohaTestCase { public function setUp() { parent::setUp(); $this->mock_web_client @@ -121,10 +120,18 @@ class KohaServiceGetNoticeHarryPotterTest extends KohaTestCase { ->method('open_url') ->with('http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl?service=GetRecords&id=33233') ->will($this->returnValue(KohaFixtures::xmlGetRecordHarryPotter())); + } +} + + +class KohaServiceGetNoticeHarryPotterTest extends KohaServiceGetNoticeHarryPotterTestCase { + public function setUp() { + parent::setUp(); $this->potter = $this->service->getNotice('33233'); } + /** @test */ public function shouldAnswerOneNotice() { $this->assertInstanceOf('Class_WebService_SIGB_Notice', $this->potter); @@ -244,7 +251,6 @@ class KohaServiceGetNoticeHarryPotterTest extends KohaTestCase { $this->assertEquals('En réserve', $this->potter->exemplaireAt(7)->getDisponibilite()); } - /** @test */ public function eigthExemplaireShouldBeReservable() { $this->assertTrue($this->potter->exemplaireAt(7)->isReservable()); @@ -260,6 +266,32 @@ class KohaServiceGetNoticeHarryPotterTest extends KohaTestCase { +class KohaServiceGetNoticeHarryPotterAltenativeCodifDisponibiliteTest extends KohaServiceGetNoticeHarryPotterTestCase { + public function setUp() { + parent::setUp(); + + $this->service = Class_WebService_SIGB_Koha::getService(['url_serveur' => 'http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl', + 'Codification_disponibilites' => "1:Disponible\n4:En transit"]); + $this->service->setWebClient($this->mock_web_client); + $this->potter = $this->service->getNotice('33233'); + } + + + /** @test */ + public function withCodificationDispoAlternativeEightExemplaireDisponibiliteShouldBeEnTransit() { + $this->assertEquals('En transit', $this->potter->exemplaireAt(7)->getDisponibilite()); + } + + + /** @test */ + public function seventhExemplaireDisponibiliteShouldBeEnTraitement() { + $this->assertEquals("En traitement", $this->potter->exemplaireAt(6)->getDisponibilite()); + } +} + + + + class KohaGetEmprunteurErrorTest extends KohaTestCase { public function setUp() { parent::setUp(); -- GitLab