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';
class OAIControllerListIdentifiersValidTest extends AbstractControllerTestCase {
protected $_xpath;
protected $_response;
protected $_xml;
public function setUp() {
parent::setUp();
$this->_xpath = TestXPathFactory::newOai();
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue')
->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)
->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')));
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork');
$this->_xml = $this->_response->getBody();
}
/** @test */
public function controllerShouldBeOai() {
$this->assertController('oai');
}
/** @test */
public function actionShouldBeRequest() {
$this->assertAction('list-identifiers');
}
/** @test */
public function xmlShouldBeValid() {
$dom = new DOMDocument();
$dom->loadXml($this->_response->getBody());
$dom->schemaValidate('tests/application/modules/opac/controllers/OAI-PMH.xsd');
}
/** @test */
public function requestVerbShouldBeListIdentifiers() {
$this->_xpath->assertXPath($this->_xml,
'//oai:request[@verb="ListIdentifiers"]');
}
/** @test */
public function shouldHaveThreeHeaders() {
$this->_xpath->assertXpathCount($this->_xml,
'//oai:ListIdentifiers/oai:header',
3);
}
/** @test */
public function shouldNotHaveMetadata() {
$this->_xpath->assertNotXpath($this->_xml,
'//oai:ListIdentifiers/oai:metadata');
}
/** @test */
public function shouldNotHaveResumptionToken() {
$this->_xpath->assertNotXpath($this->_xml,
'//oai:resumptionToken');
}
/** @test */
public function firstIdentifierShouldContainSorciers() {
$this->_assertIdentifierContentAt('sorciers', 1);
}
/** @test */
public function firstDateShouldBeDecemberFourteen2001() {
$this->_assertDateContentAt('2001-12-14', 1);
}
/** @test */
public function firstSetSpecShouldBeZork() {
$this->_assertHeaderContentAt('setSpec', 'zork', 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->_xml, $path, $content);
}
class OAIControllerListIdentifiersWithPaginatorTest extends AbstractControllerTestCase {
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
224
225
226
227
228
protected $_xpath;
protected $_xml;
protected $_cache;
public function setUp() {
parent::setUp();
$this->_xpath = TestXPathFactory::newOai();
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue')
->whenCalled('countNoticesFor')
->answers(10000)
->whenCalled('findAllBy')
->with(array('oai_spec' => 'zork'))
->answers(array(Class_Catalogue::getLoader()->newInstanceWithId(2)))
->whenCalled('loadNoticesFor')
->answers(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')));
$this->_cache = Storm_Test_ObjectWrapper::mock()
->whenCalled('save')
->answers(true);
//Class_WebService_OAI_ResumptionToken::defaultCache($this->_cache);
Storm_Cache::setDefaultZendCache($this->_cache);
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork');
$this->_xml = $this->_response->getBody();
}
public function tearDown() {
//Class_WebService_OAI_ResumptionToken::defaultCache(null);
Storm_Cache::setDefaultZendCache(null);
parent::tearDown();
}
/** @test */
public function shouldHaveResumptionToken() {
$this->_xpath->assertXPath($this->_xml, '//oai:resumptionToken');
}
/** @test */
public function shouldHaveSavedToken() {
$this->assertTrue($this->_cache->methodHasBeenCalled('save'));
}
class OAIControllerListIdentifiersInvalidParamsTest extends AbstractControllerTestCase {
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
protected $_xpath;
public function setUp() {
parent::setUp();
$this->_xpath = TestXPathFactory::newOai();
}
public function tearDown() {
//Class_WebService_OAI_ResumptionToken::defaultCache(null);
Storm_Cache::setDefaultZendCache(null);
parent::tearDown();
}
/** @test */
public function withUnknownFormatErrorCodeShouldBeCannotDisseminateFormat() {
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=zork');
$this->_xpath->assertXpath($this->_response->getBody(),
'//oai:error[@code="cannotDisseminateFormat"]');
}
/** @test */
public function withUnknownSetErrorCodeShouldBeBadArgument() {
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue')
->whenCalled('findAllBy')
->answers(array());
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=' . urlencode('jeunesse:bd'));
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:error[@code="badArgument"]');
}
/** @test */
public function withoutNoticesErrorCodeShouldBeNoRecordsMatch() {
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue')
->whenCalled('findAllBy')
->with(array('oai_spec' => 'zork'))
->answers(array(Class_Catalogue::getLoader()->newInstanceWithId(2)));
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice')
->whenCalled('countBy')
->answers(0);
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork');
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:error[@code="noRecordsMatch"]');
}
/** @test */
public function withUnknownResumptionTokenErrorCodeShouldBeBadResumptionToken() {
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue')
->whenCalled('findAllBy')
->with(array('oai_spec' => 'zork'))
->answers(array(Class_Catalogue::getLoader()->newInstanceWithId(2)))
->whenCalled('countNoticesFor')
->answers(10000);
$cache = Storm_Test_ObjectWrapper::mock()
->whenCalled('load')
->answers(false);
//Class_WebService_OAI_ResumptionToken::defaultCache($cache);
Storm_Cache::setDefaultZendCache($cache);
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork&resumptionToken=Zork',true);
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:error[@code="badResumptionToken"]');
}
/** @test */
public function withBadFromAndUntilResponseShouldNotContainsAttributes() {
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=really_wrong_set&from=some_random_date&until=some_random_date');
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:request[not(@from)][not(@until)]');
}
/** @test */
public function withFromAndUntilDifferentGranularityResponseShouldNotContainsAttributes() {
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&from=2001-01-01&until=2002-01-01T00:00:00Z');
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:error[@code="badArgument"]');
}
/** @test */
public function withListIdentifiersWithoutMetadataPrefixResponseShouldResponseBadArgument() {
$this->dispatch('opac/oai/request?verb=ListIdentifiers');
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:error[@code="badArgument"]');
}
/** @test */
public function withFromAndUntilWithBadFormatShouldResponse() {
$this->dispatch('opac/oai/request?verb=ListIdentifiers');
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:error[@code="badArgument"]');
}
/** @test */
public function withUntilBeforeFromResponseShouldResponseNoRecordsMatch() {
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&from=2000-01-01&until=1999-01-01');
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:error[@code="noRecordsMatch"]');
}
/** @test */
public function withUntilFromGranularityHoursShouldAnswerBadArgument() {
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&from=2000-01-01T00:00:00Z', true);
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:error[@code="badArgument"]');
}
class OAIControllerListIdentifiersWithoutDataFoundTest extends AbstractControllerTestCase {
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
protected $_xpath;
protected $_xml;
protected $_cache;
public function setUp() {
parent::setUp();
$this->_xpath = TestXPathFactory::newOai();
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue')
->whenCalled('countNoticesFor')
->answers(10)
->whenCalled('findAllBy')
->with(array('oai_spec' => 'zork'))
->answers([Class_Catalogue::getLoader()->newInstanceWithId(2)])
->whenCalled('loadNoticesFor')
->answers([]);
$this->_cache = Storm_Test_ObjectWrapper::mock()
->whenCalled('save')
->answers(true);
Storm_Cache::setDefaultZendCache($this->_cache);
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork');
$this->_xml = $this->_response->getBody();
}
/** @test */
public function responseShouldCountainsErrorNoRecordMatch() {
$this->_xpath->assertXPath($this->_xml, '//oai:error[@code="noRecordsMatch"]');
}
class OAIControllerListIdentifiersWithUntilParamTest extends AbstractControllerTestCase {
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
protected $_xpath;
protected $_xml;
protected $_cache;
public function setUp() {
parent::setUp();
$this->_xpath = TestXPathFactory::newOai();
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue')
->whenCalled('countNoticesFor')
->answers(1000);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice')
->whenCalled('findAllBy')
->with(['limitPage' => [1, 100],
'where' => 'left(date_maj, 10) <= \'2012-01-01\''])
->answers([])
->beStrict();
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&until=2012-01-01', true);
$this->_xml = $this->_response->getBody();
}
/** @test */
public function responseShouldCountainsErrorNoRecordMatch() {
$this->_xpath->assertXPath($this->_xml, '//oai:error[@code="noRecordsMatch"]');
}