Skip to content
Snippets Groups Projects
Commit 7786a388 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

hotline #118227 : OAI-PMH resumptionToken no longer depend on cache availability

parent 1f7f6382
Branches
Tags
1 merge request!3864hotline #118227 : OAI-PMH resumptionToken no longer depend on cache availability
Pipeline #12465 failed with stage
in 27 minutes and 38 seconds
Showing
with 305 additions and 350 deletions
- ticket #118227 : Entrepôt OAI : Correction de la mécanique de resumptionToken
\ No newline at end of file
......@@ -71,78 +71,76 @@ class OaiController extends Zend_Controller_Action {
public function listIdentifiersAction() {
$request = new Class_WebService_OAI_Request_ListIdentifiers($this->_request->getParams(),
$this->buildBaseUrl());
$builder = new Class_Xml_Builder();
$this->view->request = $request;
$this->view->error = $request->getErrorOn($builder);
if ($notices = $request->getNotices()) {
$visitor = $request->getRecordVisitor();
$visitor->setGlobalSetSpec($request->getSet());
$recordBuilder = new Class_WebService_OAI_Response_RecordHeadersBuilder();
$headers = '';
foreach ($notices as $notice) {
$visitor->visit($notice);
$headers .= $recordBuilder->xml($builder, $visitor);
}
$this->view->headers = $headers;
}
$this->view->builder = $builder;
$this->view->token = $request->getToken();
$item_builder = new Class_WebService_OAI_Response_RecordHeadersBuilder();
$this->_listWith($request, $item_builder);
}
public function listRecordsAction() {
$request = new Class_WebService_OAI_Request_ListRecords($this->_request->getParams(),
$this->buildBaseUrl());
$item_builder = new Class_WebService_OAI_Response_RecordBuilder();
$this->_listWith($request, $item_builder);
}
protected function _listWith($request, $item_builder) {
$builder = new Class_Xml_Builder();
$this->view->request = $request;
$this->view->error = $request->getErrorOn($builder);
$this->view->request = $request->renderOn($builder);
$this->view->token = $request->renderResumptionTokenOn($builder);
if (!$notices = $request->getNotices())
return;
if ($notices = $request->getNotices()) {
$visitor = $request->getRecordVisitor();
$visitor->setGlobalSetSpec($request->getSet());
$recordBuilder = new Class_WebService_OAI_Response_RecordBuilder();
$records = '';
foreach ($notices as $notice) {
$visitor->visit($notice);
$records .= $builder->record($recordBuilder->xml($builder, $visitor));
}
$this->view->records = $records;
$visitor = $request->getRecordVisitor();
$visitor->setGlobalSetSpec($request->getSet());
$items = '';
foreach ($notices as $notice) {
$visitor->visit($notice);
$items .= $item_builder->xml($builder, $visitor);
}
$this->view->builder = $builder;
$this->view->token = $request->getToken();
$this->view->items = $items;
}
public function identifyAction() {
$this->view->baseUrl = $baseUrl = $this->buildBaseUrl();
$baseUrl = $this->buildBaseUrl();
$request = new Class_WebService_OAI_Request_Identify($this->_request->getParams(),
$baseUrl);
$this->view->request = $request;
$this->view->builder = $builder = new Class_Xml_Builder();
$this->view->error = $request->getErrorOn($builder);
$this->view->request = $request->renderOn($builder);
$this->view->repositoryName = ($name = Class_AdminVar::get('OAI_REPOSITORY_NAME'))
if ($this->view->error)
return;
$repositoryName = ($name = Class_AdminVar::get('OAI_REPOSITORY_NAME'))
? $name
: $_SERVER['SERVER_NAME'] . ' Oai repository';
$this->view->earliestDatestamp = ($notice = Class_Notice::getEarliestNotice())
$earliestDatestamp = ($notice = Class_Notice::getEarliestNotice())
? $notice->getCreatedAt()
: '';
$this->view->adminEmail = ($mail = Class_AdminVar::get('OAI_ADMIN_EMAIL'))
$adminEmail = ($mail = Class_AdminVar::get('OAI_ADMIN_EMAIL'))
? $mail
: Class_CosmoVar::get('mail_admin');
$this->view->identify = $builder->repositoryName($builder->cdata($repositoryName))
. $builder->baseURL($baseUrl)
. $builder->protocolVersion('2.0')
. $builder->adminEmail($builder->cdata($adminEmail))
. $builder->earliestDatestamp($earliestDatestamp)
. $builder->deletedRecord('no')
. $builder->granularity('YYYY-MM-DD');
}
public function listMetadataFormatsAction() {
$baseUrl = $this->buildBaseUrl();
$request = new Class_WebService_OAI_Request_ListMetadataFormats($this->_request->getParams(),
$baseUrl);
$this->buildBaseUrl());
$builder = new Class_Xml_Builder();
$this->view->request = $request->renderOn($builder);
$this->view->response = $request->getResponseOn($builder);
......@@ -150,41 +148,37 @@ class OaiController extends Zend_Controller_Action {
public function listSetsAction() {
$baseUrl = $this->buildBaseUrl();
$request = new Class_WebService_OAI_Request_ListSets($this->_request->getParams(),
$baseUrl);
$this->view->request = $request;
$this->buildBaseUrl());
$builder = new Class_Xml_Builder();
$this->view->request = $request->renderOn($builder);
if (!$catalogs = $request->getCatalogs())
return;
if ($catalogs = $request->getCatalogs()) {
$visitor = new Class_WebService_OAI_CatalogueVisitor($builder);
$sets = '';
foreach ($catalogs as $catalog) {
$visitor->visitCatalogue($catalog);
$sets .= $builder->set($visitor->xml());
}
$this->view->sets = $sets;
$visitor = new Class_WebService_OAI_CatalogueVisitor($builder);
$sets = '';
foreach ($catalogs as $catalog) {
$visitor->visitCatalogue($catalog);
$sets .= $builder->set($visitor->xml());
}
$this->view->builder = $builder;
$this->view->sets = $sets;
}
public function getRecordAction() {
$baseUrl = $this->buildBaseUrl();
$request = new Class_WebService_OAI_Request_GetRecord($this->_request->getParams(),
$baseUrl);
$this->view->request = $request;
$this->buildBaseUrl());
$builder = new Class_Xml_Builder();
$this->view->error = $request->getErrorOn($builder);
$this->view->request = $request->renderOn($builder);
if ($notice = $request->getNotice()) {
$visitor = $request->getRecordVisitor();
$visitor->visit($notice);
$recordBuilder = new Class_WebService_OAI_Response_RecordBuilder();
$this->view->record = $recordBuilder->xml($builder, $visitor);
}
$this->view->builder = $builder;
if (!$notice = $request->getNotice())
return;
$visitor = $request->getRecordVisitor();
$visitor->visit($notice);
$this->view->record = (new Class_WebService_OAI_Response_RecordBuilder)->xml($builder, $visitor);
}
......
......@@ -3,11 +3,11 @@
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">
<responseDate><?php echo date('c');?></responseDate>
<?php echo $this->request->renderOn($this->builder); ?>
<?php echo ($this->error) ? $this->error : '';?>
<?php echo $this->request; ?>
<?php echo $this->error; ?>
<?php if ($this->record) { ?>
<GetRecord>
<record><?php echo $this->record; ?></record>
<?php echo $this->record; ?>
</GetRecord>
<?php } ?>
</OAI-PMH>
......@@ -3,22 +3,11 @@
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">
<responseDate><?php echo date('c');?></responseDate>
<?php
echo $this->request->renderOn($this->builder);
if ($this->error)
echo $this->error;
else {
?>
<Identify>
<repositoryName><![CDATA[<?php echo $this->repositoryName;?>]]></repositoryName>
<baseURL><?php echo $this->baseUrl; ?></baseURL>
<protocolVersion>2.0</protocolVersion>
<adminEmail><![CDATA[<?php echo $this->adminEmail;?>]]></adminEmail>
<earliestDatestamp><?php echo $this->earliestDatestamp; ?></earliestDatestamp>
<deletedRecord>no</deletedRecord>
<granularity>YYYY-MM-DD</granularity>
<?php echo $this->request; ?>
<?php echo $this->error; ?>
<?php if ($this->identify) { ?>
<Identify>
<?php echo $this->identify; ?>
</Identify>
<?php } ?>
<?php } ?>
</OAI-PMH>
......@@ -3,17 +3,12 @@
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">
<responseDate><?php echo date('c');?></responseDate>
<?php
echo $this->request->renderOn($this->builder);
if ($this->error)
echo $this->error;
else {
if ($this->headers) { ?>
<?php echo $this->request; ?>
<?php echo $this->error; ?>
<?php if ($this->items) { ?>
<ListIdentifiers>
<?php echo $this->headers; ?>
<?php echo ($this->token) ? $this->token->renderOn($this->builder): '' ?>
</ListIdentifiers>
<?php } }?>
<?php echo $this->items; ?>
<?php echo $this->token; ?>
</ListIdentifiers>
<?php } ?>
</OAI-PMH>
......@@ -3,12 +3,12 @@
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">
<responseDate><?php echo date('c');?></responseDate>
<?php echo $this->request->renderOn($this->builder); ?>
<?php echo ($this->error) ? $this->error : '';?>
<?php if ($this->records) { ?>
<?php echo $this->request; ?>
<?php echo $this->error;?>
<?php if ($this->items) { ?>
<ListRecords>
<?php echo $this->records; ?>
<?php echo ($this->token) ? $this->token->renderOn($this->builder): '' ?>
<?php echo $this->items; ?>
<?php echo $this->token; ?>
</ListRecords>
<?php } ?>
</OAI-PMH>
\ No newline at end of file
</OAI-PMH>
......@@ -3,10 +3,10 @@
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">
<responseDate><?php echo date('c');?></responseDate>
<?php echo $this->request->renderOn($this->builder); ?>
<?php echo $this->request; ?>
<?php if ($this->sets) { ?>
<ListSets>
<?php echo $this->sets;?>
</ListSets>
<?php } ?>
</OAI-PMH>
\ No newline at end of file
</OAI-PMH>
......@@ -35,6 +35,8 @@ class Class_WebService_OAI extends Class_WebService_Abstract {
Verb = 'verb',
MetadataPrefix = 'metadataPrefix',
Set = 'set',
From = 'from',
Until = 'until',
ResumptionToken = 'resumptionToken',
ListSets = 'ListSets',
ListRecords = 'ListRecords';
......@@ -58,6 +60,30 @@ class Class_WebService_OAI extends Class_WebService_Abstract {
}
public static function listParams() {
return [static::MetadataPrefix,
static::Set,
static::From,
static::Until];
}
public static function filterParams($params) {
if (!$params || !is_array($params))
return [];
$known = static::listParams();
return array_filter($params,
function($key) use($known)
{
return in_array($key, $known);
},
ARRAY_FILTER_USE_KEY);
}
public function __construct() {
$this->parser = new Class_WebService_OAI_DublinCoreParser_ForRessourceNumerique();
}
......
......@@ -21,48 +21,52 @@
class Class_WebService_OAI_Request_ListIdentifiers {
const IDENTIFIERS_BY_PAGE = 100;
protected $_verb = 'ListIdentifiers';
protected $_baseUrl;
protected $_params;
protected $_metadataPrefix;
protected $_catalogue;
protected $_set;
protected $_from;
protected $_until;
protected $_resumptionToken;
protected $_notices;
protected $_token;
protected
$_verb = 'ListIdentifiers',
$_baseUrl,
$_params,
$_metadataPrefix,
$_catalogue,
$_set,
$_from,
$_until,
$_resumptionToken,
$_notices,
$_token,
$_total_count;
public function __construct($params, $baseUrl) {
$this->_baseUrl = $baseUrl;
$this->_params = array_merge(['metadataPrefix' => null,
'set' => null,
'from' => null,
'until' => null,
'resumptionToken' => null],
$this->_params = array_merge([Class_WebService_OAI::MetadataPrefix => null,
Class_WebService_OAI::Set => null,
Class_WebService_OAI::From => null,
Class_WebService_OAI::Until => null,
Class_WebService_OAI::ResumptionToken => null],
$params);
$this->_metadataPrefix = $this->_params['metadataPrefix'];
$this->_set = $this->_params['set'];
$this->_from = $this->_params['from'];
$this->_until = $this->_params['until'];
$this->_metadataPrefix = $this->_params[Class_WebService_OAI::MetadataPrefix];
$this->_set = $this->_params[Class_WebService_OAI::Set];
$this->_from = $this->_params[Class_WebService_OAI::From];
$this->_until = $this->_params[Class_WebService_OAI::Until];
$this->_resumptionToken = $this->_params[Class_WebService_OAI::ResumptionToken];
$this->_resumptionToken = $this->_params['resumptionToken'];
$this->_initFromToken();
if ($this->_resumptionToken
&& ($token = Class_WebService_OAI_ResumptionToken::find($this->_resumptionToken))) {
$this->_set = $token->getParam('set');
$this->_from = $token->getParam('from');
$this->_until = $token->getParam('until');
$this->_catalogue = $this->getCatalogueFromSetSpec($this->_set);
}
if ($this->_metadataPrefix)
$this->_metadataPrefix=null;
else
$this->_metadataPrefix=$token->getParam('metadataPrefix');
}
$this->_catalogue = $this->getCatalogueFromSetSpec($this->_set);
protected function _initFromToken() {
if (!$this->_token = Class_WebService_OAI_ResumptionToken::fromString($this->_resumptionToken))
return $this;
$this->_set = $this->_token->set();
$this->_from = $this->_token->from();
$this->_until = $this->_token->until();
$this->_metadataPrefix = $this->_token->metadataPrefix();
return $this;
}
......@@ -77,62 +81,47 @@ class Class_WebService_OAI_Request_ListIdentifiers {
public function getErrorOn($builder) {
$answer = '';
if ($this->_resumptionToken && !$this->_token)
return $builder->error(['code' => 'badResumptionToken']);
if (null == $this->_metadataPrefix)
$answer .= $builder->error(['code' => 'badArgument'],
'Metadata prefix is not found');
return $this->_badArgument($builder, 'Metadata prefix is not found');
if (!Class_WebService_OAI_MetadataFormat::isKnownPrefix($this->_metadataPrefix))
$answer .= $builder->error(['code' => 'cannotDisseminateFormat']);
return $builder->error(['code' => 'cannotDisseminateFormat']);
if (!$this->_set)
$answer .= $builder->error(['code' => 'badArgument'], 'Set argument missing');
return $this->_badArgument($builder, 'Set argument missing');
if ($this->_set && !$this->_catalogue)
$answer .= $builder->error(['code' => 'badArgument'], 'Set not found');
return $this->_badArgument($builder, 'Set not found');
if (! ($this->isDateValid($this->_from) && $this->isDateValid($this->_until))) {
$this->_from = $this->_until = null;
return $builder->error(['code' => 'badArgument'], 'date invalid');
}
if (! ($this->isDateValid($this->_from) && $this->isDateValid($this->_until)))
return $this->_badArgument($builder, 'date invalid');
if ($this->_until && $this->_from) {
if (strlen($this->_until) != strlen($this->_from))
return $builder->error(['code' => 'badArgument'],
'from granularity != until granularity');
return $this->_badArgument($builder, 'from granularity != until granularity');
if (strtotime($this->_from) > (strtotime($this->_until)))
return $builder->error(['code' => 'noRecordsMatch']);
}
$token = null;
if ($this->_resumptionToken
&& !($token = Class_WebService_OAI_ResumptionToken::find($this->_resumptionToken)))
return $builder->error(['code' => 'badResumptionToken']);
if ($answer)
return $answer;
if ($this->_from)
$this->_catalogue->setFrom(substr($this->_from, 0, 10));
if ($this->_until)
$this->_catalogue->setUntil(substr($this->_until, 0, 10));
if (0 == ($count = $this->_catalogue->getNoticesCount()))
if (0 == ($this->_total_count = $this->_catalogue->getNoticesCount()))
return $builder->error(['code' => 'noRecordsMatch']);
$page_number = 1;
if (null != $token) {
$this->_token = $token->next(self::IDENTIFIERS_BY_PAGE);
$page_number = $this->_token->getPageNumber();
} elseif (self::IDENTIFIERS_BY_PAGE < $count) {
$this->_token = Class_WebService_OAI_ResumptionToken::newWithParamsAndListSize($this->_params, $count);
}
if (!$this->_token && static::IDENTIFIERS_BY_PAGE < $this->_total_count)
$this->_token = new Class_WebService_OAI_ResumptionToken($this->_params);
if ($this->_token)
$this->_token->save();
$page_number = $this->_token
? $this->_token->pageNumber()
: 1;
$this->_notices = $this->_catalogue->getNotices($page_number, self::IDENTIFIERS_BY_PAGE);
if (empty($this->_notices))
......@@ -140,13 +129,19 @@ class Class_WebService_OAI_Request_ListIdentifiers {
}
protected function _badArgument($builder, $label) {
$this->_metadataPrefix = $this->_set = $this->_from = $this->_until = $this->_resumptionToken = null;
return $builder->error(['code' => 'badArgument'], $label);
}
public function getToken() {
return $this->_token;
}
public function renderOn($builder) {
$requestOptions = array('verb' => $this->_verb);
$requestOptions = ['verb' => $this->_verb];
if (null !== $this->_set)
$requestOptions['set'] = $this->_set;
if (null !== $this->_from)
......@@ -162,6 +157,13 @@ class Class_WebService_OAI_Request_ListIdentifiers {
}
public function renderResumptionTokenOn($builder) {
return $this->_token
? $this->_token->renderOn($builder, $this->_total_count)
: '';
}
public function getCatalogueFromSetSpec($setSpec) {
if (null == $setSpec)
return Class_Catalogue::newCatalogueForAll();
......
......@@ -20,9 +20,8 @@
*/
class Class_WebService_OAI_Response_RecordBuilder {
public function xml($builder, $visitor) {
return
$this->buildHeaders($builder, $visitor)
. $this->buildMetadata($builder, $visitor);
return $builder->record($this->buildHeaders($builder, $visitor)
. $this->buildMetadata($builder, $visitor));
}
......
......@@ -16,11 +16,12 @@
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_WebService_OAI_Response_RecordHeadersBuilder extends Class_WebService_OAI_Response_RecordBuilder {
public function buildMetadata($builder, $visitor) {
return '';
class Class_WebService_OAI_Response_RecordHeadersBuilder
extends Class_WebService_OAI_Response_RecordBuilder {
public function xml($builder, $visitor) {
return $this->buildHeaders($builder, $visitor);
}
}
?>
\ No newline at end of file
......@@ -21,75 +21,96 @@
class Class_WebService_OAI_ResumptionToken {
protected $_cache = null;
protected $_params;
protected $_list_size;
protected $_cursor = 0;
protected $_page_number = 1;
const PARAM_SEPARATOR = '!';
protected
$_params,
$_page_number = 1;
public function __sleep(){
return ['_params', '_list_size', '_cursor', '_page_number'];
public static function fromString($value) {
if (!$value)
return;
$params = explode(static::PARAM_SEPARATOR, $value);
$known = Class_WebService_OAI::listParams();
if (count($params) - 1 != count($known))
return;
$page_number = (int) array_pop($params);
$token = new static(array_combine($known, $params), $page_number);
return $token->isEmpty()
? null
: $token;
}
public function __construct($params, $page_number=null) {
$this->_params = Class_WebService_OAI::filterParams($params);
if ((int)$page_number)
$this->_page_number = (int)$page_number;
}
public function getCache() {
if (!isset($this->_cache))
$this->_cache = (new Storm_Cache());
return $this->_cache;
public function __toString() {
$params = [];
foreach(Class_WebService_OAI::listParams() as $key)
$params[] = $this->getParam($key, '');
$params[] = $this->_page_number + 1;
return implode(static::PARAM_SEPARATOR, $params);
}
public static function newWithParamsAndListSize($params, $list_size, $cursor = 0, $page_number = 1) {
return new self($params, $list_size, $cursor, $page_number);
public function isEmpty() {
return 0 === count($this->_params);
}
public static function find($key) {
return (new Storm_Cache())->load($key);
public function renderOn($builder, $complete_list_size) {
return $builder->resumptionToken(['completeListSize' => $complete_list_size,
'cursor' => $this->_cursor()],
$builder->cdata($this->__toString()));
}
public function __construct($params, $list_size, $cursor, $page_number) {
$this->_params = $params;
$this->_list_size = $list_size;
$this->_cursor = $cursor;
$this->_page_number = $page_number;
protected function _cursor() {
return ($this->_page_number-1) * 100;
}
public function save() {
return $this->getCache()->save($this, $this->getCacheKey());
public function pageNumber() {
return $this->_page_number;
}
public function next($size) {
return self::newWithParamsAndListSize($this->_params,
$this->_list_size,
$this->_cursor + $size,
$this->_page_number + 1);
public function getParam($key, $default=null) {
return isset($this->_params[$key])
? $this->_params[$key]
: $default;
}
public function renderOn($builder) {
return $builder->resumptionToken(array('completeListSize' => $this->_list_size,
'cursor' => $this->_cursor),
md5(serialize($this)));
public function set() {
return $this->getParam(Class_WebService_OAI::Set);
}
public function getPageNumber() {
return $this->_page_number;
public function from() {
return $this->getParam(Class_WebService_OAI::From);
}
public function getParam($key) {
if (!array_key_exists($key, $this->_params))
return null;
return $this->_params[$key];
public function until() {
return $this->getParam(Class_WebService_OAI::Until);
}
public function getCacheKey() {
return md5(serialize($this));
public function metadataPrefix() {
return $this->getParam(Class_WebService_OAI::MetadataPrefix);
}
}
......@@ -79,10 +79,7 @@ class OAIControllerListIdentifiersValidTest
parent::setUp();
$this->_catalog_loader->whenCalled('countNoticesFor')->answers(3);
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork',
true);
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork');
$this->_xml = $this->_response->getBody();
}
......@@ -97,8 +94,7 @@ class OAIControllerListIdentifiersValidTest
/** @test */
public function requestVerbShouldBeListIdentifiers() {
$this->_xpath->assertXPath($this->_xml,
'//oai:request[@verb="ListIdentifiers"]');
$this->_xpath->assertXPath($this->_xml, '//oai:request[@verb="ListIdentifiers"]');
}
......@@ -112,15 +108,13 @@ class OAIControllerListIdentifiersValidTest
/** @test */
public function shouldNotHaveMetadata() {
$this->_xpath->assertNotXpath($this->_xml,
'//oai:ListIdentifiers/oai:metadata');
$this->_xpath->assertNotXpath($this->_xml, '//oai:ListIdentifiers/oai:metadata');
}
/** @test */
public function shouldNotHaveResumptionToken() {
$this->_xpath->assertNotXpath($this->_xml,
'//oai:resumptionToken');
$this->_xpath->assertNotXpath($this->_xml, '//oai:resumptionToken');
}
......@@ -191,38 +185,27 @@ class OAIControllerListIdentifiersValidTest
class OAIControllerListIdentifiersWithPaginatorTest
extends OAIControllerListIdentifiersTestCase {
protected $_cache;
public function setUp() {
parent::setUp();
$this->_catalog_loader->whenCalled('countNoticesFor')->answers(10000);
$this->_cache = $this->mock()->whenCalled('save')->answers(true);
Storm_Cache::setDefaultZendCache($this->_cache);
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork',
true);
$this->_xml = $this->_response->getBody();
}
public function tearDown() {
Storm_Cache::setDefaultZendCache(null);
parent::tearDown();
}
/** @test */
public function shouldHaveResumptionToken() {
$this->_xpath->assertXPath($this->_xml, '//oai:resumptionToken');
public function firstPageShouldHaveResumptionTokenToPage2() {
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork');
$this->_xpath->assertXPathContentContains($this->_response->getBody(),
'//oai:resumptionToken',
'oai_dc!zork!!!2');
}
/** @test */
public function shouldHaveSavedToken() {
$this->assertTrue($this->_cache->methodHasBeenCalled('save'));
public function secondPageShouldHaveResumptionTokenToPage3() {
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&resumptionToken=oai_dc!zork!!!2');
$this->_xpath->assertXPathContentContains($this->_response->getBody(),
'//oai:resumptionToken',
'oai_dc!zork!!!3');
}
}
......@@ -231,13 +214,6 @@ class OAIControllerListIdentifiersWithPaginatorTest
class OAIControllerListIdentifiersInvalidParamsTest
extends OAIControllerListIdentifiersTestCase {
protected $_xpath;
public function tearDown() {
Storm_Cache::setDefaultZendCache(null);
parent::tearDown();
}
/** @test */
public function withUnknownFormatErrorCodeShouldBeCannotDisseminateFormat() {
......@@ -251,23 +227,18 @@ class OAIControllerListIdentifiersInvalidParamsTest
public function withUnknownSetErrorCodeShouldBeBadArgument() {
$this->_catalog_loader->whenCalled('findAllBy')->answers([]);
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=' . urlencode('jeunesse:bd'),
true);
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=' . urlencode('jeunesse:bd'));
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:error[@code="badArgument"]');
$this->assertBadArgument();
}
/** @test */
public function withoutSetErrorCodeShouldBeBadArgument() {
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc',
true);
$this->_xpath
->assertXPathContentContains($this->_response->getBody(),
'//oai:error[@code="badArgument"]',
'Set argument missing');
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc');
$this->_xpath->assertXPathContentContains($this->_response->getBody(),
'//oai:error[@code="badArgument"]',
'Set argument missing');
}
......@@ -275,8 +246,7 @@ class OAIControllerListIdentifiersInvalidParamsTest
public function withoutNoticesErrorCodeShouldBeNoRecordsMatch() {
$this->onLoaderOfModel('Class_Notice')->whenCalled('countBy')->answers(0);
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork',
true);
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork');
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:error[@code="noRecordsMatch"]');
......@@ -289,12 +259,7 @@ class OAIControllerListIdentifiersInvalidParamsTest
->whenCalled('countNoticesFor')
->answers(10000);
$cache = $this->mock()
->whenCalled('load')->answers(false);
Storm_Cache::setDefaultZendCache($cache);
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=zork&resumptionToken=Zork',
true);
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&resumptionToken=Zork');
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:error[@code="badResumptionToken"]');
......@@ -303,45 +268,41 @@ class OAIControllerListIdentifiersInvalidParamsTest
/** @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',
true);
$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)]');
'//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',
true);
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:error[@code="badArgument"]');
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&from=2001-01-01&until=2002-01-01T00:00:00Z');
$this->assertBadArgument();
}
/** @test */
public function withListIdentifiersWithoutMetadataPrefixResponseShouldResponseBadArgument() {
$this->dispatch('opac/oai/request?verb=ListIdentifiers', true);
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:error[@code="badArgument"]');
$this->dispatch('opac/oai/request?verb=ListIdentifiers');
$this->assertBadArgument();
}
/** @test */
public function withFromAndUntilWithBadFormatShouldResponseBadArgument() {
$this->dispatch('opac/oai/request?verb=ListIdentifiers', true);
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:error[@code="badArgument"]');
$this->dispatch('opac/oai/request?verb=ListIdentifiers&from=woot');
$this->assertBadArgument();
}
/** @test */
public function withUntilBeforeFromResponseShouldResponseNoRecordsMatch() {
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&from=2000-01-01&until=1999-01-01',
true);
$this->fixture('Class_Catalogue', ['id' => 122,
'libelle' => 'testing',
'oai_spec' => 'test']);
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&set=test&from=2000-01-01&until=1999-01-01');
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:error[@code="noRecordsMatch"]');
......@@ -350,11 +311,13 @@ class OAIControllerListIdentifiersInvalidParamsTest
/** @test */
public function withUntilFromGranularityHoursShouldAnswerBadArgument() {
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&from=2000-01-01T00:00:00Z',
true);
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&from=2000-01-01T00:00:00Z');
$this->assertBadArgument();
}
$this->_xpath->assertXPath($this->_response->getBody(),
'//oai:error[@code="badArgument"]');
protected function assertBadArgument() {
$this->_xpath->assertXPath($this->_response->getBody(), '//oai:error[@code="badArgument"]');
}
}
......@@ -364,8 +327,6 @@ class OAIControllerListIdentifiersInvalidParamsTest
class OAIControllerListIdentifiersWithoutDataFoundTest
extends OAIControllerListIdentifiersTestCase {
protected $_cache;
public function setUp() {
parent::setUp();
......@@ -373,20 +334,11 @@ class OAIControllerListIdentifiersWithoutDataFoundTest
->whenCalled('countNoticesFor')->answers(10)
->whenCalled('loadNoticesFor')->answers([]);
$this->_cache = $this->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();
}
public function tearDown() {
Storm_Cache::setDefaultZendCache(null);
parent::tearDown();
}
/** @test */
public function responseShouldCountainsErrorNoRecordMatch() {
$this->_xpath->assertXPath($this->_xml, '//oai:error[@code="noRecordsMatch"]');
......@@ -404,10 +356,10 @@ class OAIControllerListIdentifiersWithUntilParamTest
$this->_catalog_loader
->whenCalled('countNoticesFor')->answers(1000)
->whenCalled('loadNoticesFor')->answers([]);
->whenCalled('loadNoticesFor')->answers([])
;
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&until=2012-01-01&set=zork',
true);
$this->dispatch('/opac/oai/request?verb=ListIdentifiers&metadataPrefix=oai_dc&until=2012-01-01&set=zork');
$this->_xml = $this->_response->getBody();
}
......
......@@ -161,16 +161,8 @@ class OAIControllerListRecordsInZorkSetWithBadResumptionTokenTest
public function setUp() {
parent::setUp();
$cache = $this->mock()
->whenCalled('save')->answers(true)
->whenCalled('load')->answers(false);
Storm_Cache::setDefaultZendCache($cache);
Class_Catalogue::whenCalled('countNoticesFor')->answers(0);
$this->dispatch('/opac/oai/request?verb=ListRecords&metadataPrefix=oai_dc&set=zork&resumptionToken=junktoken',
true);
$this->dispatch('/opac/oai/request?verb=ListRecords&resumptionToken=junktoken');
}
......
......@@ -22,7 +22,6 @@
class ResumptionTokenTest extends ModelTestCase {
protected
$_storm_default_to_volatile = true,
$_token,
$_request_params,
$_xpath,
......@@ -34,57 +33,32 @@ class ResumptionTokenTest extends ModelTestCase {
'metadataPrefix' => 'oai_dc',
'set' => 'bande_dessinees'];
Storm_Cache::beVolatile();
Storm_Cache::setSeed('local');
$this->_token = Class_WebService_OAI_ResumptionToken::newWithParamsAndListSize($this->_request_params, 10000);
$this->_token->save();
$this->_token = new Class_WebService_OAI_ResumptionToken($this->_request_params);
$this->_xpath = new Storm_Test_XPathXML();
$this->_builder = new Class_Xml_Builder();
}
/** @test */
public function pageNumberShouldBeOne() {
$this->assertEquals(1, $this->_token->getPageNumber());
}
public function loadFromStringShouldAnswerToken() {
$expected = new Class_WebService_OAI_ResumptionToken($this->_request_params, 2);
$token_string = 'oai_dc!bande_dessinees!2011-12-25!!2';
/** @test */
public function findByMd5ShouldAnswerToken() {
$this->assertEquals(Class_WebService_OAI_ResumptionToken::newWithParamsAndListSize($this->_request_params, 10000, 0, 1),
Class_WebService_OAI_ResumptionToken::find($this->_token->getCacheKey()));
$this->assertEquals($expected,
Class_WebService_OAI_ResumptionToken::fromString($token_string));
}
/** @test */
public function findByUnknownMd5ShouldAnswerNull() {
$this->assertEquals(null, Class_WebService_OAI_ResumptionToken::find('Zork!!'));
public function loadFromInvalidStringShouldAnswerNull() {
$this->assertEquals(null,
Class_WebService_OAI_ResumptionToken::fromString('what=if'));
}
/** @test */
public function renderShouldAnswerXml() {
$this->_xpath->assertXPathContentContains($this->_token->renderOn($this->_builder),
'//resumptionToken[@completeListSize="10000"][@cursor="0"]',
md5(serialize($this->_token)));
}
/** @test */
public function renderNextTokenShouldAnswerXml() {
$next = $this->_token->next(10);
$this->_xpath->assertXPathContentContains($next->renderOn($this->_builder),
'//resumptionToken[@completeListSize="10000"][@cursor="10"]',
md5(serialize($next)));
}
/** @test */
public function nextPageNumberShouldBeTwo() {
$this->assertEquals(2, $this->_token->next(10)->getPageNumber());
public function pageNumberShouldBeOne() {
$this->assertEquals(1, $this->_token->pageNumber());
}
......@@ -98,4 +72,13 @@ class ResumptionTokenTest extends ModelTestCase {
public function getParamOfUnknownShouldReturnNull() {
$this->assertNull($this->_token->getParam('Zork'));
}
/** @test */
public function renderShouldContainsListSize10000AndCursor0() {
$this->_xpath
->assertXPathContentContains($this->_token->renderOn($this->_builder, 10000),
'//resumptionToken[@completeListSize="10000"][@cursor="0"]',
'oai_dc!bande_dessinees!2011-12-25!!2');
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment