From 6aa159982caaf13c7f2d42167d15e573cfd50697 Mon Sep 17 00:00:00 2001 From: Paul Barrett Date: Tue, 30 Jun 2009 13:16:47 +0200 Subject: [PATCH] CMIS Repository config change. Fixed CMIS Unit Test breakage caused by moving and changing of core CMIS interface --- lib/api/ktcmis/config/repositories.xml | 2 +- lib/api/ktcmis/ktcmis.inc.php | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- tests/ktcmis/testCmisApi.php | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- 3 files changed, 120 insertions(+), 38 deletions(-) diff --git a/lib/api/ktcmis/config/repositories.xml b/lib/api/ktcmis/config/repositories.xml index 301bccb..8f65088 100644 --- a/lib/api/ktcmis/config/repositories.xml +++ b/lib/api/ktcmis/config/repositories.xml @@ -19,7 +19,7 @@ KnowledgeTree KnowledgeTree Document Management System 3.6.2 - Root%20Folder + Root Folder 0.61c diff --git a/lib/api/ktcmis/ktcmis.inc.php b/lib/api/ktcmis/ktcmis.inc.php index c13464a..6cc8d3a 100644 --- a/lib/api/ktcmis/ktcmis.inc.php +++ b/lib/api/ktcmis/ktcmis.inc.php @@ -77,20 +77,11 @@ class KTCMISBase { public function startSession($username, $password) { - global $default; - $default->log->debug("attempt auth with $username :: $password"); $this->session = null; - // remove as soon as actual auth code is in place - $username = 'admin'; - $password = 'admin'; + $this->ktapi = new KTAPI(); $this->session =& $this->ktapi->start_session($username, $password); - if (PEAR::isError($this->session)) - { - $default->log->debug("FAILED $username :: $password FAILED"); - } - return $this->session; } @@ -358,6 +349,37 @@ class KTNavigationService extends KTCMISBase { ); } + /** + * Gets the parents for the selected object + * + * @param string $repositoryId + * @param string $folderId + * @param boolean $includeAllowableActions + * @param boolean $includeRelationships + * @param string $filter + * @return ancestry[] + */ + function getObjectParents($repositoryId, $objectId, $includeAllowableActions, $includeRelationships, $filter = '') + { + $ancestryResult = $this->NavigationService->getObjectParents($repositoryId, $objectId, $includeAllowableActions, + $includeRelationships); + + if (PEAR::isError($ancestryResult)) + { + return array( + "status_code" => 1, + "message" => "Failed getting ancestry for object" + ); + } + + $ancestry = CMISUtil::decodeObjectHierarchy($ancestryResult, 'child'); + + return array( + "status_code" => 0, + "results" => $ancestry + ); + } + } /** @@ -411,6 +433,35 @@ class KTObjectService extends KTCMISBase { ); } + /** + * Function to create a folder + * + * @param string $repositoryId The repository to which the folder must be added + * @param string $typeId Object Type id for the folder object being created + * @param array $properties Array of properties which must be applied to the created folder object + * @param string $folderId The id of the folder which will be the parent of the created folder object + * @return string $objectId The id of the created folder object + */ + function createFolder($repositoryId, $typeId, $properties, $folderId) + { + $objectId = null; + + $objectId = $this->ObjectService->createFolder($repositoryId, $typeId, $properties, $folderId); + + if (PEAR::isError($propertiesResult)) + { + return array( + "status_code" => 1, + "message" => "Failed getting properties for object" + ); + } + + return array( + 'status_code' => 0, + 'results' => $objectId + ); + } + } ?> diff --git a/tests/ktcmis/testCmisApi.php b/tests/ktcmis/testCmisApi.php index b3f8cd5..bac216d 100644 --- a/tests/ktcmis/testCmisApi.php +++ b/tests/ktcmis/testCmisApi.php @@ -1,12 +1,14 @@ ktapi = new KTAPI(); $this->session = $this->ktapi->start_session(KT_TEST_USER, KT_TEST_PASS); - $this->ktcmis = new KTCMIS($this->ktapi); $this->root = $this->ktapi->get_root_folder(); $this->folders = array(); $this->docs = array(); @@ -60,9 +61,11 @@ class CMISTestCase extends KTUnitTestCase { // Repository service functions function testRepositoryServices() { + $RepositoryService = new KTRepositoryService(); + // TEST 1 // test get repositories - $response = $this->ktcmis->getRepositories(); + $response = $RepositoryService->getRepositories(); $this->assertEqual($response['status_code'], 0); $this->assertNotNull($response['results'][0]); @@ -91,7 +94,7 @@ class CMISTestCase extends KTUnitTestCase { // test getting info for specified repository // get info - $response = $this->ktcmis->getRepositoryInfo($repositoryId); + $response = $RepositoryService->getRepositoryInfo($repositoryId); $this->assertEqual($response['status_code'], 0); $this->assertNotNull($response['results']); @@ -119,7 +122,7 @@ class CMISTestCase extends KTUnitTestCase { // TEST 3 // test get object types supported by specified repository - $response = $this->ktcmis->getTypes($repositoryId); + $response = $RepositoryService->getTypes($repositoryId); $this->assertEqual($response['status_code'], 0); $this->assertNotNull($response['results']); @@ -148,7 +151,7 @@ class CMISTestCase extends KTUnitTestCase { // now get info foreach ($types as $typeId) { - $response = $this->ktcmis->getTypeDefinition($repositoryId, $typeId); + $response = $RepositoryService->getTypeDefinition($repositoryId, $typeId); $this->assertEqual($response['status_code'], 0); $this->assertNotNull($response['results']); @@ -169,18 +172,20 @@ class CMISTestCase extends KTUnitTestCase { } // test printout - echo '
 
'; + if (DEBUG_CMIS) echo '
 
'; } // Navigation service functions function testNavigationServices() { + $NavigationService = new KTNavigationService(); + $NavigationService->startSession(KT_TEST_USER, KT_TEST_PASS); + // set up the folder/doc tree structure with which we will be testing $this->createFolderDocStructure(); - // TEST 1 - // test getting descendants - $response = $this->ktcmis->getRepositories(); + $RepositoryService = new KTRepositoryService(); + $response = $RepositoryService->getRepositories(); $this->assertEqual($response['status_code'], 0); $this->assertNotNull($response['results'][0]); @@ -189,12 +194,15 @@ class CMISTestCase extends KTUnitTestCase { $repository = $response['results'][0]; $repositoryId = $repository['repositoryId']; + // TEST 1 + // test getting descendants // test descendant functionality on first of created folders, should have depth 2; $folderid = 'F' . $this->folders[1]; +// echo "FOLDER: $folderid
"; // $folderid = 'F1'; $depth = 2; - $result = $this->ktcmis->getDescendants($repositoryId, $folderid, false, false, $depth); + $result = $NavigationService->getDescendants($repositoryId, $folderid, false, false, $depth); // echo '
'.print_r($result, true).'
'; // var_dump($result); $this->assertEqual($response['status_code'], 0); @@ -217,7 +225,7 @@ class CMISTestCase extends KTUnitTestCase { // test getting direct children, using the second set of folders, should have a folder and a document as children $folderid_2 = 'F' . $this->folders[0]; - $result = $this->ktcmis->getChildren($repositoryId, $folderid_2, false, false); + $result = $NavigationService->getChildren($repositoryId, $folderid_2, false, false); $this->assertNotNull($result['results']); $children = $result['results']; @@ -234,7 +242,7 @@ class CMISTestCase extends KTUnitTestCase { // test getting folder parent, using first created folder, parent should be root folder // echo "OUTPUT FROM FIRST TEST
"; - $ancestry = $this->ktcmis->getFolderParent($repositoryId, $folderid, false, false, false); + $ancestry = $NavigationService->getFolderParent($repositoryId, $folderid, false, false, false); $this->assertNotNull($ancestry['results']); // echo "OUTPUT FROM FIRST TEST
"; // echo '
'.print_r($ancestry, true).'
'; @@ -247,7 +255,7 @@ class CMISTestCase extends KTUnitTestCase { // echo "OUTPUT FROM SECOND TEST
"; // TODO since here we are testing more than one level up, add check for depth as with testGetDescendants - $ancestry = $this->ktcmis->getFolderParent($repositoryId, $subfolder_id, false, false, true); + $ancestry = $NavigationService->getFolderParent($repositoryId, $subfolder_id, false, false, true); $this->assertNotNull($ancestry['results']); // echo "OUTPUT FROM SECOND TEST
"; // echo '
'.print_r($ancestry, true).'
'; @@ -262,7 +270,7 @@ class CMISTestCase extends KTUnitTestCase { // test getting object parent(s) with a document $objectId = 'D' . $this->docs[0]->get_documentid(); - $ancestry = $this->ktcmis->getObjectParents($repositoryId, $objectId, false, false); + $ancestry = $NavigationService->getObjectParents($repositoryId, $objectId, false, false); $this->assertNotNull($ancestry); // echo '
'.print_r($ancestry, true).'
'; @@ -273,7 +281,7 @@ class CMISTestCase extends KTUnitTestCase { // test getting object parent(s) with a folder $objectId = 'F' . $this->subfolders[0]; - $ancestry = $this->ktcmis->getObjectParents($repositoryId, $objectId, false, false); + $ancestry = $NavigationService->getObjectParents($repositoryId, $objectId, false, false); $this->assertNotNull($ancestry); // echo '
'.print_r($ancestry, true).'
'; @@ -284,20 +292,21 @@ class CMISTestCase extends KTUnitTestCase { $this->cleanupFolderDocStructure(); // test printout - echo '
 
'; + if (DEBUG_CMIS) echo '
 
'; } // Object Services function testObjectServices() { + $ObjectService = new KTObjectService(); + $ObjectService->startSession(KT_TEST_USER, KT_TEST_PASS); + // set up the folder/doc tree structure with which we will be testing $this->createFolderDocStructure(); - - // TEST 1 - // test getting properties for a specific object - $response = $this->ktcmis->getRepositories(); + $RepositoryService = new KTRepositoryService(); + $response = $RepositoryService->getRepositories(); $this->assertEqual($response['status_code'], 0); $this->assertNotNull($response['results'][0]); @@ -305,10 +314,12 @@ class CMISTestCase extends KTUnitTestCase { // we only expect one repository $repository = $response['results'][0]; $repositoryId = $repository['repositoryId']; - + + // TEST 1 + // test getting properties for a specific object $objectId = 'F'.$this->folders[0]; - $properties = $this->ktcmis->getProperties($repositoryId, $objectId, false, false); + $properties = $ObjectService->getProperties($repositoryId, $objectId, false, false); $this->assertNotNull($properties['results']); // echo '
'.print_r($properties['results'], true).'
'; // @@ -317,17 +328,33 @@ class CMISTestCase extends KTUnitTestCase { $objectId = 'D'.$this->docs[0]->get_documentid(); - $properties = $this->ktcmis->getProperties($repositoryId, $objectId, false, false); + $properties = $ObjectService->getProperties($repositoryId, $objectId, false, false); $this->assertNotNull($properties['results']); // test printout $this->printTable($properties['results'][0], 'Properties for Folder Object ' . $objectId . ' (getProperties())'); + // TEST 2 + // test creation of a folder (random name so that we don't have to clean up after) + // TODO test invalid type + // TODO test invalid parent folder + // TODO other invalid parameters + $created = $ObjectService->createFolder($repositoryId, 'Folder', array('name' => 'My Test Folder ' . mt_rand()), 1); + $this->assertNotNull($created['results']); + + // delete created folder + if (!is_null($created['results'])) + { + $folder_id = $created['results']; + CMISUtil::decodeObjectId($folder_id); + $this->ktapi->delete_folder($folder_id, 'Testing API', KT_TEST_USER, KT_TEST_PASS); + } + // tear down the folder/doc tree structure with which we were testing $this->cleanupFolderDocStructure(); // test printout - echo '
 
'; + if (DEBUG_CMIS) echo '
 
'; } /** @@ -493,8 +520,9 @@ class CMISTestCase extends KTUnitTestCase { function printTable($results, $header, $subheader = '', $depth = 1) { - // turn off for testing :) -// return null; + if (!DEBUG_CMIS) return null; + if (!is_array($results)) return null; + ?>