Commit e68e3b69dd57018850c4a2a711c01a902dd0c092

Authored by Kevin Cyster
1 parent ae1ccccd

Moved the saved searches tests to a separate file

Committed By: Kevin Cyster
Reviewed By: Megan Watson

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@9742 c91229c3-7414-0410-bfa2-8a42b809f60b
tests/api/testApi.php
... ... @@ -139,7 +139,7 @@ class APITestCase extends KTUnitTestCase {
139 139 $user = $this->ktapi->can_user_access_object_requiring_permission($internalDocObject2, $permission);
140 140  
141 141 $this->assertNotNull($user);
142   - $this->assertEqual($user, PEAR::isError($user));
  142 + $this->assertIsA($user, 'PEAR_Error');
143 143 $this->assertNoErrors();
144 144  
145 145 // clean up
... ... @@ -302,6 +302,7 @@ class APITestCase extends KTUnitTestCase {
302 302 // create the document object
303 303 $randomFile = $this->createRandomFile();
304 304 $document = $this->root->add_document('title_5.txt', 'name_5.txt', 'Default', $randomFile);
  305 + @unlink($randomFile);
305 306  
306 307 $documentID = $document->get_documentid();
307 308  
... ... @@ -310,7 +311,9 @@ class APITestCase extends KTUnitTestCase {
310 311 $this->assertNotNull($docObject);
311 312 $this->assertIsA($docObject, 'KTAPI_Document');
312 313 $this->assertNoErrors();
313   - @unlink($randomFile);
  314 +
  315 + $document->delete('Testing');
  316 + $document->expunge();
314 317 }
315 318  
316 319 /**
... ... @@ -422,81 +425,6 @@ class APITestCase extends KTUnitTestCase {
422 425 $this->assertNoErrors();
423 426 }
424 427  
425   - /**
426   - * This method tests the creation of the saved search
427   - *
428   - */
429   - public function testCreate()
430   - {
431   - $searchID = $this->ktapi->create(rand(1,1000), '(GeneralText contains "title")');
432   -
433   - $this->assertNotNull($searchID);
434   - $this->assertNoErrors();
435   - }
436   -
437   - /**
438   - * This method tests the retrieval for the saved search by it's id
439   - *
440   - */
441   - public function testGetSavedSearch()
442   - {
443   - $list = $this->ktapi->getList();
444   -
445   - $searchID = $list[0]['id'];
446   - $search = $this->ktapi->getSavedSearch($searchID);
447   -
448   - $this->assertNotNull($search);
449   - $this->assertNoErrors();
450   - }
451   -
452   - /**
453   - * This method tests the list of the saved search
454   - *
455   - */
456   - public function testList()
457   - {
458   - $list = $this->ktapi->getList();
459   -
460   - $this->assertNotNull($list);
461   - $this->assertNoErrors();
462   - }
463   -
464   - /**
465   - * This method tests the deleting of the saved search
466   - *
467   - */
468   - public function testDelete()
469   - {
470   - $searchID = $this->ktapi->create(rand(1,1000), '(GeneralText contains "title")');
471   - $this->ktapi->delete($searchID);
472   - $result = $this->ktapi->getSavedSearch($searchID);
473   -
474   - $this->assertTrue(empty($result));
475   - $this->assertEqual($result, PEAR::isError($result));
476   - $this->assertNoErrors();
477   - }
478   -
479   - /**
480   - * This method tests the processing of the saved search
481   - *
482   - */
483   - public function testRunSavedSearch()
484   - {
485   - // create the document object
486   - $randomFile = $this->createRandomFile();
487   - $document = $this->root->add_document('title_1.txt', 'name_1.txt', 'Default', $randomFile);
488   -
489   - $searchID = $this->ktapi->create(rand(1,1000), '(GeneralText contains "title")');
490   -
491   - $result = $this->ktapi->runSavedSearch($searchID);
492   -
493   - $this->assertNotNull($result);
494   - $this->assertNotEqual($result, PEAR::isError($result));
495   - $this->assertNoErrors();
496   - @unlink($randomFile);
497   - }
498   -
499   -
500 428 function createRandomFile($content = 'this is some text') {
501 429 $temp = tempnam(dirname(__FILE__), 'myfile');
502 430 $fp = fopen($temp, 'wt');
... ... @@ -505,4 +433,4 @@ class APITestCase extends KTUnitTestCase {
505 433 return $temp;
506 434 }
507 435 }
508   -?>
  436 +?>
509 437 \ No newline at end of file
... ...
tests/api/testSavedSearches.php 0 โ†’ 100644
  1 +<?php
  2 +require_once (KT_DIR . '/tests/test.php');
  3 +require_once (KT_DIR . '/ktapi/ktapi.inc.php');
  4 +
  5 +/**
  6 +* These are the unit tests for the main KTAPI class
  7 +*
  8 +*/
  9 +class savedSearchTestCase extends KTUnitTestCase {
  10 +
  11 + /**
  12 + * @var object $ktapi The main ktapi object
  13 + */
  14 + var $ktapi;
  15 +
  16 + /**
  17 + * @var object $savedSearch The saved searches object object
  18 + */
  19 + var $savedSearch;
  20 +
  21 + /**
  22 + * @var object $session The KT session object
  23 + */
  24 + var $session;
  25 +
  26 + /**
  27 + * @var object $root The KT folder object
  28 + */
  29 + var $root;
  30 +
  31 + /**
  32 + * This method sets up the KT session
  33 + *
  34 + */
  35 + public function setUp() {
  36 + $this->ktapi = new KTAPI();
  37 + $this->savedSearch = new savedSearches($this->ktapi);
  38 + $this->session = $this->ktapi->start_session('admin', 'admin');
  39 + $this->root = $this->ktapi->get_root_folder();
  40 + $this->assertTrue($this->root instanceof KTAPI_Folder);
  41 + }
  42 +
  43 + /**
  44 + * This method emds the KT session
  45 + *
  46 + */
  47 + public function tearDown() {
  48 + $this->session->logout();
  49 + }
  50 +
  51 + /**
  52 + * This method tests the creation of the saved search
  53 + *
  54 + */
  55 + public function testCreate()
  56 + {
  57 + //case 1: user logged in
  58 + $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")');
  59 +
  60 + $this->assertNotA($searchID, 'PEAR_Error');
  61 + $this->assertNotNull($searchID);
  62 + $this->assertNoErrors();
  63 +
  64 + $this->savedSearch->delete($searchID);
  65 +
  66 + //case 2: user NOT logged in
  67 + $this->ktapi->session_logout();
  68 + $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")');
  69 +
  70 + $this->assertIsA($searchID, 'PEAR_Error');
  71 + $this->assertNoErrors();
  72 + }
  73 +
  74 + /**
  75 + * This method tests the retrieval for the saved search by it's id
  76 + *
  77 + */
  78 + public function testGetSavedSearch()
  79 + {
  80 + // case 1: search exists
  81 + $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")');
  82 + $list = $this->savedSearch->getList();
  83 +
  84 + $searchID = $list[0]['id'];
  85 + $search = $this->savedSearch->getSavedSearch($searchID);
  86 +
  87 + $this->assertNotNull($search);
  88 + $this->assertNoErrors();
  89 +
  90 + $this->savedSearch->delete($searchID);
  91 +
  92 + // case 2: search does NOT exists
  93 + $array = array();
  94 + $list = $this->savedSearch->getList();
  95 +
  96 + $this->assertNotA($list, 'PEAR_Error');
  97 + $this->assertEqual($list, $array);
  98 + $this->assertNoErrors();
  99 + }
  100 +
  101 + /**
  102 + * This method tests the list of the saved search
  103 + *
  104 + */
  105 + public function testList()
  106 + {
  107 + // case 1: Saved searches exist
  108 + $array = array();
  109 + $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")');
  110 + $list = $this->savedSearch->getList();
  111 +
  112 + $this->assertNotA($list, 'PEAR_Error');
  113 + $this->assertNotEqual($list, $array);
  114 + $this->assertNoErrors();
  115 +
  116 + $this->savedSearch->delete($searchID);
  117 +
  118 + // case 2: saved searches do NOT exist
  119 + $list = $this->savedSearch->getList();
  120 +
  121 + $this->assertNotA($list, 'PEAR_Error');
  122 + $this->assertEqual($list, $array);
  123 + $this->assertNoErrors();
  124 +}
  125 +
  126 + /**
  127 + * This method tests the deleting of the saved search
  128 + *
  129 + */
  130 + public function testDelete()
  131 + {
  132 + $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")');
  133 + $this->savedSearch->delete($searchID);
  134 + $result = $this->savedSearch->getSavedSearch($searchID);
  135 +
  136 + $array = array();
  137 + $this->assertEqual($result, $array);
  138 + $this->assertNotA($result, 'PEAR_Error');
  139 + $this->assertNoErrors();
  140 + }
  141 +
  142 + /**
  143 + * This method tests the processing of the saved search
  144 + *
  145 + */
  146 + public function testRunSavedSearch()
  147 + {
  148 + // create the document object
  149 + $randomFile = $this->createRandomFile();
  150 + $document = $this->root->add_document('title.txt', 'name_1.txt', 'Default', $randomFile);
  151 + @unlink($randomFile);
  152 +
  153 + $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")');
  154 +
  155 + $result = $this->savedSearch->runSavedSearch($searchID);
  156 +
  157 + $this->assertNotNull($result);
  158 + $this->assertNotA($result, 'PEAR_Error');
  159 + $this->assertNoErrors();
  160 +
  161 + $document->delete('Testing');
  162 + $document->expunge();
  163 +
  164 + $this->savedSearch->delete($searchID);
  165 + }
  166 +
  167 +
  168 + function createRandomFile($content = 'this is some text') {
  169 + $temp = tempnam(dirname(__FILE__), 'myfile');
  170 + $fp = fopen($temp, 'wt');
  171 + fwrite($fp, $content);
  172 + fclose($fp);
  173 + return $temp;
  174 + }
  175 +}
  176 +?>
0 177 \ No newline at end of file
... ...