Newer
Older
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* 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).
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once 'AbstractControllerTestCase.php';
abstract class OAIControllerGetRecordTestCase extends AbstractControllerTestCase {
const OAI_RECORD_PATH = '//oai:GetRecord/oai:record/';
const OAI_HEADER_PATH = 'oai:header/';
public function setUp() {
parent::setUp();
$this->_xpath = TestXPathFactory::newOaiDc();
}

pbarroca
committed
}
class OAIControllerGetRecordNoIdentifierTest extends OAIControllerGetRecordTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/opac/oai/request?verb=GetRecord&metadataPrefix=oai_dc');
$this->_xml = $this->_response->getBody();
}

pbarroca
committed
/** @test */
public function requestVerbShouldBeGetRecord() {
$this->_xpath->assertXpath($this->_xml,
'//oai:request[@verb="GetRecord"][@metadataPrefix="oai_dc"]');
}

pbarroca
committed
/** @test */
public function errorCodeShouldBeBadArgument() {
$this->_xpath->assertXpath($this->_xml,
'//oai:error[@code="badArgument"]');
}

pbarroca
committed
}
class OAIControllerGetRecordNoMetadataPrefixTest extends OAIControllerGetRecordTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/opac/oai/request?verb=GetRecord&identifier=toto');
$this->_xml = $this->_response->getBody();
}

pbarroca
committed
/** @test */
public function requestVerbShouldBeGetRecord() {
$this->_xpath->assertXpath($this->_xml,
'//oai:request[@verb="GetRecord"][@identifier="toto"]');
}

pbarroca
committed
/** @test */
public function errorCodeShouldBeBadArgument() {
$this->_xpath->assertXpath($this->_xml,
'//oai:error[@code="badArgument"]');
}

pbarroca
committed
}
class OAIControllerGetRecordNotFoundParamsTest extends OAIControllerGetRecordTestCase {

pbarroca
committed
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice')
->whenCalled('getNoticeByClefAlpha')
->with('harrypotter-sorciers')
->answers(null);

pbarroca
committed
$this->dispatch('/opac/oai/request?verb=GetRecord&metadataPrefix=oai_dc&identifier=harrypotter-sorciers\"id', true);
$this->_xml = $this->_response->getBody();
}

pbarroca
committed
/** @test */
public function requestVerbShouldBeGetRecord() {
$this->_xpath->assertXpath($this->_xml,
'//oai:request[@verb="GetRecord"][contains(@identifier, "harrypotter-sorciers")][@metadataPrefix="oai_dc"]');
}

pbarroca
committed
/** @test */
public function errorCodeShouldBeIdDoesNotExist() {
$this->_xpath->assertXpath($this->_xml,
'//oai:error[@code="idDoesNotExist"]');
}

pbarroca
committed
}
class OAIControllerGetRecordNotSupportedPrefixTest extends OAIControllerGetRecordTestCase {

pbarroca
committed
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice')
->whenCalled('getNoticeByClefAlpha')
->with('harrypotter-sorciers')
->answers(Class_Notice::getLoader()
->newInstanceWithId(4)
->setClefAlpha('harrypotter-sorciers')
->setTitrePrincipal('Harry Potter a l\'ecole des sorciers')
->setDateMaj('2001-12-14 11:39:44'));

pbarroca
committed
$this->dispatch('/opac/oai/request?verb=GetRecord&metadataPrefix=not_supported&identifier=harrypotter-sorciers');
$this->_xml = $this->_response->getBody();
}

pbarroca
committed
/** @test */
public function requestVerbShouldBeGetRecord() {
$this->_xpath->assertXpath($this->_xml,
'//oai:request[@verb="GetRecord"][@identifier="harrypotter-sorciers"][@metadataPrefix="not_supported"]');
}

pbarroca
committed
/** @test */
public function errorCodeShouldBeCannotDisseminateFormat() {
$this->_xpath->assertXpath($this->_xml,
'//oai:error[@code="cannotDisseminateFormat"]');
}

pbarroca
committed
}
class OAIControllerGetRecordValidParamsTest extends OAIControllerGetRecordTestCase {
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
public function setUp() {
parent::setUp();
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice')
->whenCalled('getNoticeByClefAlpha')
->with('harrypotter-sorciers')
->answers(Class_Notice::getLoader()
->newInstanceWithId(4)
->setClefAlpha('harrypotter-sorciers')
->setTitrePrincipal('Harry Potter a l\'ecole des sorciers')
->setDateMaj('2001-12-14 11:39:44'));
$this->dispatch('/opac/oai/request?verb=GetRecord&metadataPrefix=oai_dc&identifier=harrypotter-sorciers', true);
$this->_xml = $this->_response->getBody();
}
/** @test */
public function requestVerbShouldBeGetRecord() {
$this->_xpath->assertXpath($this->_xml,
'//oai:request[@verb="GetRecord"][@identifier="harrypotter-sorciers"][@metadataPrefix="oai_dc"]');
}
/** @test */
public function requestMetadataPrefixShouldBeOaiDc() {
$this->_xpath->assertXpath($this->_xml,
'//oai:request[@metadataPrefix="oai_dc"]');
}
/** @test */
public function shouldContainOneHeader() {
$this->_xpath->assertXpathCount($this->_xml,
self::OAI_RECORD_PATH . 'oai:header',
1);
}
/** @test */
public function headerShouldContainRecordIdentifier() {
$this->_xpath->assertXPathContentContains($this->_xml,
self::OAI_RECORD_PATH . self::OAI_HEADER_PATH . 'oai:identifier',
'oai:localhost:harrypotter-sorciers');
}
/** @test */
public function recordHeaderDateStampShouldBe2001DecemberFourteen() {
$this->_xpath->assertXPathContentContains($this->_xml,
self::OAI_RECORD_PATH . self::OAI_HEADER_PATH . 'oai:datestamp',
'2001-12-14');
}
/** @test */
public function metadataShouldContainOaiDublinCore() {
$this->_xpath->assertXPath($this->_xml,
self::OAI_RECORD_PATH . 'oai:metadata/oai_dc:dc');
}
/** @test */
public function shouldContainOneMetadata() {
$this->_xpath->assertXpathCount($this->_xml,
self::OAI_RECORD_PATH . 'oai:metadata',
1);
}