Commit 28181f0e692225e541cf0846136b8c58ccf0d7f5

Authored by Kevin Cyster
1 parent 767fd85c

Added unit tests for webservice functionality for subscriptions

Committed By: Kevin Cyster

Reviewed By: Megan Watson
Showing 1 changed file with 59 additions and 0 deletions
tests/api/testDocument.php
... ... @@ -356,5 +356,64 @@ class APIDocumentTestCase extends KTUnitTestCase {
356 356 }
357 357 }
358 358 */
  359 +
  360 + /**
  361 + * Method to test the document subscriptions for webservices
  362 + *
  363 + */
  364 + public function testSubscriptions_KTAPI()
  365 + {
  366 + $this->ktapi->session_logout();
  367 + $this->session = $this->ktapi->start_session('admin', 'admin');
  368 +
  369 + $randomFile = APIDocumentHelper::createRandomFile();
  370 + $this->assertTrue(is_file($randomFile));
  371 +
  372 + $document = $this->root->add_document('testtitle.txt', 'testname.txt', 'Default', $randomFile);
  373 + $this->assertIsA($document, 'KTAPI_Document');
  374 + $this->assertNoErrors();
  375 +
  376 + @unlink($randomFile);
  377 + $documentid = $document->get_documentid();
  378 +
  379 + // case no subscription
  380 + $response = $this->ktapi->is_document_subscribed($documentid);
  381 + $this->assertIsA($response, 'array');
  382 + $this->assertEqual($response['results']['subscribed'], 'FALSE');
  383 + $this->assertNoErrors();
  384 +
  385 + //case add subscription
  386 + $response = $this->ktapi->subscribe_to_document($documentid);
  387 + $this->assertIsA($response, 'array');
  388 + $this->assertEqual($response['results']['action_result'], 'TRUE');
  389 + $this->assertNoErrors();
  390 +
  391 + //case add DUPLICATE subscription
  392 + $response = $this->ktapi->subscribe_to_document($documentid);
  393 + $this->assertIsA($response, 'array');
  394 + $this->assertEqual($response['results']['action_result'], 'TRUE');
  395 + $this->assertNoErrors();
  396 +
  397 + // case subscription exists
  398 + $response = $this->ktapi->is_document_subscribed($documentid);
  399 + $this->assertIsA($response, 'array');
  400 + $this->assertEqual($response['results']['subscribed'], 'TRUE');
  401 + $this->assertNoErrors();
  402 +
  403 + //case delete subscription
  404 + $response = $this->ktapi->unsubscribe_from_document($documentid);
  405 + $this->assertIsA($response, 'array');
  406 + $this->assertEqual($response['results']['action_result'], 'TRUE');
  407 + $this->assertNoErrors();
  408 +
  409 + //case delete NOT EXISTANT subscription
  410 + $response = $this->ktapi->unsubscribe_from_document($documentid);
  411 + $this->assertIsA($response, 'array');
  412 + $this->assertEqual($response['results']['action_result'], 'TRUE');
  413 + $this->assertNoErrors();
  414 +
  415 + $document->delete('Test');
  416 + $document->expunge();
  417 + }
359 418 }
360 419 ?>
... ...