diff --git a/application/modules/opac/controllers/OaiController.php b/application/modules/opac/controllers/OaiController.php index 154c029a88f3b9352f48820f0d3ea127821f89fa..224d2057cb5684a0e81e541110faedb9db2f7a10 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 86e997da689e4e168fd22bdf71c248102cba2d20..d272b6aee7481f87289197d5ee249163f6b02051 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 cd0eb29cd6735635e8534585db7569ca329cc5fc..9ba100a23b97f14081a1486e2228bdcdc66f77e3 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 53cc83ec4e404bcbf8ea3e9360ccbb5906e65864..0e6ff431a3504d6c007c5e5b51d9e08bff2e3cb1 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 455df52b07e0cddab1c2169a58b8576d658a6e27..082986ff7d6f7e05bd15488394789860e2fefea7 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 9f2fc664481f99a08137716d452463175ede37fa..9039fd5d51862998f7830ae6bf9db91dd40efb4c 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 f85389ec16c42905e36261fc8afc4eb263bbcb52..6fca6cd7315b7b32b3781910e97e51e5e8f45fcc 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