From b465529dc081a228b4f1cce770e1c730d09ba515 Mon Sep 17 00:00:00 2001 From: pbarroca <pbarroca@git-test.afi-sa.fr> Date: Thu, 3 May 2012 10:32:42 +0000 Subject: [PATCH] =?UTF-8?q?OAI:=20Refacto=20ListIdentifiers=20est=20trait?= =?UTF-8?q?=C3=A9=20via=20MVC=20+=20apparition=20du=20premier=20objet=20re?= =?UTF-8?q?quest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 5 +- .../opac/controllers/OaiController.php | 38 ++++++++++++ .../scripts/oai/list-identifiers.xml.phtml | 36 +++++++++++ .../OAIControllerListIdentifiersTest.php} | 59 +++++++++++++------ ...ntrollerTest.php => OAIControllerTest.php} | 4 +- 5 files changed, 119 insertions(+), 23 deletions(-) create mode 100644 application/modules/opac/views/scripts/oai/list-identifiers.xml.phtml rename tests/{library/Class/WebService/OAI/Response/ListIdentifiersTest.php => application/modules/opac/controllers/OAIControllerListIdentifiersTest.php} (77%) rename tests/application/modules/opac/controllers/{OaiControllerTest.php => OAIControllerTest.php} (96%) diff --git a/.gitattributes b/.gitattributes index db17a7a50b0..33390128635 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 920504b267b..fa519c388c7 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 00000000000..1ed2fa75e78 --- /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 6f639a52c5c..06e147e2e4a 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 947d9090b7e..e6b71bb1141 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() { -- GitLab