diff --git a/.gitattributes b/.gitattributes index db17a7a50b09459f13a61fbdba544a9dda77da08..33390128635e9ec5f8f096e58f59b12e7769940f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -582,6 +582,7 @@ application/modules/opac/views/scripts/java/protoflow.phtml -text application/modules/opac/views/scripts/java/slide_show.phtml -text application/modules/opac/views/scripts/module.phtml -text application/modules/opac/views/scripts/noticeajax/notice.phtml -text +application/modules/opac/views/scripts/oai/list-identifiers.xml.phtml -text application/modules/opac/views/scripts/panier/error.phtml -text application/modules/opac/views/scripts/panier/export.phtml -text application/modules/opac/views/scripts/panier/index.phtml -text @@ -3431,7 +3432,8 @@ tests/application/modules/opac/controllers/CmsControllerTest.php -text tests/application/modules/opac/controllers/FormulaireContactTest.php -text tests/application/modules/opac/controllers/IndexControllerTranslationTest.php -text tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php -text -tests/application/modules/opac/controllers/OaiControllerTest.php -text +tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php -text +tests/application/modules/opac/controllers/OAIControllerTest.php -text tests/application/modules/opac/controllers/PanierControllerTest.php -text tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php -text tests/application/modules/opac/controllers/RechercheAvanceeTest.php -text @@ -3509,7 +3511,6 @@ tests/library/Class/VodeclicLinkTest.php -text tests/library/Class/WebService/BabelioTest.php -text tests/library/Class/WebService/OAI/Response/GetRecordTest.php -text tests/library/Class/WebService/OAI/Response/IdentifyTest.php -text -tests/library/Class/WebService/OAI/Response/ListIdentifiersTest.php -text tests/library/Class/WebService/OAI/Response/ListMetadataFormatsTest.php -text tests/library/Class/WebService/OAI/Response/ListRecordsTest.php -text tests/library/Class/WebService/OAI/Response/ListSetsTest.php -text diff --git a/application/modules/opac/controllers/OaiController.php b/application/modules/opac/controllers/OaiController.php index 920504b267b01405f25b60d3bb19dd31204ea810..fa519c388c77c92838ceeb276046174d91c89aff 100644 --- a/application/modules/opac/controllers/OaiController.php +++ b/application/modules/opac/controllers/OaiController.php @@ -19,10 +19,25 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class OaiController extends Zend_Controller_Action { + public function init() { + $this->_helper->getHelper('contextSwitch') + ->addActionContext('list-identifiers', 'xml') + ->initContext(); + } + + public function requestAction() { $this->getResponse()->setHeader('Content-Type', 'text/xml;charset=utf-8'); $this->getHelper('ViewRenderer')->setNoRender(); + if ('ListIdentifiers' == $this->_getParam('verb')) { + $this->_forward('list-identifiers', + null, + null, + $this->_request->getParams() + array('format' => 'xml')); + return; + } + $request = Class_WebService_OAI_ResponseFactory::verbAndBaseUrl($this->_getParam('verb'), $this->buildBaseUrl()); $this->_response->setBody($request->xml($this->_request->getParams())); @@ -33,6 +48,29 @@ class OaiController extends Zend_Controller_Action { return $this->_request->getScheme() . ':' . $_SERVER['SERVER_NAME'] . BASE_URL . '/opac/oai/request'; } + + + public function listIdentifiersAction() { + $this->getHelper('ViewRenderer')->setLayoutScript('empty.phtml'); + $request = new Class_WebService_OAI_Request_ListIdentifiers($this->_request->getParams(), + $this->buildBaseUrl()); + $builder = new Class_Xml_Builder(); + $this->view->request = $request; + $this->view->error = $request->getErrorOn($builder); + + if ($notices = $request->getNotices()) { + $visitor = new Class_Notice_DublinCoreVisitor(); + $recordBuilder = new Class_WebService_OAI_Response_RecordHeadersBuilder(); + $headers = ''; + foreach ($notices as $notice) { + $visitor->visit($notice); + $headers .= $recordBuilder->xml($builder, $visitor); + } + $this->view->headers = $headers; + } + $this->view->builder = $builder; + $this->view->token = $request->getToken(); + } } ?> \ No newline at end of file diff --git a/application/modules/opac/views/scripts/oai/list-identifiers.xml.phtml b/application/modules/opac/views/scripts/oai/list-identifiers.xml.phtml new file mode 100644 index 0000000000000000000000000000000000000000..1ed2fa75e78b2ba0eb46d1d648b186e2bc351d5c --- /dev/null +++ b/application/modules/opac/views/scripts/oai/list-identifiers.xml.phtml @@ -0,0 +1,36 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +echo '<?xml version="1.0" ?>' +?> +<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + 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 : '';?> + <?php if ($this->headers) { ?> + <ListIdentifiers> + <?php echo $this->headers; ?> + </ListIdentifiers> + <?php } ?> + <?php echo ($this->token) ? $this->token->renderOn($this->builder): '' ?> +</OAI-PMH> diff --git a/tests/library/Class/WebService/OAI/Response/ListIdentifiersTest.php b/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php similarity index 77% rename from tests/library/Class/WebService/OAI/Response/ListIdentifiersTest.php rename to tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php index 6f639a52c5c3adf6afb3327b3913b2dd75050652..06e147e2e4a2d4f0cfe1bf5ef2e51e68f0a44eb4 100644 --- a/tests/library/Class/WebService/OAI/Response/ListIdentifiersTest.php +++ b/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php @@ -18,14 +18,18 @@ * along with AFI-OPAC 2.0; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class ListIdentifiersValidTest extends Storm_Test_ModelTestCase { +require_once 'AbstractControllerTestCase.php'; + + +class OAIControllerListIdentifiersValidTest extends AbstractControllerTestCase { protected $_xpath; protected $_response; + protected $_xml; public function setUp() { parent::setUp(); $this->_xpath = TestXPathFactory::newOai(); - $this->_response = new Class_WebService_OAI_Response_ListIdentifiers('http://moulins.fr/oai2/do'); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') ->whenCalled('countNoticesFor') ->answers(3) @@ -43,15 +47,27 @@ class ListIdentifiersValidTest extends Storm_Test_ModelTestCase { ->newInstanceWithId(4) ->setClefAlpha('harrypotter-azkaban') ->setDateMaj('2012-04-03 11:42:42'))); - $this->_xml = $this->_response->xml(array('metadataPrefix' => 'oai_dc')); + $this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc'); + $this->_xml = $this->_response->getBody(); + } + + + /** @test */ + public function controllerShouldBeOai() { + $this->assertController('oai'); + } + + + /** @test */ + public function actionShouldBeRequest() { + $this->assertAction('list-identifiers'); } /** @test */ public function requestVerbShouldBeListIdentifiers() { - $this->_xpath->assertXPathContentContains($this->_xml, - '//oai:request[@verb="ListIdentifiers"]', - 'http://moulins.fr/oai2/do'); + $this->_xpath->assertXPath($this->_xml, + '//oai:request[@verb="ListIdentifiers"]'); } @@ -135,11 +151,13 @@ class ListIdentifiersValidTest extends Storm_Test_ModelTestCase { } -class ListIdentifiersWithPaginatorTest extends Storm_Test_ModelTestCase { +class OAIControllerListIdentifiersWithPaginatorTest extends AbstractControllerTestCase { + protected $_xpath; + protected $_xml; + public function setUp() { parent::setUp(); $this->_xpath = TestXPathFactory::newOai(); - $this->_response = new Class_WebService_OAI_Response_ListIdentifiers('http://moulins.fr/oai2/do'); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') ->whenCalled('countNoticesFor') ->answers(10000) @@ -157,7 +175,8 @@ class ListIdentifiersWithPaginatorTest extends Storm_Test_ModelTestCase { ->newInstanceWithId(4) ->setClefAlpha('harrypotter-azkaban') ->setDateMaj('2012-04-03 11:42:42'))); - $this->_xml = $this->_response->xml(array('metadataPrefix' => 'oai_dc')); + $this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc'); + $this->_xml = $this->_response->getBody(); } @@ -169,14 +188,12 @@ class ListIdentifiersWithPaginatorTest extends Storm_Test_ModelTestCase { } -class ListIdentifiersInvalidParamsTest extends Storm_Test_ModelTestCase { +class OAIControllerListIdentifiersInvalidParamsTest extends AbstractControllerTestCase { protected $_xpath; - protected $_response; public function setUp() { parent::setUp(); $this->_xpath = TestXPathFactory::newOai(); - $this->_response = new Class_WebService_OAI_Response_ListIdentifiers('http://moulins.fr/oai2/do'); } @@ -188,13 +205,16 @@ class ListIdentifiersInvalidParamsTest extends Storm_Test_ModelTestCase { /** @test */ public function withoutMetadataPrefixErrorCodeShouldBeBadArgument() { - $this->_xpath->assertXPath($this->_response->xml(array()), '//oai:error[@code="badArgument"]'); + $this->dispatch('/opac/oai/request?verb=ListIdentifiers'); + $this->_xpath->assertXPath($this->_response->getBody(), + '//oai:error[@code="badArgument"]'); } /** @test */ public function withUnknownFormatErrorCodeShouldBeCannotDisseminateFormat() { - $this->_xpath->assertXpath($this->_response->xml(array('metadataPrefix' => 'zork')), + $this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=zork'); + $this->_xpath->assertXpath($this->_response->getBody(), '//oai:error[@code="cannotDisseminateFormat"]'); } @@ -204,8 +224,8 @@ class ListIdentifiersInvalidParamsTest extends Storm_Test_ModelTestCase { Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') ->whenCalled('findAllBy') ->answers(array()); - $this->_xpath->assertXPath($this->_response->xml(array('metadataPrefix' => 'oai_dc', - 'set' => 'jeunesse:bd')), + $this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=' . urlencode('jeunesse:bd')); + $this->_xpath->assertXPath($this->_response->getBody(), '//oai:error[@code="badArgument"]'); } @@ -215,7 +235,8 @@ class ListIdentifiersInvalidParamsTest extends Storm_Test_ModelTestCase { Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice') ->whenCalled('countBy') ->answers(0); - $this->_xpath->assertXPath($this->_response->xml(array('metadataPrefix' => 'oai_dc')), + $this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc'); + $this->_xpath->assertXPath($this->_response->getBody(), '//oai:error[@code="noRecordsMatch"]'); } @@ -226,8 +247,8 @@ class ListIdentifiersInvalidParamsTest extends Storm_Test_ModelTestCase { ->whenCalled('load') ->answers(false); Class_WebService_OAI_ResumptionToken::defaultCache($cache); - $this->_xpath->assertXPath($this->_response->xml(array('metadataPrefix' => 'oai_dc', - 'resumptionToken' => 'Zork')), + $this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&resumptionToken=Zork'); + $this->_xpath->assertXPath($this->_response->getBody(), '//oai:error[@code="badResumptionToken"]'); } } diff --git a/tests/application/modules/opac/controllers/OaiControllerTest.php b/tests/application/modules/opac/controllers/OAIControllerTest.php similarity index 96% rename from tests/application/modules/opac/controllers/OaiControllerTest.php rename to tests/application/modules/opac/controllers/OAIControllerTest.php index 947d9090b7e561bad9df92001927804879710357..e6b71bb11413b36de746a7fbac8fed0b8df067ea 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 OaiControllerRequestTestCase extends AbstractControllerTestCase { +abstract class OAIControllerRequestTestCase extends AbstractControllerTestCase { protected $_xpath; public function setUp() { @@ -58,7 +58,7 @@ abstract class OaiControllerRequestTestCase extends AbstractControllerTestCase { -class OaiControllerIndentifyRequestTest extends OaiControllerRequestTestCase { +class OAIControllerIndentifyRequestTest extends OaiControllerRequestTestCase { protected $_xpath; public function setUp() {