diff --git a/.gitattributes b/.gitattributes index b0858f9db82f26c422af42f974e538dc5155e469..7324f195a89d3d2d9b8e1bb5f58465b1fd63acf3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1761,6 +1761,7 @@ library/Class/WebService/Lastfm.php -text library/Class/WebService/LibraryThing.php -text library/Class/WebService/MappedSoapClient.php -text library/Class/WebService/OAI.php -text +library/Class/WebService/OAI/Response/Identify.php -text library/Class/WebService/Premiere.php -text library/Class/WebService/ReseauxSociaux.php -text library/Class/WebService/ResumptionToken.php -text @@ -1815,6 +1816,7 @@ library/Class/WebService/SimpleWebClient.php -text library/Class/WebService/Vignette.php -text library/Class/WebService/XMLParser.php -text library/Class/Xml.php -text +library/Class/Xml/Builder.php -text library/Class/Zone.php -text library/Thumbs/GdThumb.inc.php -text library/Thumbs/PhpThumb.inc.php -text @@ -3478,6 +3480,7 @@ tests/library/Class/UserGroupTest.php -text tests/library/Class/UsersTest.php -text tests/library/Class/VodeclicLinkTest.php -text tests/library/Class/WebService/BabelioTest.php -text +tests/library/Class/WebService/OAI/Response/IdentifyTest.php -text tests/library/Class/WebService/OAIIdentify.xml -text tests/library/Class/WebService/OAIListIdentifiers.xml -text tests/library/Class/WebService/OAIListRecords.xml -text diff --git a/library/Class/WebService/OAI/Response/Identify.php b/library/Class/WebService/OAI/Response/Identify.php new file mode 100644 index 0000000000000000000000000000000000000000..11e6c7a8b31394f86632260320623049ce257d06 --- /dev/null +++ b/library/Class/WebService/OAI/Response/Identify.php @@ -0,0 +1,45 @@ +<?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_Identify { + protected $_baseUrl; + + public function __construct($baseUrl) { + $this->_baseUrl = $baseUrl; + } + + + public function xml() { + $builder = new Class_Xml_Builder(); + + return + $builder->_tag(array('OAI-PMH' => array('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')), + $builder->responseDate(date('c')). + $builder->request(array('verb' => 'Identify'), + $this->_baseUrl)); + } +} + + +?> \ No newline at end of file diff --git a/library/Class/Xml/Builder.php b/library/Class/Xml/Builder.php new file mode 100644 index 0000000000000000000000000000000000000000..850911822b59d264d43bebea6c38497753ea21d7 --- /dev/null +++ b/library/Class/Xml/Builder.php @@ -0,0 +1,47 @@ +<?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_Xml_Builder { + public function __call($method, $arguments) { + if (is_array($first_arg = $arguments[0])) + return $this->_tag(array($method => $first_arg), $arguments[1]); + return $this->_tag($method, $first_arg); + } + + + public function _tag($tag, $content) { + if (!is_array($tag)) + return $this->_xmlString((string)$tag, $content); + + $attributes = ''; + foreach (current($tag) as $k => $v) + $attributes .= ' ' . $k . '="' . $v . '"'; + + return $this->_xmlString(key($tag), $content, $attributes); + } + + + public function _xmlString($name, $content, $attributes = '') { + return '<'.$name.$attributes.'>'.$content.'</'.$name.'>'; + } +} + +?> \ No newline at end of file diff --git a/tests/library/Class/WebService/OAI/Response/IdentifyTest.php b/tests/library/Class/WebService/OAI/Response/IdentifyTest.php new file mode 100644 index 0000000000000000000000000000000000000000..92e873dae82260593dd757621838df8c32352e34 --- /dev/null +++ b/tests/library/Class/WebService/OAI/Response/IdentifyTest.php @@ -0,0 +1,51 @@ +<?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 OAIIdentifyTest extends Storm_Test_ModelTestCase { + protected $_xpath; + protected $_response; + + public function setUp() { + parent::setUp(); + $this->_xpath = new Storm_Test_XPathXML(); + $this->_xpath->registerNameSpace('oai', 'http://www.openarchives.org/OAI/2.0/'); + $this->_response = new Class_WebService_OAI_Response_Identify('http://moulins.fr/oai2/do'); + } + + + /** @test */ + public function responseDateShouldBeNow() { + $this->_xpath->assertXPathContentContains($this->_response->xml(), + '//oai:responseDate', + date('Y-m-d')); + + } + + + /** @test */ + public function requestVerbShouldBeIdentify() { + $this->_xpath->assertXpathContentContains($this->_response->xml(), + '//oai:request[@verb="Identify"]', + 'http://moulins.fr/oai2/do'); + } +} +?> \ No newline at end of file