From 7115132c785d9c3f54e0bd9ef44f2da8c2ab12a3 Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Mon, 10 Dec 2012 11:02:42 +0000 Subject: [PATCH] Correction validation OAI: (23) Testing : ListMetadataFormats (illegal_id) --- .../opac/controllers/OaiController.php | 4 +++- .../oai/list-metadata-formats.xml.phtml | 19 +++++++++------ library/Class/Notice.php | 6 +++++ .../WebService/OAI/Request/GetRecord.php | 5 ++-- .../OAI/Request/ListMetadataFormats.php | 6 +++++ .../OAIControllerGetRecordTest.php | 4 ++-- .../OAIControllerListMetadataFormatsTest.php | 23 ++++++++++++++++++- 7 files changed, 53 insertions(+), 14 deletions(-) diff --git a/application/modules/opac/controllers/OaiController.php b/application/modules/opac/controllers/OaiController.php index 154c029a88f..224d2057cb5 100644 --- a/application/modules/opac/controllers/OaiController.php +++ b/application/modules/opac/controllers/OaiController.php @@ -132,7 +132,9 @@ class OaiController extends Zend_Controller_Action { $request = new Class_WebService_OAI_Request_ListMetadataFormats($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); + } diff --git a/application/modules/opac/views/scripts/oai/list-metadata-formats.xml.phtml b/application/modules/opac/views/scripts/oai/list-metadata-formats.xml.phtml index 86e997da689..d272b6aee74 100644 --- a/application/modules/opac/views/scripts/oai/list-metadata-formats.xml.phtml +++ b/application/modules/opac/views/scripts/oai/list-metadata-formats.xml.phtml @@ -4,11 +4,16 @@ 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); ?> - <ListMetadataFormats> - <metadataFormat> - <metadataPrefix>oai_dc</metadataPrefix> - <schema>http://www.openarchives.org/OAI/2.0/oai_dc.xsd</schema> - <metadataNamespace>http://www.openarchives.org/OAI/2.0/oai_dc/</metadataNamespace> - </metadataFormat> - </ListMetadataFormats> + <?php + if ($this->error) + echo $this->error; + else { ?> + <ListMetadataFormats> + <metadataFormat> + <metadataPrefix>oai_dc</metadataPrefix> + <schema>http://www.openarchives.org/OAI/2.0/oai_dc.xsd</schema> + <metadataNamespace>http://www.openarchives.org/OAI/2.0/oai_dc/</metadataNamespace> + </metadataFormat> + </ListMetadataFormats> + <?php } ?> </OAI-PMH> \ No newline at end of file diff --git a/library/Class/Notice.php b/library/Class/Notice.php index cd0eb29cd67..9ba100a23b9 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -43,6 +43,12 @@ class NoticeLoader extends Storm_Model_Loader } + public function getNoticeByOAIIdentifier($identifier) { + $parts = explode(':', $identifier); + return Class_Notice::getLoader()->getNoticeByClefAlpha(end($parts)); + } + + public function getNoticeByClefAlpha($clef) { return Class_Notice::findFirstBy(['clef_alpha' => $clef]); } diff --git a/library/Class/WebService/OAI/Request/GetRecord.php b/library/Class/WebService/OAI/Request/GetRecord.php index 53cc83ec4e4..0e6ff431a35 100644 --- a/library/Class/WebService/OAI/Request/GetRecord.php +++ b/library/Class/WebService/OAI/Request/GetRecord.php @@ -45,9 +45,8 @@ class Class_WebService_OAI_Request_GetRecord { if (!$this->_identifier) return $builder->error(array('code' => 'badArgument'), 'Missing identifier'); - - $parts = explode(':', $this->_identifier); - $this->_notice = Class_Notice::getLoader()->getNoticeByClefAlpha(end($parts)); + + $this->_notice = Class_Notice::getNoticeByOAIIdentifier($this->_identifier); if (!$this->_notice) return $builder->error(array('code' => 'idDoesNotExist')); diff --git a/library/Class/WebService/OAI/Request/ListMetadataFormats.php b/library/Class/WebService/OAI/Request/ListMetadataFormats.php index 455df52b07e..082986ff7d6 100644 --- a/library/Class/WebService/OAI/Request/ListMetadataFormats.php +++ b/library/Class/WebService/OAI/Request/ListMetadataFormats.php @@ -29,6 +29,12 @@ class Class_WebService_OAI_Request_ListMetadataFormats { } + public function getErrorOn($builder) { + if (!Class_Notice::getNoticeByOAIIdentifier($this->_identifier)) + return $builder->error(['code' => 'idDoesNotExist']); + } + + public function renderOn($builder) { $attributes = array('verb' => 'ListMetadataFormats'); if ($this->_identifier) diff --git a/tests/application/modules/opac/controllers/OAIControllerGetRecordTest.php b/tests/application/modules/opac/controllers/OAIControllerGetRecordTest.php index 9f2fc664481..9039fd5d518 100644 --- a/tests/application/modules/opac/controllers/OAIControllerGetRecordTest.php +++ b/tests/application/modules/opac/controllers/OAIControllerGetRecordTest.php @@ -90,7 +90,7 @@ class OAIControllerGetRecordNotFoundParamsTest extends OAIControllerGetRecordTes ->with('harrypotter-sorciers') ->answers(null); - $this->dispatch('/opac/oai/request?verb=GetRecord&metadataPrefix=oai_dc&identifier=harrypotter-sorciers'); + $this->dispatch('/opac/oai/request?verb=GetRecord&metadataPrefix=oai_dc&identifier=harrypotter-sorciers', true); $this->_xml = $this->_response->getBody(); } @@ -156,7 +156,7 @@ class OAIControllerGetRecordValidParamsTest extends OAIControllerGetRecordTestCa ->setTitrePrincipal('Harry Potter a l\'ecole des sorciers') ->setDateMaj('2001-12-14 11:39:44')); - $this->dispatch('/opac/oai/request?verb=GetRecord&metadataPrefix=oai_dc&identifier=harrypotter-sorciers'); + $this->dispatch('/opac/oai/request?verb=GetRecord&metadataPrefix=oai_dc&identifier=harrypotter-sorciers', true); $this->_xml = $this->_response->getBody(); } diff --git a/tests/application/modules/opac/controllers/OAIControllerListMetadataFormatsTest.php b/tests/application/modules/opac/controllers/OAIControllerListMetadataFormatsTest.php index f85389ec16c..6fca6cd7315 100644 --- a/tests/application/modules/opac/controllers/OAIControllerListMetadataFormatsTest.php +++ b/tests/application/modules/opac/controllers/OAIControllerListMetadataFormatsTest.php @@ -20,12 +20,21 @@ */ require_once 'AbstractControllerTestCase.php'; -class OAIControllerListMetadataFormatsTest extends AbstractControllerTestCase { +abstract class OAIControllerListMetadataFormatsTestCase extends AbstractControllerTestCase { protected $_xpath; public function setUp() { parent::setUp(); $this->_xpath = TestXPathFactory::newOai(); + } +} + + + + +class OAIControllerListMetadataFormatsValidTest extends OAIControllerListMetadataFormatsTest { + public function setUp() { + parent::setUp(); $this->dispatch('/opac/oai/request?verb=ListMetadataFormats'); } @@ -81,4 +90,16 @@ class OAIControllerListMetadataFormatsTest extends AbstractControllerTestCase { $this->_xpath->assertXpathContentContains($this->_response->getBody(), $path, $content); } } + + + + +class OAIControllerListMetadataFormatsTest extends OAIControllerListMetadataFormatsTestCase { + /** @test */ + public function withWrongIdentifierShouldReturnErrorIdDoesNotExist() { + $this->dispatch('/opac/oai/request?verb=ListMetadataFormats&identifier=really_wrong_id', true); + $this->_xpath->assertXPath($this->_response->getBody(), + '//oai:error[@code="idDoesNotExist"]'); + } +} ?> \ No newline at end of file -- GitLab