From 920efa413950c5d3cf793e66edf2e151f6002fd7 Mon Sep 17 00:00:00 2001 From: pbarroca <pbarroca@git-test.afi-sa.fr> Date: Fri, 20 Apr 2012 12:53:59 +0000 Subject: [PATCH] OAI : prise en charge bad verb --- .../Class/WebService/OAI/Response/Null.php | 2 +- .../Class/WebService/OAI/ResponseFactory.php | 6 +++- .../opac/controllers/OaiControllerTest.php | 30 +++++++++++++++---- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/library/Class/WebService/OAI/Response/Null.php b/library/Class/WebService/OAI/Response/Null.php index ef677fc42df..e02ee83b29a 100644 --- a/library/Class/WebService/OAI/Response/Null.php +++ b/library/Class/WebService/OAI/Response/Null.php @@ -39,7 +39,7 @@ class Class_WebService_OAI_Response_Null { } public function buildXmlOn($builder) { - return ''; + return $builder->error(array('code' => 'badVerb'), 'Illegal OAI verb'); } } diff --git a/library/Class/WebService/OAI/ResponseFactory.php b/library/Class/WebService/OAI/ResponseFactory.php index 85b84876080..a4f0eaff786 100644 --- a/library/Class/WebService/OAI/ResponseFactory.php +++ b/library/Class/WebService/OAI/ResponseFactory.php @@ -19,6 +19,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_WebService_OAI_ResponseFactory { + const RESPONSE_PREFIX = 'Class_WebService_OAI_Response_'; + public static function verbAndBaseUrl($verb, $baseUrl) { $instance = new self(); return $instance->responseForVerbAndBaseUrl($verb, $baseUrl); @@ -32,7 +34,9 @@ class Class_WebService_OAI_ResponseFactory { public function getResponseClassByVerb($verb) { - return 'Class_WebService_OAI_Response_'.$verb; + if (!class_exists(self::RESPONSE_PREFIX . $verb)) + $verb = 'Null'; + return self::RESPONSE_PREFIX . $verb; } } diff --git a/tests/application/modules/opac/controllers/OaiControllerTest.php b/tests/application/modules/opac/controllers/OaiControllerTest.php index c2ee656abe2..fe4d83be682 100644 --- a/tests/application/modules/opac/controllers/OaiControllerTest.php +++ b/tests/application/modules/opac/controllers/OaiControllerTest.php @@ -20,7 +20,7 @@ rf<?php */ require_once 'AbstractControllerTestCase.php'; -abstract class OaiControllerListSetsRequestTestCase extends AbstractControllerTestCase { +abstract class OaiControllerRequestTestCase extends AbstractControllerTestCase { protected $_xpath; public function setUp() { @@ -58,7 +58,7 @@ abstract class OaiControllerListSetsRequestTestCase extends AbstractControllerTe -class OaiControllerIndentifyRequestTest extends OaiControllerListSetsRequestTestCase { +class OaiControllerIndentifyRequestTest extends OaiControllerRequestTestCase { protected $_xpath; public function setUp() { @@ -68,7 +68,7 @@ class OaiControllerIndentifyRequestTest extends OaiControllerListSetsRequestTest /** @test */ - public function identifyShouldReturnIdentifyResponse() { + public function shouldReturnIdentifyResponse() { $this->_xpath->assertXPath($this->_response->getBody(), '//oai:request[@verb="Identify"]'); } @@ -77,7 +77,7 @@ class OaiControllerIndentifyRequestTest extends OaiControllerListSetsRequestTest -class OaiControllerListSetsRequestTest extends OaiControllerListSetsRequestTestCase { +class OaiControllerListSetsRequestTest extends OaiControllerRequestTestCase { protected $_xpath; public function setUp() { @@ -87,9 +87,29 @@ class OaiControllerListSetsRequestTest extends OaiControllerListSetsRequestTestC /** @test */ - public function identifyShouldReturnIdentifyResponse() { + public function shouldReturnListSetsResponse() { $this->_xpath->assertXPath($this->_response->getBody(), '//oai:request[@verb="ListSets"]'); } } + + + +class OaiControllerUnknownVerbRequestTest extends OaiControllerRequestTestCase { + protected $_xpath; + + public function setUp() { + parent::setUp(); + $this->dispatch('/opac/oai/request?verb=DoASpecialThing'); + } + + + /** @test */ + public function shouldReturnErrorResponse() { + $this->_xpath->assertXpathContentContains($this->_response->getBody(), + '//oai:error[@code="badVerb"]', + 'Illegal OAI verb'); + } + +} ?> \ No newline at end of file -- GitLab