Commit 873bae71b99894bed4193b0c119d6dac0f28c54b
Merge branch 'master' of git@github.com:ktgit/knowledgetree
Showing
3 changed files
with
284 additions
and
3 deletions
lib/foldermanagement/compressionArchiveUtil.inc.php
| ... | ... | @@ -614,6 +614,7 @@ class DownloadQueue |
| 614 | 614 | // Get all the folders within the current folder |
| 615 | 615 | $sWhereClause = "parent_folder_ids like '%,{$folderId}' |
| 616 | 616 | OR parent_folder_ids like '%,{$folderId},%' |
| 617 | + OR parent_folder_ids like '{$folderId},%' | |
| 617 | 618 | OR parent_id = {$folderId}"; |
| 618 | 619 | |
| 619 | 620 | $aFolderList = $oFolder->getList($sWhereClause); | ... | ... |
tests/api/testElectronicSignatures.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 APIElectronicSignaturesTestCase 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 | + * @var bool $esig_enabled True if electronic signatures for api are enabled | False if not enabled | |
| 28 | + */ | |
| 29 | + var $esig_enabled; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * This method sets up the KT session | |
| 33 | + * | |
| 34 | + */ | |
| 35 | + public function setUp() { | |
| 36 | + $this->ktapi = new KTAPI(); | |
| 37 | + $this->session = $this->ktapi->start_session('admin', 'admin'); | |
| 38 | + $this->root = $this->ktapi->get_root_folder(); | |
| 39 | + $this->assertTrue($this->root instanceof KTAPI_Folder); | |
| 40 | + $this->esig_enabled = $this->ktapi->electronic_sig_enabled(); | |
| 41 | + $this->assertTrue($this->esig_enabled); | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * This method emds the KT session | |
| 46 | + * | |
| 47 | + */ | |
| 48 | + public function tearDown() { | |
| 49 | + $this->session->logout(); | |
| 50 | + } | |
| 51 | + | |
| 52 | + /* *** Test webservice functions *** */ | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Testing folder creation and deletion, add document, get folder contents, folder detail | |
| 56 | + * Folder shortcuts and actions | |
| 57 | + */ | |
| 58 | + public function testFolderApiFunctions() | |
| 59 | + { | |
| 60 | + // Create a folder | |
| 61 | + // test without authentication - should fail | |
| 62 | + $result1 = $this->ktapi->create_folder(1, 'New test api folder'); | |
| 63 | + $this->assertEqual($result1['status_code'], 1); | |
| 64 | + | |
| 65 | + // test with authentication | |
| 66 | + $result2 = $this->ktapi->create_folder(1, 'New test api folder', 'admin', 'admin', 'Testing API'); | |
| 67 | + $folder_id = $result2['results']['id']; | |
| 68 | + $this->assertEqual($result2['status_code'], 0); | |
| 69 | + $this->assertTrue($result2['results']['parent_id'] == 1); | |
| 70 | + | |
| 71 | + // Create a sub folder | |
| 72 | + // test without authentication - should fail | |
| 73 | + $result3 = $this->ktapi->create_folder($folder_id, 'New test api sub-folder'); | |
| 74 | + $this->assertEqual($result3['status_code'], 1); | |
| 75 | + | |
| 76 | + // test with authentication | |
| 77 | + $result4 = $this->ktapi->create_folder($folder_id, 'New test api sub-folder', 'admin', 'admin', 'Testing API'); | |
| 78 | + $folder_id2 = $result4['results']['id']; | |
| 79 | + $this->assertEqual($result4['status_code'], 0); | |
| 80 | + | |
| 81 | + // Add a document | |
| 82 | + global $default; | |
| 83 | + $dir = $default->uploadDirectory; | |
| 84 | + $tempfilename = $this->createRandomFile('some text', $dir); | |
| 85 | + | |
| 86 | + // test without authentication - should fail | |
| 87 | + $doc = $this->ktapi->add_document($folder_id, 'New API test doc', 'testdoc1.txt', 'Default', $tempfilename); | |
| 88 | + $this->assertEqual($doc['status_code'], 1); | |
| 89 | + | |
| 90 | + // test with authentication | |
| 91 | + $doc = $this->ktapi->add_document($folder_id, 'New API test doc', 'testdoc1.txt', 'Default', $tempfilename, | |
| 92 | + 'admin', 'admin', 'Testing API'); | |
| 93 | + $this->assertEqual($doc['status_code'], 0); | |
| 94 | + $doc_id = $doc['results']['document_id']; | |
| 95 | + $this->assertEqual($doc['results']['title'], 'New API test doc'); | |
| 96 | + | |
| 97 | + // Rename the folder | |
| 98 | + // test without authentication - should fail | |
| 99 | + $renamed = $this->ktapi->rename_folder($folder_id, 'Renamed test folder'); | |
| 100 | + $this->assertEqual($renamed['status_code'], 1); | |
| 101 | + | |
| 102 | + // test with authentication | |
| 103 | + $renamed = $this->ktapi->rename_folder($folder_id, 'Renamed test folder', 'admin', 'admin', 'Testing API'); | |
| 104 | + $this->assertEqual($renamed['status_code'], 0); | |
| 105 | + | |
| 106 | + /** | |
| 107 | + * Copy and move appear to fail in other parts of the code, so only going to test failure here | |
| 108 | + * | |
| 109 | + * Must be VERY careful here with skipping the valid submissions, 3 failed auth attempts in a row locks out the user! | |
| 110 | + */ | |
| 111 | + // Copy folder | |
| 112 | + // test without authentication - should fail | |
| 113 | + $copied = $this->ktapi->copy_folder($source_id, $target_id, $reason); | |
| 114 | + $this->assertEqual($copied['status_code'], 1); | |
| 115 | + | |
| 116 | +// // test with authentication | |
| 117 | +// $copied = $this->ktapi->copy_folder($source_id, $target_id, $reason, 'admin', 'admin'); | |
| 118 | +// echo $copied['status_code']."sd<BR>"; | |
| 119 | +// $this->assertEqual($copied['status_code'], 0); | |
| 120 | + | |
| 121 | + // Move folder | |
| 122 | + // test without authentication - should fail | |
| 123 | + $moved = $this->ktapi->move_folder($source_id, $target_id, $reason); | |
| 124 | + $this->assertEqual($moved['status_code'], 1); | |
| 125 | + | |
| 126 | + // before we end up with 3 fails in a row (see note above the first copy attempt,) force a successful auth | |
| 127 | + $renamed = $this->ktapi->rename_folder($folder_id, 'A New Name', 'admin', 'admin', 'Testing API'); | |
| 128 | + | |
| 129 | +// // test with authentication | |
| 130 | +// $moved = $this->ktapi->move_folder($source_id, $target_id, $reason, 'admin', 'admin'); | |
| 131 | +// $this->assertEqual($moved['status_code'], 0); | |
| 132 | + | |
| 133 | + // before we end up with 3 fails in a row (see note above the first copy attempt,) force a successful auth | |
| 134 | + $renamed = $this->ktapi->rename_folder($folder_id, 'A New Name', 'admin', 'admin', 'Testing API'); | |
| 135 | + | |
| 136 | + // Clean up - delete the folder | |
| 137 | + // test without authentication - should fail | |
| 138 | + $deleted = $this->ktapi->delete_folder($folder_id, 'Testing API'); | |
| 139 | + $this->assertEqual($deleted['status_code'], 1); | |
| 140 | + | |
| 141 | + // test with authentication | |
| 142 | + $deleted = $this->ktapi->delete_folder($folder_id, 'Testing API', 'admin', 'admin'); | |
| 143 | + $this->assertEqual($deleted['status_code'], 0); | |
| 144 | + } | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * Testing document get, update, actions, delete, shortcuts and detail | |
| 148 | + */ | |
| 149 | + public function testDocumentApiFunctions() | |
| 150 | + { | |
| 151 | + // Create a folder | |
| 152 | + // test without authentication - should fail | |
| 153 | + $result1 = $this->ktapi->create_folder(1, 'New test api folder'); | |
| 154 | + $this->assertEqual($result1['status_code'], 1); | |
| 155 | + | |
| 156 | + // test with authentication | |
| 157 | + $result2 = $this->ktapi->create_folder(1, 'New test api folder', 'admin', 'admin', 'Testing API'); | |
| 158 | + $folder_id = $result2['results']['id']; | |
| 159 | + $this->assertEqual($result2['status_code'], 0); | |
| 160 | + | |
| 161 | + // Create a sub folder | |
| 162 | + // test without authentication - should fail | |
| 163 | + $result3 = $this->ktapi->create_folder($folder_id, 'New test api sub-folder'); | |
| 164 | + $this->assertEqual($result3['status_code'], 1); | |
| 165 | + | |
| 166 | + // test with authentication | |
| 167 | + $result4 = $this->ktapi->create_folder($folder_id, 'New test api sub-folder', 'admin', 'admin', 'Testing API'); | |
| 168 | + $folder_id2 = $result4['results']['id']; | |
| 169 | + $this->assertEqual($result4['status_code'], 0); | |
| 170 | + | |
| 171 | + // Add a document | |
| 172 | + global $default; | |
| 173 | + $dir = $default->uploadDirectory; | |
| 174 | + $tempfilename = $this->createRandomFile('some text', $dir); | |
| 175 | + | |
| 176 | + // test without authentication - should fail | |
| 177 | + $doc = $this->ktapi->add_document($folder_id, 'New API test doc', 'testdoc1.txt', 'Default', $tempfilename); | |
| 178 | + $this->assertEqual($doc['status_code'], 1); | |
| 179 | + | |
| 180 | + // test with authentication | |
| 181 | + $doc = $this->ktapi->add_document($folder_id, 'New API test doc', 'testdoc1.txt', 'Default', $tempfilename, | |
| 182 | + 'admin', 'admin', 'Testing API'); | |
| 183 | + $this->assertEqual($doc['status_code'], 0); | |
| 184 | + $doc_id = $doc['results']['document_id']; | |
| 185 | + | |
| 186 | + // Checkout the document | |
| 187 | + // test without authentication - should fail | |
| 188 | + $result1 = $this->ktapi->checkout_document($doc_id, 'Testing API', true); | |
| 189 | + $this->assertEqual($result1['status_code'], 1); | |
| 190 | + | |
| 191 | + // test with authentication | |
| 192 | + $result2 = $this->ktapi->checkout_document($doc_id, 'Testing API', true, 'admin', 'admin'); | |
| 193 | + $this->assertEqual($doc['status_code'], 0); | |
| 194 | + $this->assertTrue(!empty($result2['results'])); | |
| 195 | + | |
| 196 | + // Checkin the document | |
| 197 | + $dir = $default->uploadDirectory; | |
| 198 | + $tempfilename = $this->createRandomFile('some text', $dir); | |
| 199 | + // test without authentication - should fail | |
| 200 | + $result3 = $this->ktapi->checkin_document($doc_id, 'testdoc1.txt', 'Testing API', $tempfilename, false); | |
| 201 | + $this->assertEqual($result3['status_code'], 1); | |
| 202 | + | |
| 203 | + // test with authentication | |
| 204 | + $result4 = $this->ktapi->checkin_document($doc_id, 'testdoc1.txt', 'Testing API', $tempfilename, false, 'admin', 'admin'); | |
| 205 | + $this->assertEqual($result4['status_code'], 0); | |
| 206 | + $this->assertEqual($result4['results']['document_id'], $doc_id); | |
| 207 | + | |
| 208 | + // Delete the document | |
| 209 | + // test without authentication - should fail | |
| 210 | + $result5 = $this->ktapi->delete_document($doc_id, 'Testing API'); | |
| 211 | + $this->assertEqual($result5['status_code'], 1); | |
| 212 | + | |
| 213 | + // test with authentication | |
| 214 | + $result6 = $this->ktapi->delete_document($doc_id, 'Testing API', 'admin', 'admin', true); | |
| 215 | + $this->assertEqual($result6['status_code'], 0); | |
| 216 | + | |
| 217 | + // Clean up - delete the folder | |
| 218 | + // test without authentication - should fail | |
| 219 | + $result7 = $this->ktapi->delete_folder($folder_id, 'Testing API'); | |
| 220 | + $this->assertEqual($result7['status_code'], 1); | |
| 221 | + | |
| 222 | + $result8 = $this->ktapi->delete_folder($folder_id, 'Testing API', 'admin', 'admin'); | |
| 223 | + $this->assertEqual($result8['status_code'], 0); | |
| 224 | + } | |
| 225 | + | |
| 226 | + /** | |
| 227 | + * Helper function to create a document | |
| 228 | + */ | |
| 229 | + function createDocument($title, $filename, $folder = null) | |
| 230 | + { | |
| 231 | + if(is_null($folder)){ | |
| 232 | + $folder = $this->root; | |
| 233 | + } | |
| 234 | + | |
| 235 | + // Create a new document | |
| 236 | + $randomFile = $this->createRandomFile(); | |
| 237 | + $this->assertTrue(is_file($randomFile)); | |
| 238 | + | |
| 239 | + if ($this->esig_enabled) | |
| 240 | + { | |
| 241 | + $document = $folder->add_document($title, $filename, 'Default', $randomFile, 'admin', 'admin', 'Testing API'); | |
| 242 | + } | |
| 243 | + else | |
| 244 | + { | |
| 245 | + $document = $folder->add_document($title, $filename, 'Default', $randomFile); | |
| 246 | + } | |
| 247 | + $this->assertNotError($document); | |
| 248 | + | |
| 249 | + @unlink($randomFile); | |
| 250 | + if(PEAR::isError($document)) return false; | |
| 251 | + | |
| 252 | + return $document; | |
| 253 | + } | |
| 254 | + | |
| 255 | + /** | |
| 256 | + * Helper function to delete docs | |
| 257 | + */ | |
| 258 | + function deleteDocument($document) | |
| 259 | + { | |
| 260 | + $document->delete('Testing API'); | |
| 261 | + $document->expunge(); | |
| 262 | + } | |
| 263 | + | |
| 264 | + function createRandomFile($content = 'this is some text', $uploadDir = null) { | |
| 265 | + if(is_null($uploadDir)){ | |
| 266 | + $uploadDir = dirname(__FILE__); | |
| 267 | + } | |
| 268 | + $temp = tempnam($uploadDir, 'myfile'); | |
| 269 | + $fp = fopen($temp, 'wt'); | |
| 270 | + fwrite($fp, $content); | |
| 271 | + fclose($fp); | |
| 272 | + return $temp; | |
| 273 | + } | |
| 274 | +} | |
| 275 | +?> | |
| 0 | 276 | \ No newline at end of file | ... | ... |
tests/runtests.php
| ... | ... | @@ -8,6 +8,9 @@ class UnitTests extends TestSuite { |
| 8 | 8 | $this->TestSuite('Unit tests'); |
| 9 | 9 | |
| 10 | 10 | // KTAPI |
| 11 | + // Some of these tests will fail if Electronic Signatures are enabled for the API. | |
| 12 | + // To fix, check the failing functions and add 'admin', 'admin' as username and password, | |
| 13 | + // and where necessary send 'Testing API' as a reason | |
| 11 | 14 | $this->addFile('api/testApi.php'); |
| 12 | 15 | $this->addFile('api/testAuto.php'); |
| 13 | 16 | $this->addFile('api/testSavedSearches.php'); |
| ... | ... | @@ -17,6 +20,8 @@ class UnitTests extends TestSuite { |
| 17 | 20 | $this->addFile('api/testFolder.php'); |
| 18 | 21 | $this->addFile('api/testBulkActions.php'); |
| 19 | 22 | $this->addFile('api/testCollection.php'); |
| 23 | + // Only activate this test if Electronic Signatures are enabled for the API | |
| 24 | +// $this->addFile('api/testElectronicSignatures.php'); | |
| 20 | 25 | |
| 21 | 26 | // $this->addFile('SQLFile/test_sqlfile.php'); |
| 22 | 27 | // $this->addFile('cache/testCache.php'); |
| ... | ... | @@ -28,9 +33,9 @@ class UnitTests extends TestSuite { |
| 28 | 33 | // $this->addFile('filelike/testStringFileLike.php'); |
| 29 | 34 | |
| 30 | 35 | // Search (2) and indexing |
| 31 | - $this->addFile('documentProcessor/testExtracters.php'); | |
| 32 | - $this->addFile('documentProcessor/testGuidInserter.php'); | |
| 33 | - $this->addFile('search2/testSearch.php'); | |
| 36 | +// $this->addFile('documentProcessor/testExtracters.php'); | |
| 37 | +// $this->addFile('documentProcessor/testGuidInserter.php'); | |
| 38 | +// $this->addFile('search2/testSearch.php'); | |
| 34 | 39 | } |
| 35 | 40 | } |
| 36 | 41 | ... | ... |