From 072405a8e5f3591512b72f0531fd60b26c874e9f Mon Sep 17 00:00:00 2001 From: pbarroca <pbarroca@git-test.afi-sa.fr> Date: Tue, 24 Apr 2012 15:30:43 +0000 Subject: [PATCH] =?UTF-8?q?OAI:=20ajout=20r=C3=A9ponse=20ListIdentifiers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 2 + .../OAI/Response/ListIdentifiers.php | 55 +++++++++ .../OAI/Response/ListIdentifiersTest.php | 115 ++++++++++++++++++ 3 files changed, 172 insertions(+) create mode 100644 library/Class/WebService/OAI/Response/ListIdentifiers.php create mode 100644 tests/library/Class/WebService/OAI/Response/ListIdentifiersTest.php diff --git a/.gitattributes b/.gitattributes index 36f5523c9f4..8e09035e7f4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1765,6 +1765,7 @@ library/Class/WebService/OAI.php -text library/Class/WebService/OAI/CatalogueVisitor.php -text library/Class/WebService/OAI/Response/GetRecord.php -text library/Class/WebService/OAI/Response/Identify.php -text +library/Class/WebService/OAI/Response/ListIdentifiers.php -text library/Class/WebService/OAI/Response/ListSets.php -text library/Class/WebService/OAI/Response/Null.php -text library/Class/WebService/OAI/ResponseFactory.php -text @@ -3491,6 +3492,7 @@ 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/ListSetsTest.php -text tests/library/Class/WebService/OAIIdentify.xml -text tests/library/Class/WebService/OAIListIdentifiers.xml -text diff --git a/library/Class/WebService/OAI/Response/ListIdentifiers.php b/library/Class/WebService/OAI/Response/ListIdentifiers.php new file mode 100644 index 00000000000..ae64d042860 --- /dev/null +++ b/library/Class/WebService/OAI/Response/ListIdentifiers.php @@ -0,0 +1,55 @@ +<?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 + */ +class Class_WebService_OAI_Response_ListIdentifiers extends Class_WebService_OAI_Response_Null { + protected $_notices; + + public function buildXmlOn($builder) { + return + $builder->request(array('verb' => 'ListIdentifiers'), + $this->_baseUrl) + . $this->listIdentifiers($builder); + } + + + public function listIdentifiers($builder) { + return $builder->ListIdentifiers($this->headers($builder)); + } + + + public function headers($builder) { + $visitor = new Class_Notice_DublinCoreVisitor(); + $headers = ''; + foreach ($this->_notices as $notice) { + $visitor->visit($notice); + $headers .= $builder->header($builder->identifier($visitor->getIdentifier()) + . $builder->datestamp($visitor->getDate())); + } + + return $headers; + } + + + public function setNotices($notices) { + $this->_notices = $notices; + } +} + +?> \ No newline at end of file diff --git a/tests/library/Class/WebService/OAI/Response/ListIdentifiersTest.php b/tests/library/Class/WebService/OAI/Response/ListIdentifiersTest.php new file mode 100644 index 00000000000..2fea1bc9f9e --- /dev/null +++ b/tests/library/Class/WebService/OAI/Response/ListIdentifiersTest.php @@ -0,0 +1,115 @@ +<?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 + */ +class ListIdentifiersTest extends Storm_Test_ModelTestCase { + 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'); + $this->_response->setNotices(array(Class_Notice::getLoader() + ->newInstanceWithId(2) + ->setClefAlpha('harrypotter-sorciers') + ->setDateMaj('2001-12-14 11:42:42'), + Class_Notice::getLoader() + ->newInstanceWithId(3) + ->setClefAlpha('harrypotter-chambresecrets') + ->setDateMaj('2005-10-24 11:42:42'), + Class_Notice::getLoader() + ->newInstanceWithId(4) + ->setClefAlpha('harrypotter-azkaban') + ->setDateMaj('2012-04-03 11:42:42'))); + } + + + /** @test */ + public function requestVerbShouldBeListIdentifiers() { + $this->_xpath->assertXPathContentContains($this->_response->xml(), + '//oai:request[@verb="ListIdentifiers"]', + 'http://moulins.fr/oai2/do'); + } + + + /** @test */ + public function shouldHaveThreeHeaders() { + $this->_xpath->assertXpathCount($this->_response->xml(), + '//oai:ListIdentifiers/oai:header', + 3); + } + + + /** @test */ + public function firstIdentifierShouldContainSorciers() { + $this->_assertIdentifierContentAt('sorciers', 1); + } + + + /** @test */ + public function firstDateShouldBeDecemberFourteen2001() { + $this->_assertDateContentAt('2001-12-14', 1); + } + + + + /** @test */ + public function secondIdentifierShouldContainSecrets() { + $this->_assertIdentifierContentAt('secrets', 2); + } + + + /** @test */ + public function secondDateShouldBeOctoberTwentyfourth2005() { + $this->_assertDateContentAt('2005-10-24', 2); + } + + + + /** @test */ + public function thirdIdentifierShouldContainAzkaban() { + $this->_assertIdentifierContentAt('azkaban', 3); + } + + + /** @test */ + public function thirdDateShouldBeAprilThird2013() { + $this->_assertDateContentAt('2012-04-03', 3); + } + + + + protected function _assertIdentifierContentAt($content, $position) { + $this->_assertHeaderContentAt('identifier', $content, $position); + } + + + protected function _assertDateContentAt($content, $position) { + $this->_assertHeaderContentAt('datestamp', $content, $position); + } + + + protected function _assertHeaderContentAt($header, $content, $position) { + $path = sprintf('//oai:ListIdentifiers/oai:header[%s]/oai:%s', + $position, $header); + $this->_xpath->assertXPathContentContains($this->_response->xml(), $path, $content); + } +} +?> \ No newline at end of file -- GitLab