Skip to content
Snippets Groups Projects
Commit ae7a9f84 authored by efalcy's avatar efalcy
Browse files

Correction validation OAI sur granularite < jour

parent 53356df9
Branches
Tags
No related merge requests found
......@@ -56,26 +56,21 @@ class Class_WebService_OAI_Request_ListIdentifiers {
$this->_until = $token->getParam('until');
}
$this->checkUntilAndFromValidity();
$this->_catalogue = $this->getCatalogueFromSetSpec($this->_set);
}
public function checkUntilAndFromValidity() {
if ($this->_until && !strtotime($this->_until))
$this->_until = null;
if ($this->_from && !strtotime($this->_from))
$this->_from = null;
public function isDateValid($value) {
return empty($value) || preg_match('/^\d{4}-\d{2}-\d{2}$/', $value );
}
public function getNotices() {
return $this->_notices;
}
public function getErrorOn($builder) {
$answer = '';
if (null == $this->_metadataPrefix)
......@@ -88,10 +83,18 @@ class Class_WebService_OAI_Request_ListIdentifiers {
if ($this->_set && !$this->_catalogue)
$answer .= $builder->error(array('code' => 'badArgument'), 'Set not found');
if (! ($this->isDateValid($this->_from) && $this->isDateValid($this->_until))) {
$this->_from = $this->_until = null;
return $builder->error(array('code' => 'badArgument'), 'date invalid');
}
if ($this->_until && $this->_from) {
if (strlen($this->_until) != strlen($this->_from))
return $builder->error(array('code' => 'badArgument'), 'from granularity != until granularity');
if (strtotime($this->_from)>(strtotime($this->_until)))
return $builder->error(array('code' => 'noRecordsMatch'));
}
$token = null;
......
......@@ -323,6 +323,29 @@ class OAIControllerListIdentifiersInvalidParamsTest extends AbstractControllerTe
'//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"]');
}
}
......
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