diff --git a/application/modules/opac/controllers/OaiController.php b/application/modules/opac/controllers/OaiController.php index 20d2e1d8ae859132e2a5a846109c08d48e2f1548..27ce936db971aecfd1f6c18350ac611fac743e8d 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 c1d0cfa94ae834b7ffef942f785ca1ecf919dc92..8f1ca226cef9491ce713094c5807f1901b88cc7d 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 a85c41cc00816b10d5832e041ed39b0346f6fa79..cfc49f0551ea1b3ba51b1b40eb9844eddb784109 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 b0ea4edf2f7252ceba9f79a04dc9627fc4da8335..c4d153fdbb69643c5eb405084c4af6435a2c740a 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 725640b6f1b22d0d68a08fbc6a877350a6134b44..83f645a26e4aa661c65451531e66efe76d25702b 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);