From 9b871893210f0181465d7d4920e05311760e203c Mon Sep 17 00:00:00 2001
From: efalcy <efalcy@git-test.afi-sa.fr>
Date: Mon, 10 Dec 2012 10:34:36 +0000
Subject: [PATCH] Gallica validation XML

---
 .../OAI/Request/ListIdentifiers.php           | 19 +++++++++++++++----
 .../OAIControllerListIdentifiersTest.php      |  7 +++++++
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/library/Class/WebService/OAI/Request/ListIdentifiers.php b/library/Class/WebService/OAI/Request/ListIdentifiers.php
index 588fd68b6f2..6ed67385d10 100644
--- a/library/Class/WebService/OAI/Request/ListIdentifiers.php
+++ b/library/Class/WebService/OAI/Request/ListIdentifiers.php
@@ -55,15 +55,20 @@ class Class_WebService_OAI_Request_ListIdentifiers {
 			$this->_from = $token->getParam('from');
 			$this->_until = $token->getParam('until');
 		}
-		if (!strtotime($this->_until))
-				$this->_until = null;
-		if (!strtotime($this->_from))
-			$this->_from = null;
 
+		$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 getNotices() {
 		return $this->_notices;
 	}
@@ -78,6 +83,12 @@ class Class_WebService_OAI_Request_ListIdentifiers {
 		if ($this->_set && !$this->_catalogue)
 			$answer .= $builder->error(array('code' => 'badArgument'), 'Set not found');
 
+
+		if ($this->_until && $this->_from) {
+			if (strlen($this->_until) != strlen($this->_from))
+				return $builder->error(array('code' => 'badArgument'), 'Set not found');
+		}
+
 		$token = null;
 		if ($this->_resumptionToken 
 				&& !($token = Class_WebService_OAI_ResumptionToken::find($this->_resumptionToken)))
diff --git a/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php b/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php
index e2b02352ea8..08c0af8ce12 100644
--- a/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php
+++ b/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php
@@ -299,6 +299,7 @@ class OAIControllerListIdentifiersInvalidParamsTest extends AbstractControllerTe
 															 '//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');
@@ -308,6 +309,12 @@ class OAIControllerListIdentifiersInvalidParamsTest extends AbstractControllerTe
 	}
 
 
+	/** @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"]');
+	}
 }
 
 
-- 
GitLab