From 7c2fc7dd447c2572957ddb2be797e634d8276d43 Mon Sep 17 00:00:00 2001 From: pbarroca <pbarroca@git-test.afi-sa.fr> Date: Mon, 7 May 2012 16:38:15 +0000 Subject: [PATCH] =?UTF-8?q?OAI:=20reprise=20du=20set=20dans=20chaque=20enr?= =?UTF-8?q?egistrement=20si=20pass=C3=A9=20en=20requ=C3=AAte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/opac/controllers/OaiController.php | 2 ++ library/Class/Notice/DublinCoreVisitor.php | 12 ++++++++++++ .../WebService/OAI/Response/RecordBuilder.php | 7 +++++-- .../OAIControllerListIdentifiersTest.php | 12 ++++++++++-- .../controllers/OAIControllerListRecordsTest.php | 15 ++++++++++++++- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/application/modules/opac/controllers/OaiController.php b/application/modules/opac/controllers/OaiController.php index 20d2e1d8ae8..27ce936db97 100644 --- a/application/modules/opac/controllers/OaiController.php +++ b/application/modules/opac/controllers/OaiController.php @@ -71,6 +71,7 @@ class OaiController extends Zend_Controller_Action { if ($notices = $request->getNotices()) { $visitor = new Class_Notice_DublinCoreVisitor(); + $visitor->setGlobalSetSpec($this->_getParam('set')); $recordBuilder = new Class_WebService_OAI_Response_RecordHeadersBuilder(); $headers = ''; foreach ($notices as $notice) { @@ -94,6 +95,7 @@ class OaiController extends Zend_Controller_Action { if ($notices = $request->getNotices()) { $visitor = new Class_Notice_DublinCoreVisitor(); + $visitor->setGlobalSetSpec($this->_getParam('set')); $recordBuilder = new Class_WebService_OAI_Response_RecordBuilder(); $records = ''; foreach ($notices as $notice) { diff --git a/library/Class/Notice/DublinCoreVisitor.php b/library/Class/Notice/DublinCoreVisitor.php index c1d0cfa94ae..8f1ca226cef 100644 --- a/library/Class/Notice/DublinCoreVisitor.php +++ b/library/Class/Notice/DublinCoreVisitor.php @@ -24,6 +24,7 @@ class Class_Notice_DublinCoreVisitor { protected $_builder; protected $_identifier; protected $_date; + protected $_globalSetSpec; public function __construct() { @@ -90,6 +91,17 @@ class Class_Notice_DublinCoreVisitor { public function cdata($value) { return $this->_builder->cdata($value); } + + + public function setGlobalSetSpec($spec) { + $this->_globalSetSpec = $spec; + return $this; + } + + + public function getGlobalSetSpec() { + return $this->_globalSetSpec; + } } ?> \ No newline at end of file diff --git a/library/Class/WebService/OAI/Response/RecordBuilder.php b/library/Class/WebService/OAI/Response/RecordBuilder.php index a85c41cc008..cfc49f0551e 100644 --- a/library/Class/WebService/OAI/Response/RecordBuilder.php +++ b/library/Class/WebService/OAI/Response/RecordBuilder.php @@ -27,8 +27,11 @@ class Class_WebService_OAI_Response_RecordBuilder { public function buildHeaders($builder, $visitor) { - return $builder->header($builder->identifier($visitor->getIdentifier()) - . $builder->datestamp($visitor->getDate())); + $header = $builder->identifier($visitor->getIdentifier()) + . $builder->datestamp($visitor->getDate()); + if ($visitor->getGlobalSetSpec()) + $header .= $builder->setSpec($visitor->getGlobalSetSpec()); + return $builder->header($header); } diff --git a/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php b/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php index b0ea4edf2f7..c4d153fdbb6 100644 --- a/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php +++ b/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php @@ -34,6 +34,10 @@ class OAIControllerListIdentifiersValidTest extends AbstractControllerTestCase { ->whenCalled('countNoticesFor') ->answers(3) + ->whenCalled('findAllBy') + ->with(array('oai_spec' => 'zork')) + ->answers(array(Class_Catalogue::getLoader()->newInstanceWithId(2))) + ->whenCalled('loadNoticesFor') ->answers(array(Class_Notice::getLoader() ->newInstanceWithId(2) @@ -47,7 +51,7 @@ class OAIControllerListIdentifiersValidTest extends AbstractControllerTestCase { ->newInstanceWithId(4) ->setClefAlpha('harrypotter-azkaban') ->setDateMaj('2012-04-03 11:42:42'))); - $this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc'); + $this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork'); $this->_xml = $this->_response->getBody(); } @@ -114,6 +118,11 @@ class OAIControllerListIdentifiersValidTest extends AbstractControllerTestCase { } + /** @test */ + public function firstSetSpecShouldBeZork() { + $this->_assertHeaderContentAt('setSpec', 'zork', 1); + } + /** @test */ public function secondIdentifierShouldContainSecrets() { @@ -127,7 +136,6 @@ class OAIControllerListIdentifiersValidTest extends AbstractControllerTestCase { } - /** @test */ public function thirdIdentifierShouldContainAzkaban() { $this->_assertIdentifierContentAt('azkaban', 3); diff --git a/tests/application/modules/opac/controllers/OAIControllerListRecordsTest.php b/tests/application/modules/opac/controllers/OAIControllerListRecordsTest.php index 725640b6f1b..83f645a26e4 100644 --- a/tests/application/modules/opac/controllers/OAIControllerListRecordsTest.php +++ b/tests/application/modules/opac/controllers/OAIControllerListRecordsTest.php @@ -28,6 +28,13 @@ class OAIControllerListRecordsTest extends AbstractControllerTestCase { $this->_xpath = TestXPathFactory::newOaiDc(); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') + ->whenCalled('findAllBy') + ->with(array('oai_spec' => 'zork')) + ->answers(array(Class_Catalogue::getLoader()->newInstanceWithId(2))) + + ->whenCalled('countNoticesFor') + ->answers(3) + ->whenCalled('loadNoticesFor') ->answers(array(Class_Notice::getLoader() ->newInstanceWithId(2) @@ -42,7 +49,7 @@ class OAIControllerListRecordsTest extends AbstractControllerTestCase { ->newInstanceWithId(4) ->setClefAlpha('harrypotter-azkaban') ->setDateMaj('2012-04-03 11:42:42'))); - $this->dispatch('/opac/oai/request?verb=ListRecords&metadataPrefix=oai_dc'); + $this->dispatch('/opac/oai/request?verb=ListRecords&metadataPrefix=oai_dc&set=zork'); } @@ -67,6 +74,12 @@ class OAIControllerListRecordsTest extends AbstractControllerTestCase { } + /** @test */ + public function firstSetSpecShouldBeZork() { + $this->_assertHeaderContentAt('setSpec', 'zork', 1); + } + + /** @test */ public function secondIdentifierShouldContainSecrets() { $this->_assertHeaderContentAt('identifier', 'secrets', 2); -- GitLab