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

Prise en compte erreur OAI: badArgument sur Identify

parent 9c3225cb
Branches
Tags
No related merge requests found
......@@ -115,7 +115,8 @@ class OaiController extends Zend_Controller_Action {
$request = new Class_WebService_OAI_Request_Identify($this->_request->getParams(),
$baseUrl);
$this->view->request = $request;
$this->view->builder = new Class_Xml_Builder();
$this->view->builder = $builder = new Class_Xml_Builder();
$this->view->error = $request->getErrorOn($builder);
$this->view->repositoryName = $_SERVER['SERVER_NAME'] . ' Oai repository';
$this->view->baseUrl = $baseUrl;
......
......@@ -4,6 +4,7 @@
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
<responseDate><?php echo date('c');?></responseDate>
<?php echo $this->request->renderOn($this->builder); ?>
<?php echo ($this->error) ? $this->error : '';?>
<Identify>
<repositoryName><![CDATA[<?php echo $this->repositoryName;?>]]></repositoryName>
<baseURL><?php echo $this->baseUrl; ?></baseURL>
......
......@@ -20,14 +20,29 @@
*/
class Class_WebService_OAI_Request_Identify {
protected $_baseUrl;
protected $_params;
public function __construct($params, $baseUrl) {
$this->_baseUrl = $baseUrl;
$this->_params = $params;
foreach(['module',
'action',
'controller',
'current_module',
'verb',
'format'] as $param)
unset($this->_params[$param]);
}
public function renderOn($builder) {
return $builder->request(array('verb' => 'Identify'), $this->_baseUrl);
}
public function getErrorOn($builder) {
if (!empty($this->_params))
return $builder->error(array('code' => 'badArgument'), array_keys($this->_params)[0]);
}
}
?>
\ No newline at end of file
......@@ -57,18 +57,21 @@ abstract class OAIControllerRequestTestCase extends AbstractControllerTestCase {
class OAIControllerIndentifyRequestTest extends OaiControllerRequestTestCase {
protected $_xpath;
public function setUp() {
parent::setUp();
$this->dispatch('/opac/oai/request?verb=Identify');
/** @test */
public function shouldReturnIdentifyResponseWithoutError() {
$this->dispatch('/opac/oai/request?verb=Identify', true);
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:request[@verb="Identify"]');
$this->_xpath->assertNotXPath($this->_response->getBody(),
'//oai:error');
}
/** @test */
public function shouldReturnIdentifyResponse() {
public function shouldReturnErrorBadArgumentWithIllegalParameter() {
$this->dispatch('/opac/oai/request?verb=Identify&test=test', true);
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:request[@verb="Identify"]');
'//oai:error[@code="badArgument"]');
}
}
......
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