Commit 12c2259ba3616d43ff1817431f26358a04679f97

Authored by donaldjackson
1 parent b55386de

new file: api/testAuto.php

modified:   api/testFolder.php
modified:   runtests.php

Added unit tests for folder and KTAPI
tests/api/testAuto.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 APIAutoTestCase extends KTUnitTestCase {
  10 +
  11 + /**
  12 + * @var object $ktapi The main ktapi object
  13 + */
  14 + var $ktapi;
  15 +
  16 + /**
  17 + * @var object $session The KT session object
  18 + */
  19 + var $session;
  20 +
  21 + /**
  22 + * @var object $root The KT folder object
  23 + */
  24 + var $root;
  25 +
  26 + /**
  27 + * This method sets up the KT session
  28 + *
  29 + */
  30 + public function setUp() {
  31 + $this->ktapi = new KTAPI();
  32 + $this->session = $this->ktapi->start_session('admin', 'admin');
  33 + $this->root = $this->ktapi->get_root_folder();
  34 + $this->assertTrue($this->root instanceof KTAPI_Folder);
  35 + }
  36 +
  37 + /**
  38 + * This method emds the KT session
  39 + *
  40 + */
  41 + public function tearDown() {
  42 + $this->session->logout();
  43 + }
  44 +
  45 +
  46 +
  47 + function testJunkanonymous_login() {
  48 + $result = $this->ktapi->anonymous_login(null);
  49 + $this->assertIsA($result, 'array');
  50 + $this->assertEqual($result['status_code'], 1);
  51 + }
  52 +
  53 + function tesRealanonymous_login() {
  54 + $result = $this->ktapi->anonymous_login($ip);
  55 + $this->assertIsA($result, 'array');
  56 + $this->assertEqual($result['status_code'], 0);
  57 + }
  58 +
  59 + function testJunklogin() {
  60 + $result = $this->ktapi->login(null, null, null);
  61 + $this->assertIsA($result, 'array');
  62 + $this->assertEqual($result['status_code'], 1);
  63 + }
  64 +
  65 + function tesReallogin() {
  66 + $result = $this->ktapi->login($username, $password, $ip);
  67 + $this->assertIsA($result, 'array');
  68 + $this->assertEqual($result['status_code'], 0);
  69 + }
  70 +
  71 +
  72 + function testJunkget_folder_detail_by_name() {
  73 + $result = $this->ktapi->get_folder_detail_by_name(null);
  74 + $this->assertIsA($result, 'array');
  75 + $this->assertEqual($result['status_code'], 1);
  76 + }
  77 +
  78 + function tesRealget_folder_detail_by_name() {
  79 + $result = $this->ktapi->get_folder_detail_by_name($folder_name);
  80 + $this->assertIsA($result, 'array');
  81 + $this->assertEqual($result['status_code'], 0);
  82 + }
  83 +
  84 +
  85 +
  86 +
  87 + function tesRealcreate_document_shortcut() {
  88 + $result = $this->ktapi->create_document_shortcut($target_folder_id, $source_document_id);
  89 + $this->assertIsA($result, 'array');
  90 + $this->assertEqual($result['status_code'], 0);
  91 + }
  92 +
  93 +
  94 +
  95 + function tesRealdelete_folder() {
  96 + $result = $this->ktapi->delete_folder($folder_id, $reason);
  97 + $this->assertIsA($result, 'array');
  98 + $this->assertEqual($result['status_code'], 0);
  99 + }
  100 +
  101 +
  102 +
  103 + function tesRealrename_folder() {
  104 + $result = $this->ktapi->rename_folder($folder_id, $newname);
  105 + $this->assertIsA($result, 'array');
  106 + $this->assertEqual($result['status_code'], 0);
  107 + }
  108 +
  109 +
  110 + function tesRealcopy_folder() {
  111 + $result = $this->ktapi->copy_folder($source_id, $target_id, $reason);
  112 + $this->assertIsA($result, 'array');
  113 + $this->assertEqual($result['status_code'], 0);
  114 + }
  115 +
  116 +
  117 + function tesRealmove_folder() {
  118 + $result = $this->ktapi->move_folder($source_id, $target_id, $reason);
  119 + $this->assertIsA($result, 'array');
  120 + $this->assertEqual($result['status_code'], 0);
  121 + }
  122 +
  123 + function testJunkget_document_types() {
  124 + $result = $this->ktapi->get_document_types(null);
  125 + $this->assertIsA($result, 'array');
  126 + $this->assertEqual($result['status_code'], 0);
  127 + }
  128 +
  129 + function tesRealget_document_types() {
  130 + $result = $this->ktapi->get_document_types($session_id);
  131 + $this->assertIsA($result, 'array');
  132 + $this->assertEqual($result['status_code'], 0);
  133 + }
  134 +
  135 + function testJunkget_document_detail_by_filename() {
  136 + $result = $this->ktapi->get_document_detail_by_filename(null, null, null);
  137 + $this->assertIsA($result, 'array');
  138 + $this->assertEqual($result['status_code'], 1);
  139 + }
  140 +
  141 + function tesRealget_document_detail_by_filename() {
  142 + $result = $this->ktapi->get_document_detail_by_filename($folder_id, $filename, $detail);
  143 + $this->assertIsA($result, 'array');
  144 + $this->assertEqual($result['status_code'], 0);
  145 + }
  146 +
  147 + function testJunkget_document_detail_by_title() {
  148 + $result = $this->ktapi->get_document_detail_by_title(null, null, null);
  149 + $this->assertIsA($result, 'array');
  150 + $this->assertEqual($result['status_code'], 1);
  151 + }
  152 +
  153 + function tesRealget_document_detail_by_title() {
  154 + $result = $this->ktapi->get_document_detail_by_title($folder_id, $title, $detail);
  155 + $this->assertIsA($result, 'array');
  156 + $this->assertEqual($result['status_code'], 0);
  157 + }
  158 +
  159 + function testJunkget_document_detail_by_name() {
  160 + $result = $this->ktapi->get_document_detail_by_name(null, null, null, null);
  161 + $this->assertIsA($result, 'array');
  162 + $this->assertEqual($result['status_code'], 1);
  163 + }
  164 +
  165 + function tesRealget_document_detail_by_name() {
  166 + $result = $this->ktapi->get_document_detail_by_name($folder_id, $document_name, $what, $detail);
  167 + $this->assertIsA($result, 'array');
  168 + $this->assertEqual($result['status_code'], 0);
  169 + }
  170 +
  171 +
  172 + function tesRealget_document_shortcuts() {
  173 + $result = $this->ktapi->get_document_shortcuts($document_id);
  174 + $this->assertIsA($result, 'array');
  175 + $this->assertEqual($result['status_code'], 0);
  176 + }
  177 +
  178 + function testJunkadd_document() {
  179 + $result = $this->ktapi->add_document(null, null, null, null, null);
  180 + $this->assertIsA($result, 'array');
  181 + $this->assertEqual($result['status_code'], 1);
  182 + }
  183 +
  184 + function tesRealadd_document() {
  185 + $result = $this->ktapi->add_document($folder_id, $title, $filename, $documenttype, $tempfilename);
  186 + $this->assertIsA($result, 'array');
  187 + $this->assertEqual($result['status_code'], 0);
  188 + }
  189 +
  190 +
  191 +
  192 + function tesRealadd_small_document_with_metadata() {
  193 + $result = $this->ktapi->add_small_document_with_metadata($folder_id, $title, $filename, $documenttype, $base64, $metadata, $sysdata);
  194 + $this->assertIsA($result, 'array');
  195 + $this->assertEqual($result['status_code'], 0);
  196 + }
  197 +
  198 + function testJunkadd_document_with_metadata() {
  199 + $result = $this->ktapi->add_document_with_metadata(null, null, null, null, null, null, null);
  200 + $this->assertIsA($result, 'array');
  201 + $this->assertEqual($result['status_code'], 1);
  202 + }
  203 +
  204 + function tesRealadd_document_with_metadata() {
  205 + $result = $this->ktapi->add_document_with_metadata($folder_id, $title, $filename, $documenttype, $tempfilename, $metadata, $sysdata);
  206 + $this->assertIsA($result, 'array');
  207 + $this->assertEqual($result['status_code'], 0);
  208 + }
  209 +
  210 + function tesRealadd_small_document() {
  211 + $result = $this->ktapi->add_small_document($folder_id, $title, $filename, $documenttype, $base64);
  212 + $this->assertIsA($result, 'array');
  213 + $this->assertEqual($result['status_code'], 0);
  214 + }
  215 +
  216 + function testJunkcheckin_document() {
  217 + $result = $this->ktapi->checkin_document(null, null, null, null, null);
  218 + $this->assertIsA($result, 'array');
  219 + $this->assertEqual($result['status_code'], 1);
  220 + }
  221 +
  222 + function tesRealcheckin_document() {
  223 + $result = $this->ktapi->checkin_document($document_id, $filename, $reason, $tempfilename, $major_update);
  224 + $this->assertIsA($result, 'array');
  225 + $this->assertEqual($result['status_code'], 0);
  226 + }
  227 +
  228 +
  229 + function tesRealcheckin_small_document_with_metadata() {
  230 + $result = $this->ktapi->checkin_small_document_with_metadata($document_id, $filename, $reason, $base64, $major_update, $metadata, $sysdata);
  231 + $this->assertIsA($result, 'array');
  232 + $this->assertEqual($result['status_code'], 0);
  233 + }
  234 +
  235 + function tesRealcheckin_document_with_metadata() {
  236 + $result = $this->ktapi->checkin_document_with_metadata($document_id, $filename, $reason, $tempfilename, $major_update, $metadata, $sysdata);
  237 + $this->assertIsA($result, 'array');
  238 + $this->assertEqual($result['status_code'], 0);
  239 + }
  240 +
  241 +
  242 +
  243 + function tesRealcheckin_small_document() {
  244 + $result = $this->ktapi->checkin_small_document($document_id, $filename, $reason, $base64, $major_update);
  245 + $this->assertIsA($result, 'array');
  246 + $this->assertEqual($result['status_code'], 0);
  247 + }
  248 +
  249 +
  250 +
  251 + function tesRealcheckout_document() {
  252 + $result = $this->ktapi->checkout_document($document_id, $reason, $download);
  253 + $this->assertIsA($result, 'array');
  254 + $this->assertEqual($result['status_code'], 0);
  255 + }
  256 +
  257 +
  258 +
  259 + function tesRealcheckout_small_document() {
  260 + $result = $this->ktapi->checkout_small_document($document_id, $reason, $download);
  261 + $this->assertIsA($result, 'array');
  262 + $this->assertEqual($result['status_code'], 0);
  263 + }
  264 +
  265 +
  266 + function tesRealundo_document_checkout() {
  267 + $result = $this->ktapi->undo_document_checkout($document_id, $reason);
  268 + $this->assertIsA($result, 'array');
  269 + $this->assertEqual($result['status_code'], 0);
  270 + }
  271 +
  272 +
  273 +
  274 + function tesRealdownload_document() {
  275 + $result = $this->ktapi->download_document($document_id, $version);
  276 + $this->assertIsA($result, 'array');
  277 + $this->assertEqual($result['status_code'], 0);
  278 + }
  279 +
  280 +
  281 +
  282 + function tesRealdownload_small_document() {
  283 + $result = $this->ktapi->download_small_document($document_id, $version);
  284 + $this->assertIsA($result, 'array');
  285 + $this->assertEqual($result['status_code'], 0);
  286 + }
  287 +
  288 +
  289 + function tesRealdelete_document() {
  290 + $result = $this->ktapi->delete_document($document_id, $reason);
  291 + $this->assertIsA($result, 'array');
  292 + $this->assertEqual($result['status_code'], 0);
  293 + }
  294 +
  295 +
  296 +
  297 + function tesRealchange_document_type() {
  298 + $result = $this->ktapi->change_document_type($document_id, $documenttype);
  299 + $this->assertIsA($result, 'array');
  300 + $this->assertEqual($result['status_code'], 0);
  301 + }
  302 +
  303 + function tesRealmove_document() {
  304 + $result = $this->ktapi->move_document($document_id, $folder_id, $reason, $newtitle, $newfilename);
  305 + $this->assertIsA($result, 'array');
  306 + $this->assertEqual($result['status_code'], 0);
  307 + }
  308 +
  309 +
  310 +
  311 + function tesRealrename_document_title() {
  312 + $result = $this->ktapi->rename_document_title($document_id, $newtitle);
  313 + $this->assertIsA($result, 'array');
  314 + $this->assertEqual($result['status_code'], 0);
  315 + }
  316 +
  317 +
  318 +
  319 + function tesRealrename_document_filename() {
  320 + $result = $this->ktapi->rename_document_filename($document_id, $newfilename);
  321 + $this->assertIsA($result, 'array');
  322 + $this->assertEqual($result['status_code'], 0);
  323 + }
  324 +
  325 +
  326 + function tesRealchange_document_owner() {
  327 + $result = $this->ktapi->change_document_owner($document_id, $username, $reason);
  328 + $this->assertIsA($result, 'array');
  329 + $this->assertEqual($result['status_code'], 0);
  330 + }
  331 +
  332 +
  333 + function tesRealstart_document_workflow() {
  334 + $result = $this->ktapi->start_document_workflow($document_id, $workflow);
  335 + $this->assertIsA($result, 'array');
  336 + $this->assertEqual($result['status_code'], 0);
  337 + }
  338 +
  339 +
  340 + function tesRealdelete_document_workflow() {
  341 + $result = $this->ktapi->delete_document_workflow($document_id);
  342 + $this->assertIsA($result, 'array');
  343 + $this->assertEqual($result['status_code'], 0);
  344 + }
  345 +
  346 +
  347 + function tesRealperform_document_workflow_transition() {
  348 + $result = $this->ktapi->perform_document_workflow_transition($document_id, $transition, $reason);
  349 + $this->assertIsA($result, 'array');
  350 + $this->assertEqual($result['status_code'], 0);
  351 + }
  352 +
  353 +
  354 + function tesRealget_document_metadata() {
  355 + $result = $this->ktapi->get_document_metadata($document_id);
  356 + $this->assertIsA($result, 'array');
  357 + $this->assertEqual($result['status_code'], 0);
  358 + }
  359 +
  360 +
  361 + function tesRealupdate_document_metadata() {
  362 + $result = $this->ktapi->update_document_metadata($document_id, $metadata, $sysdata);
  363 + $this->assertIsA($result, 'array');
  364 + $this->assertEqual($result['status_code'], 0);
  365 + }
  366 +
  367 +
  368 + function tesRealget_document_workflow_state() {
  369 + $result = $this->ktapi->get_document_workflow_state($document_id);
  370 + $this->assertIsA($result, 'array');
  371 + $this->assertEqual($result['status_code'], 0);
  372 + }
  373 +
  374 +
  375 + function tesRealget_document_transaction_history() {
  376 + $result = $this->ktapi->get_document_transaction_history($document_id);
  377 + $this->assertIsA($result, 'array');
  378 + $this->assertEqual($result['status_code'], 0);
  379 + }
  380 +
  381 +
  382 + function tesRealget_document_version_history() {
  383 + $result = $this->ktapi->get_document_version_history($document_id);
  384 + $this->assertIsA($result, 'array');
  385 + $this->assertEqual($result['status_code'], 0);
  386 + }
  387 +
  388 +
  389 + function tesRealget_document_links() {
  390 + $result = $this->ktapi->get_document_links($document_id);
  391 + $this->assertIsA($result, 'array');
  392 + $this->assertEqual($result['status_code'], 0);
  393 + }
  394 +
  395 +
  396 + function tesRealunlink_documents() {
  397 + $result = $this->ktapi->unlink_documents($parent_document_id, $child_document_id);
  398 + $this->assertIsA($result, 'array');
  399 + $this->assertEqual($result['status_code'], 0);
  400 + }
  401 +
  402 + function tesReallink_documents() {
  403 + $result = $this->ktapi->link_documents($parent_document_id, $child_document_id, $type);
  404 + $this->assertIsA($result, 'array');
  405 + $this->assertEqual($result['status_code'], 0);
  406 + }
  407 +
  408 + function tesRealget_client_policies() {
  409 + $result = $this->ktapi->get_client_policies($client);
  410 + $this->assertIsA($result, 'array');
  411 + $this->assertEqual($result['status_code'], 0);
  412 + }
  413 +
  414 + function testJunksearch() {
  415 + $result = $this->ktapi->search(null, null);
  416 + $this->assertIsA($result, 'array');
  417 + $this->assertEqual($result['status_code'], 1);
  418 + }
  419 +
  420 + function tesRealsearch() {
  421 + $result = $this->ktapi->search($query, $options);
  422 + $this->assertIsA($result, 'array');
  423 + $this->assertEqual($result['status_code'], 0);
  424 + }
  425 +
  426 +}
  427 +?>
0 \ No newline at end of file 428 \ No newline at end of file
tests/api/testFolder.php
@@ -186,8 +186,8 @@ class APIFolderTestCase extends KTUnitTestCase { @@ -186,8 +186,8 @@ class APIFolderTestCase extends KTUnitTestCase {
186 function testPermissions() 186 function testPermissions()
187 { 187 {
188 $root = $this->ktapi->get_root_folder(); 188 $root = $this->ktapi->get_root_folder();
189 - $folder = $root->add_folder('testX');  
190 - $this->assertEntity($folder, 'KTAPI_Folder'); 189 + $folder = $root->add_folder('testXXXXX');
  190 + $this->assertIsA($folder, 'KTAPI_Folder');
191 if(PEAR::isError($folder)) return; 191 if(PEAR::isError($folder)) return;
192 192
193 $permAllocation = $folder->getPermissionAllocation(); 193 $permAllocation = $folder->getPermissionAllocation();
@@ -198,7 +198,12 @@ class APIFolderTestCase extends KTUnitTestCase { @@ -198,7 +198,12 @@ class APIFolderTestCase extends KTUnitTestCase {
198 $this->assertNotNull($roleAllocation); 198 $this->assertNotNull($roleAllocation);
199 $this->assertEntity($roleAllocation, KTAPI_RoleAllocation); 199 $this->assertEntity($roleAllocation, KTAPI_RoleAllocation);
200 200
201 - $folder->delete('Testing'); 201 + $folder->delete('testXXXXX');
  202 + }
  203 +
  204 + function testTransactionHistory() {
  205 + $transactions = $this->ktapi->get_folder_transaction_history(1);
  206 + $this->assertIsA($transactions, 'array');
202 } 207 }
203 } 208 }
204 ?> 209 ?>
tests/runtests.php
@@ -9,6 +9,7 @@ class UnitTests extends TestSuite { @@ -9,6 +9,7 @@ class UnitTests extends TestSuite {
9 9
10 // KTAPI 10 // KTAPI
11 $this->addFile('api/testApi.php'); 11 $this->addFile('api/testApi.php');
  12 + $this->addFile('api/testAuto.php');
12 $this->addFile('api/testSavedSearches.php'); 13 $this->addFile('api/testSavedSearches.php');
13 $this->addFile('api/testAcl.php'); 14 $this->addFile('api/testAcl.php');
14 $this->addFile('api/testAuthentication.php'); 15 $this->addFile('api/testAuthentication.php');