diff --git a/VERSIONS_HOTLINE/91532 b/VERSIONS_HOTLINE/91532 new file mode 100644 index 0000000000000000000000000000000000000000..24247dd6cc49c274bdba2e1ba4f92f9111f2d140 --- /dev/null +++ b/VERSIONS_HOTLINE/91532 @@ -0,0 +1 @@ + - ticket #91532 : SIGB Koha : mise à jour des message d'erreur affichés en cas d'echec sur une réservation via les webservices. \ 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 26c661bb5dd30c85ec0b50b9415c3dc1a0e18406..ea5e374369dda3cd05400fdcaa7b524fc25946d7 100644 --- a/library/Class/WebService/SIGB/Koha/Service.php +++ b/library/Class/WebService/SIGB/Koha/Service.php @@ -48,7 +48,10 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR 'cannotReserveFromOtherBranches' => $this->_('réservation impossible dans cette bibliothèque'), 'tooManyReserves' => $this->_('nombre maximum de réservations atteint'), 'notReservable' => $this->_('ce document ne peut normalement pas être réservé'), + 'OpacItemHoldNotAllowed' => $this->_('réservation interdite via le portail pour ce document'), + 'LocationNotFound' => $this->_('site de retrait introuvable'), 'debarred' => $this->_('compte bloqué'), + 'PatronDebarred' => $this->_('compte bloqué'), 'expired' => $this->_('compte expiré'), 'alreadyReserved' => $this->_('document déjà réservé sur votre compte'), 'none_available' => $this->_('aucun document n\'est disponible pour la réservation'), @@ -185,13 +188,6 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR } - protected function _xmlError($xml) { - return (false !== strpos($xml, 'OpacItemHoldNotAllowed')) - ? $this->_('La réservation à l\'exemplaire est interdite') - : ''; - } - - protected function _setPickupLocation($args, $code) { if (trim($code) && $annexe = Class_CodifAnnexe::findFirstBy(['code' => $code])) $args['pickup_location'] = $annexe->getIdOrigine(); diff --git a/tests/fixtures/KohaFixtures.php b/tests/fixtures/KohaFixtures.php index 45ad5114c0e1fae99158177b7848e61e3a86c2b4..738645654e043675ed5f17d7d40d293e07435ff4 100644 --- a/tests/fixtures/KohaFixtures.php +++ b/tests/fixtures/KohaFixtures.php @@ -751,6 +751,14 @@ class KohaFixtures { } + public static function xmlAuthenticatePatronLostCard() { + return '<?xml version="1.0" encoding="UTF-8" ?> + <AuthenticatePatron> + <code>PatronLostCard</code> + </AuthenticatePatron>'; + } + + public static function xmlGetPatronInfoLaure() { return '<?xml version="1.0" encoding="UTF-8" ?> <GetPatronInfo> diff --git a/tests/library/Class/WebService/SIGB/KohaTest.php b/tests/library/Class/WebService/SIGB/KohaTest.php index 1c966bd2725a737990a2374115f69f76d76529bb..7386c5aa26e3927bc742829b98281516c68e2c93 100644 --- a/tests/library/Class/WebService/SIGB/KohaTest.php +++ b/tests/library/Class/WebService/SIGB/KohaTest.php @@ -1067,6 +1067,54 @@ class KohaOperationsTest extends KohaTestCase { $this->assertEquals(array('statut' => false, 'erreur' => 'Réservation impossible'), $this->service->reserverExemplaire($this->_lafond, $this->_exemplaire_mireille_abeille, '')); } + + + /** @test @see http://forge.afi-sa.fr/issues/91532 */ + public function reserverExemplaireShouldBeExplicitIfPatronDebarred() { + $this->mock_web_client + ->whenCalled('open_url') + ->with('http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl?service=HoldTitle&patron_id=572&bib_id=89863&request_location=127.0.0.1') + ->answers('<HoldTitle> + <code>PatronDebarred</code> + </HoldTitle>'); + + $this->assertEquals( + ['statut' => false, + 'erreur' => 'Réservation impossible : compte bloqué'], + $this->service->reserverExemplaire($this->_lafond, $this->_exemplaire_mireille_abeille, '')); + } + + + /** @test */ + public function reserverExemplaireShouldBeExplicitIfOpacItemHoldNotAllowed() { + $this->mock_web_client + ->whenCalled('open_url') + ->with('http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl?service=HoldTitle&patron_id=572&bib_id=89863&request_location=127.0.0.1') + ->answers('<HoldTitle> + <code>OpacItemHoldNotAllowed</code> + </HoldTitle>'); + + $this->assertEquals( + ['statut' => false, + 'erreur' => 'Réservation impossible : réservation interdite via le portail pour ce document'], + $this->service->reserverExemplaire($this->_lafond, $this->_exemplaire_mireille_abeille, '')); + } + + + /** @test */ + public function reserverExemplaireShouldBeExplicitIfLocationNotFound() { + $this->mock_web_client + ->whenCalled('open_url') + ->with('http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl?service=HoldTitle&patron_id=572&bib_id=89863&request_location=127.0.0.1') + ->answers('<HoldTitle> + <code>LocationNotFound</code> + </HoldTitle>'); + + $this->assertEquals( + ['statut' => false, + 'erreur' => 'Réservation impossible : site de retrait introuvable'], + $this->service->reserverExemplaire($this->_lafond, $this->_exemplaire_mireille_abeille, '')); + } } @@ -1318,6 +1366,13 @@ class KohaAuthenticateWSTest extends KohaTestCase { 'password' => '1989']) ->answers(KohaFixtures::xmlAuthenticatePatronOk()) + ->whenCalled('postData') + ->with('http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl', + ['service' => 'AuthenticatePatron', + 'username' => 'gilles', + 'password' => '1984']) + ->answers(KohaFixtures::xmlAuthenticatePatronLostCard()) + ->whenCalled('open_url') ->with('http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl?service=GetPatronInfo&patron_id=96138&show_contact=1&show_loans=1&show_holds=1') ->answers(KohaFixtures::xmlGetPatronInfoDupont()); @@ -1329,9 +1384,19 @@ class KohaAuthenticateWSTest extends KohaTestCase { 'idabon' => 'john', 'id_site' => 3]); + $this->user_lost = $this->fixture('Class_Users', ['id' => 11, + 'login' => 'gilles', + 'password' => '1984', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB, + 'idabon' => 'gilles', + 'id_site' => 3]); + + $this->emprunteur = $this->service->getEmprunteur($this->user); + $this->emprunteur_lost = $this->service->getEmprunteur($this->user_lost); $this->emprunteur->updateUser($this->user); + $this->emprunteur_lost->updateUser($this->user_lost); } public function expectedUser() { @@ -1359,6 +1424,18 @@ class KohaAuthenticateWSTest extends KohaTestCase { } + /** @test */ + public function userWithLostCardShouldThrowError() { + $this->mock_web_client + ->whenCalled('postData') + ->with('http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl', + ['service' => 'AuthenticatePatron', + 'username' => 'john', + 'password' => '1989']) + ->answers(KohaFixtures::xmlAuthenticatePatronLostCard()); + + $this->assertFalse($this->emprunteur_lost->isValid()); + } } diff --git a/tests/scenarios/HandleBranchcode/HandleBranchcodeTest.php b/tests/scenarios/HandleBranchcode/HandleBranchcodeTest.php index 6a92ca98e8e875a69cae98e59e95dcc5a0b25e61..cc0e07ba5d90e35e290affe2cbcd3c9c256738a1 100644 --- a/tests/scenarios/HandleBranchcode/HandleBranchcodeTest.php +++ b/tests/scenarios/HandleBranchcode/HandleBranchcodeTest.php @@ -181,12 +181,10 @@ class HandleBranchcodeHoldItemAndHoldTitleTest extends HandleBranchcodeTestCase ->whenCalled('open_url') ->with($this->ilsdi . '?service=HoldItem&item_id=&pickup_location=CHY-GB') ->willDo(function() {$this->expected_call [] = 1; - return '<HoldTitle> - <title>Mireille l\'abeille</title> - <pickup_location>Bibliothèque Départementale de la Meuse</pickup_location> - <HoldItem>OpacItemHoldNotAllowed</HoldItem> - </HoldTitle>'; - }) + return '<HoldItem> + <code>OpacItemHoldNotAllowed</code> + </HoldItem>'; + }) ->whenCalled('open_url') ->with($this->ilsdi . '?service=HoldTitle&request_location=127.0.0.1&pickup_location=CHY-GB')