From b9ecc873669ac2c1c13bd01b2a6a778e100fe70f Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Mon, 10 Dec 2012 08:45:28 +0000
Subject: [PATCH] Correction test OAI: (6) Testing : ListIdentifiers (oai_dc)

---
 .../OAI/Request/ListIdentifiers.php           |  2 +
 .../OAIControllerListIdentifiersTest.php      | 49 +++++++++++++++++++
 .../opac/controllers/OAIControllerTest.php    |  1 +
 3 files changed, 52 insertions(+)

diff --git a/library/Class/WebService/OAI/Request/ListIdentifiers.php b/library/Class/WebService/OAI/Request/ListIdentifiers.php
index fdcae99ca95..d2cc9416155 100644
--- a/library/Class/WebService/OAI/Request/ListIdentifiers.php
+++ b/library/Class/WebService/OAI/Request/ListIdentifiers.php
@@ -96,6 +96,8 @@ class Class_WebService_OAI_Request_ListIdentifiers {
 			$this->_catalogue->setUntil(substr($this->_until, 0, 10));
 
 		$this->_notices = $this->_catalogue->getNotices($page_number, self::IDENTIFIERS_BY_PAGE);
+		if (empty($this->_notices))
+			return $builder->error(array('code' => 'noRecordsMatch'));
 	}
 
 
diff --git a/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php b/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php
index ec5dec5d47a..4dc5f167e01 100644
--- a/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php
+++ b/tests/application/modules/opac/controllers/OAIControllerListIdentifiersTest.php
@@ -167,6 +167,8 @@ class OAIControllerListIdentifiersValidTest extends AbstractControllerTestCase {
 }
 
 
+
+
 class OAIControllerListIdentifiersWithPaginatorTest extends AbstractControllerTestCase {
 	protected $_xpath;
 	protected $_xml;
@@ -225,6 +227,8 @@ class OAIControllerListIdentifiersWithPaginatorTest extends AbstractControllerTe
 }
 
 
+
+
 class OAIControllerListIdentifiersInvalidParamsTest extends AbstractControllerTestCase {
 	protected $_xpath;
 
@@ -295,4 +299,49 @@ class OAIControllerListIdentifiersInvalidParamsTest extends AbstractControllerTe
 															 '//oai:error[@code="badResumptionToken"]');
 	}
 }
+
+
+
+
+class OAIControllerListIdentifiersWithoutDataFoundTest extends AbstractControllerTestCase {
+	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);
+
+		Class_WebService_OAI_ResumptionToken::defaultCache($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);
+		parent::tearDown();
+	}
+
+	
+	/** @test */
+	public function responseShouldCountainsErrorNoRecordMatch() {
+		$this->_xpath->assertXPath($this->_xml, '//oai:error[@code="noRecordsMatch"]');
+	}
+}
 ?>
\ No newline at end of file
diff --git a/tests/application/modules/opac/controllers/OAIControllerTest.php b/tests/application/modules/opac/controllers/OAIControllerTest.php
index d8e124c54f3..47c73808e14 100644
--- a/tests/application/modules/opac/controllers/OAIControllerTest.php
+++ b/tests/application/modules/opac/controllers/OAIControllerTest.php
@@ -110,6 +110,7 @@ class OAIControllerRequestWithoutOAIEnabledTest extends AbstractControllerTestCa
 
 
 
+
 class OaiControllerListSetsRequestTest extends OaiControllerRequestTestCase {
 	protected $_xpath;
 	 
-- 
GitLab