diff --git a/tests/api/testApi.php b/tests/api/testApi.php index 3545541..a08f2ad 100644 --- a/tests/api/testApi.php +++ b/tests/api/testApi.php @@ -139,7 +139,7 @@ class APITestCase extends KTUnitTestCase { $user = $this->ktapi->can_user_access_object_requiring_permission($internalDocObject2, $permission); $this->assertNotNull($user); - $this->assertEqual($user, PEAR::isError($user)); + $this->assertIsA($user, 'PEAR_Error'); $this->assertNoErrors(); // clean up @@ -302,6 +302,7 @@ class APITestCase extends KTUnitTestCase { // create the document object $randomFile = $this->createRandomFile(); $document = $this->root->add_document('title_5.txt', 'name_5.txt', 'Default', $randomFile); + @unlink($randomFile); $documentID = $document->get_documentid(); @@ -310,7 +311,9 @@ class APITestCase extends KTUnitTestCase { $this->assertNotNull($docObject); $this->assertIsA($docObject, 'KTAPI_Document'); $this->assertNoErrors(); - @unlink($randomFile); + + $document->delete('Testing'); + $document->expunge(); } /** @@ -422,81 +425,6 @@ class APITestCase extends KTUnitTestCase { $this->assertNoErrors(); } - /** - * This method tests the creation of the saved search - * - */ - public function testCreate() - { - $searchID = $this->ktapi->create(rand(1,1000), '(GeneralText contains "title")'); - - $this->assertNotNull($searchID); - $this->assertNoErrors(); - } - - /** - * This method tests the retrieval for the saved search by it's id - * - */ - public function testGetSavedSearch() - { - $list = $this->ktapi->getList(); - - $searchID = $list[0]['id']; - $search = $this->ktapi->getSavedSearch($searchID); - - $this->assertNotNull($search); - $this->assertNoErrors(); - } - - /** - * This method tests the list of the saved search - * - */ - public function testList() - { - $list = $this->ktapi->getList(); - - $this->assertNotNull($list); - $this->assertNoErrors(); - } - - /** - * This method tests the deleting of the saved search - * - */ - public function testDelete() - { - $searchID = $this->ktapi->create(rand(1,1000), '(GeneralText contains "title")'); - $this->ktapi->delete($searchID); - $result = $this->ktapi->getSavedSearch($searchID); - - $this->assertTrue(empty($result)); - $this->assertEqual($result, PEAR::isError($result)); - $this->assertNoErrors(); - } - - /** - * This method tests the processing of the saved search - * - */ - public function testRunSavedSearch() - { - // create the document object - $randomFile = $this->createRandomFile(); - $document = $this->root->add_document('title_1.txt', 'name_1.txt', 'Default', $randomFile); - - $searchID = $this->ktapi->create(rand(1,1000), '(GeneralText contains "title")'); - - $result = $this->ktapi->runSavedSearch($searchID); - - $this->assertNotNull($result); - $this->assertNotEqual($result, PEAR::isError($result)); - $this->assertNoErrors(); - @unlink($randomFile); - } - - function createRandomFile($content = 'this is some text') { $temp = tempnam(dirname(__FILE__), 'myfile'); $fp = fopen($temp, 'wt'); @@ -505,4 +433,4 @@ class APITestCase extends KTUnitTestCase { return $temp; } } -?> +?> \ No newline at end of file diff --git a/tests/api/testSavedSearches.php b/tests/api/testSavedSearches.php new file mode 100644 index 0000000..1573395 --- /dev/null +++ b/tests/api/testSavedSearches.php @@ -0,0 +1,176 @@ +ktapi = new KTAPI(); + $this->savedSearch = new savedSearches($this->ktapi); + $this->session = $this->ktapi->start_session('admin', 'admin'); + $this->root = $this->ktapi->get_root_folder(); + $this->assertTrue($this->root instanceof KTAPI_Folder); + } + + /** + * This method emds the KT session + * + */ + public function tearDown() { + $this->session->logout(); + } + + /** + * This method tests the creation of the saved search + * + */ + public function testCreate() + { + //case 1: user logged in + $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")'); + + $this->assertNotA($searchID, 'PEAR_Error'); + $this->assertNotNull($searchID); + $this->assertNoErrors(); + + $this->savedSearch->delete($searchID); + + //case 2: user NOT logged in + $this->ktapi->session_logout(); + $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")'); + + $this->assertIsA($searchID, 'PEAR_Error'); + $this->assertNoErrors(); + } + + /** + * This method tests the retrieval for the saved search by it's id + * + */ + public function testGetSavedSearch() + { + // case 1: search exists + $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")'); + $list = $this->savedSearch->getList(); + + $searchID = $list[0]['id']; + $search = $this->savedSearch->getSavedSearch($searchID); + + $this->assertNotNull($search); + $this->assertNoErrors(); + + $this->savedSearch->delete($searchID); + + // case 2: search does NOT exists + $array = array(); + $list = $this->savedSearch->getList(); + + $this->assertNotA($list, 'PEAR_Error'); + $this->assertEqual($list, $array); + $this->assertNoErrors(); + } + + /** + * This method tests the list of the saved search + * + */ + public function testList() + { + // case 1: Saved searches exist + $array = array(); + $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")'); + $list = $this->savedSearch->getList(); + + $this->assertNotA($list, 'PEAR_Error'); + $this->assertNotEqual($list, $array); + $this->assertNoErrors(); + + $this->savedSearch->delete($searchID); + + // case 2: saved searches do NOT exist + $list = $this->savedSearch->getList(); + + $this->assertNotA($list, 'PEAR_Error'); + $this->assertEqual($list, $array); + $this->assertNoErrors(); +} + + /** + * This method tests the deleting of the saved search + * + */ + public function testDelete() + { + $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")'); + $this->savedSearch->delete($searchID); + $result = $this->savedSearch->getSavedSearch($searchID); + + $array = array(); + $this->assertEqual($result, $array); + $this->assertNotA($result, 'PEAR_Error'); + $this->assertNoErrors(); + } + + /** + * This method tests the processing of the saved search + * + */ + public function testRunSavedSearch() + { + // create the document object + $randomFile = $this->createRandomFile(); + $document = $this->root->add_document('title.txt', 'name_1.txt', 'Default', $randomFile); + @unlink($randomFile); + + $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")'); + + $result = $this->savedSearch->runSavedSearch($searchID); + + $this->assertNotNull($result); + $this->assertNotA($result, 'PEAR_Error'); + $this->assertNoErrors(); + + $document->delete('Testing'); + $document->expunge(); + + $this->savedSearch->delete($searchID); + } + + + function createRandomFile($content = 'this is some text') { + $temp = tempnam(dirname(__FILE__), 'myfile'); + $fp = fopen($temp, 'wt'); + fwrite($fp, $content); + fclose($fp); + return $temp; + } +} +?> \ No newline at end of file