Commit 8ad633b16ec8dee76abca9bd8723fed22b9776ff
1 parent
28102e00
Added unit tests for saved search webservice functions
Committed By: Kevin Cyster Reviewed By: Megan Watson
Showing
1 changed file
with
129 additions
and
2 deletions
tests/api/testSavedSearches.php
| @@ -118,13 +118,14 @@ class savedSearchTestCase extends KTUnitTestCase { | @@ -118,13 +118,14 @@ class savedSearchTestCase extends KTUnitTestCase { | ||
| 118 | // case 1: Saved searches exist | 118 | // case 1: Saved searches exist |
| 119 | $array = array(); | 119 | $array = array(); |
| 120 | $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")'); | 120 | $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")'); |
| 121 | + $searchID_1 = $this->savedSearch->create('test_search_1', '(GeneralText contains "title")'); | ||
| 121 | $list = $this->savedSearch->getList(); | 122 | $list = $this->savedSearch->getList(); |
| 122 | - | ||
| 123 | $this->assertNotA($list, 'PEAR_Error'); | 123 | $this->assertNotA($list, 'PEAR_Error'); |
| 124 | $this->assertNotEqual($list, $array); | 124 | $this->assertNotEqual($list, $array); |
| 125 | $this->assertNoErrors(); | 125 | $this->assertNoErrors(); |
| 126 | 126 | ||
| 127 | $this->savedSearch->delete($searchID); | 127 | $this->savedSearch->delete($searchID); |
| 128 | + $this->savedSearch->delete($searchID_1); | ||
| 128 | 129 | ||
| 129 | // case 2: saved search does NOT exist | 130 | // case 2: saved search does NOT exist |
| 130 | $list = $this->savedSearch->getList(); | 131 | $list = $this->savedSearch->getList(); |
| @@ -139,7 +140,7 @@ class savedSearchTestCase extends KTUnitTestCase { | @@ -139,7 +140,7 @@ class savedSearchTestCase extends KTUnitTestCase { | ||
| 139 | $this->assertNotA($list, 'PEAR_Error'); | 140 | $this->assertNotA($list, 'PEAR_Error'); |
| 140 | $this->assertFalse($inList); | 141 | $this->assertFalse($inList); |
| 141 | $this->assertNoErrors(); | 142 | $this->assertNoErrors(); |
| 142 | -} | 143 | + } |
| 143 | 144 | ||
| 144 | /** | 145 | /** |
| 145 | * This method tests the deleting of the saved search | 146 | * This method tests the deleting of the saved search |
| @@ -182,7 +183,133 @@ class savedSearchTestCase extends KTUnitTestCase { | @@ -182,7 +183,133 @@ class savedSearchTestCase extends KTUnitTestCase { | ||
| 182 | $this->savedSearch->delete($searchID); | 183 | $this->savedSearch->delete($searchID); |
| 183 | } | 184 | } |
| 184 | 185 | ||
| 186 | + /** | ||
| 187 | + * This method tests the creation of the saved search | ||
| 188 | + * | ||
| 189 | + */ | ||
| 190 | + public function testCreate_KTAPI() | ||
| 191 | + { | ||
| 192 | + //case 1: user logged in | ||
| 193 | + $response = $this->ktapi->createSavedSearch('test_search', '(GeneralText contains "title")'); | ||
| 194 | + | ||
| 195 | + $this->assertIsA($response, 'array'); | ||
| 196 | + $this->assertEqual($response['status_code'], 0); | ||
| 197 | + $this->assertNoErrors(); | ||
| 198 | + | ||
| 199 | + $this->savedSearch->delete($response['results']['search_id']); | ||
| 185 | 200 | ||
| 201 | + //case 2: user NOT logged in | ||
| 202 | + $this->ktapi->session_logout(); | ||
| 203 | + $response = $this->ktapi->createSavedSearch('test_search', '(GeneralText contains "title")'); | ||
| 204 | + | ||
| 205 | + $this->assertIsA($response, 'array'); | ||
| 206 | + $this->assertEqual($response['status_code'], 1); | ||
| 207 | + $this->assertNoErrors(); | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + /** | ||
| 211 | + * This method tests the retrieval for the saved search by it's id | ||
| 212 | + * | ||
| 213 | + */ | ||
| 214 | + public function testGetSavedSearch_KTAPI() | ||
| 215 | + { | ||
| 216 | + // case 1: search exists | ||
| 217 | + $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")'); | ||
| 218 | + $list = $this->savedSearch->getList(); | ||
| 219 | + | ||
| 220 | + foreach($list as $item){ | ||
| 221 | + if($item['id'] == $searchID){ | ||
| 222 | + $search = $item['id']; | ||
| 223 | + break; | ||
| 224 | + } | ||
| 225 | + } | ||
| 226 | + $response = $this->ktapi->getSavedSearch($search); | ||
| 227 | + | ||
| 228 | + $this->assertIsA($response, 'array'); | ||
| 229 | + $this->assertEqual($response['status_code'], 0); | ||
| 230 | + $this->assertNoErrors(); | ||
| 231 | + $this->savedSearch->delete($searchID); | ||
| 232 | + | ||
| 233 | + // case 2: search does NOT exists | ||
| 234 | + $response = $this->ktapi->getSavedSearch($searchID); | ||
| 235 | + | ||
| 236 | + $this->assertIsA($response, 'array'); | ||
| 237 | + $this->assertEqual($response['status_code'], 1); | ||
| 238 | + $this->assertNoErrors(); | ||
| 239 | + | ||
| 240 | + } | ||
| 241 | + | ||
| 242 | + /** | ||
| 243 | + * This method tests the list of the saved search | ||
| 244 | + * | ||
| 245 | + */ | ||
| 246 | + public function testList_KTAPI() | ||
| 247 | + { | ||
| 248 | + // case 1: Saved searches exist | ||
| 249 | + $array = array(); | ||
| 250 | + $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")'); | ||
| 251 | + | ||
| 252 | + $response = $this->ktapi->getSavedSearchList(); | ||
| 253 | + | ||
| 254 | + $this->assertIsA($response, 'array'); | ||
| 255 | + $this->assertEqual($response['status_code'], 0); | ||
| 256 | + $this->assertNoErrors(); | ||
| 257 | + $this->savedSearch->delete($searchID); | ||
| 258 | + | ||
| 259 | + // case 2: saved search does NOT exist | ||
| 260 | + $response = $this->ktapi->getSavedSearchList(); | ||
| 261 | + | ||
| 262 | + $this->assertIsA($response, 'array'); | ||
| 263 | + $this->assertEqual($response['status_code'], 1); | ||
| 264 | + $this->assertNoErrors(); | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + /** | ||
| 268 | + * This method tests the deleting of the saved search | ||
| 269 | + * | ||
| 270 | + */ | ||
| 271 | + public function testDelete_KTAPI() | ||
| 272 | + { | ||
| 273 | + $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")'); | ||
| 274 | + $response = $this->ktapi->deleteSavedSearch($searchID); | ||
| 275 | + $result = $this->savedSearch->getSavedSearch($searchID); | ||
| 276 | + | ||
| 277 | + $array = array(); | ||
| 278 | + $this->assertEqual($result, $array); | ||
| 279 | + $this->assertIsA($response, 'array'); | ||
| 280 | + $this->assertEqual($response['results'], 0); | ||
| 281 | + $this->assertNoErrors(); | ||
| 282 | + } | ||
| 283 | + | ||
| 284 | + /** | ||
| 285 | + * This method tests the processing of the saved search | ||
| 286 | + * | ||
| 287 | + */ | ||
| 288 | + public function testRunSavedSearch_KTAPI() | ||
| 289 | + { | ||
| 290 | + // create the document object | ||
| 291 | + $randomFile = $this->createRandomFile(); | ||
| 292 | + $document = $this->root->add_document('title.txt', 'name_1.txt', 'Default', $randomFile); | ||
| 293 | + @unlink($randomFile); | ||
| 294 | + | ||
| 295 | + $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")'); | ||
| 296 | + | ||
| 297 | + $response = $this->ktapi->runSavedSearch($searchID); | ||
| 298 | + | ||
| 299 | + $this->assertIsA($response, 'array'); | ||
| 300 | + $this->assertEqual($response['status_code'], 0); | ||
| 301 | + $this->assertNoErrors(); | ||
| 302 | + | ||
| 303 | + $document->delete('Testing'); | ||
| 304 | + $document->expunge(); | ||
| 305 | + | ||
| 306 | + $this->savedSearch->delete($searchID); | ||
| 307 | + } | ||
| 308 | + | ||
| 309 | + /* | ||
| 310 | + * Method to create a random file for testing | ||
| 311 | + * | ||
| 312 | + */ | ||
| 186 | function createRandomFile($content = 'this is some text') { | 313 | function createRandomFile($content = 'this is some text') { |
| 187 | $temp = tempnam(dirname(__FILE__), 'myfile'); | 314 | $temp = tempnam(dirname(__FILE__), 'myfile'); |
| 188 | $fp = fopen($temp, 'wt'); | 315 | $fp = fopen($temp, 'wt'); |