Skip to content
Snippets Groups Projects
Commit e5e62e8c authored by llaffont's avatar llaffont
Browse files

WS Koha: prise en compte de la codification des disponibilités de cosmogramme...

WS Koha: prise en compte de la codification des disponibilités de cosmogramme dans le statut de l'exemplaire
parent 813667c6
Branches
Tags
No related merge requests found
......@@ -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;
}
......
......@@ -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
......
......@@ -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));
}
}
......
......@@ -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();
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment