function testObjectService() { $ObjectService = new KTObjectService($this->ktapi); // $ObjectService->startSession(KT_TEST_USER, KT_TEST_PASS); // set up the folder/doc tree structure with which we will be testing $this->createFolderDocStructure(); $RepositoryService = new KTRepositoryService(); $response = $RepositoryService->getRepositories(); $this->assertEqual($response['status_code'], 0); $this->assertNotNull($response['results'][0]); // 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 = $ObjectService->getProperties($repositoryId, $objectId, false, false); $this->assertNotNull($properties['results']); // echo '<pre>'.print_r($properties['results'], true).'</pre>'; // // test printout $this->printTable($properties['results'][0], 'Properties for Folder Object ' . $objectId . ' (getProperties())'); $objectId = 'D' . $this->docs[0]->get_documentid(); $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()), 'F1'); $this->assertNotNull($created['results']); if (!is_null($created['results'])) { $folderId = $created['results']; // check that folder object actually exists $properties = $ObjectService->getProperties($repositoryId, $folderId, false, false); $this->assertNotNull($properties['results']); // test printout $this->printTable($properties['results'][0], 'Properties for CMIS Created Folder Object ' . $folderId . ' (getProperties())'); // delete $this->ktapi->delete_folder(CMISUtil::decodeObjectId($folderId), 'Testing API', KT_TEST_USER, KT_TEST_PASS); } // TEST 3 // test creation of document $folderId = 'F' . $this->folders[0]; // $folderId = 'F1'; $properties = array('name' => 'Test CMIS Document 1', 'title' => 'test_cmis_doc_' . mt_rand() . '.txt'); $contentStream = base64_encode('Some arbitrary text content'); $created = $ObjectService->createDocument($repositoryId, 'Document', $properties, $folderId, $contentStream); $this->assertNotNull($created['results']); // echo '<pre>'.print_r($created, true).'</pre>'; if (!is_null($created['results'])) { $documentId = $created['results']; // check that document object actually exists $properties = $ObjectService->getProperties($repositoryId, $documentId, false, false); $this->assertNotNull($properties['results']); // test printout $this->printTable($properties['results'][0], 'Properties for CMIS Created Document Object ' . $documentId . ' (getProperties())'); } // // TEST 5 // // test updating content stream for existing document // $contentStream = base64_encode('Some updated text content for the content stream'); // $updated = $ObjectService->setContentStream($repositoryId, $documentId, true, $contentStream); // // $this->assertNotNull($updated['results']); // //// echo '<pre>'.print_r($created, true).'</pre>'; // // if (!is_null($updated['results'])) // { //// $documentId = $updated['results']; // // // TODO test getContentStream here when we have it // // } // delete created document $this->ktapi->delete_document(CMISUtil::decodeObjectId($documentId), 'Testing API', false); // TEST $folderId = 'F' . $this->folders[0]; $objectId = 'D' . $this->docs[0]->get_documentid(); // test attempted delete via single object delete on folder which contains content - should fail $response = $ObjectService->deleteObject($repositoryId, $folderId); $this->assertEqual($response['status_code'], 1); $this->assertNotNull($response['message']); // test deletion of folder tree - should succeed unless there are non-deletable objects (checked out) (not testing latter) $response = $ObjectService->deleteTree($repositoryId, $folderId); $this->assertEqual($response['status_code'], 0); $this->assertNotNull($response['results']); // TODO test deleteTree with checkedout documents // test attempted delete of document with single version via single object delete. // should succeed unless there is a valid reason (checked out/immutable) (not testing latter) // TODO test failure on attempt to delete document with more than one version $response = $ObjectService->deleteObject($repositoryId, $objectId); $this->assertEqual($response['status_code'], 0); $this->assertNotNull($response['results']); // TEST // TODO test failed moves (checked out, etc) // folder to move - folder 2 $folderId = 'F' . $this->folders[1]; // document to move - document 3 $objectId = 'D' . $this->docs[1]->get_documentid(); // target folder for all moves $root = $this->ktapi->get_root_folder(); $targetFolderId = 'F' . $root->get_folderid(); // test moving of object (document) $response = $ObjectService->moveObject($repositoryId, $objectId, null, $targetFolderId); $this->assertEqual($response['status_code'], 0); $this->assertNotNull($response['results']); // test moving of object (folder) $response = $ObjectService->moveObject($repositoryId, $folderId, null, $targetFolderId); $this->assertEqual($response['status_code'], 0); $this->assertNotNull($response['results']); // TEST // TODO test failure conditions // TODO test fetching of content stream $response = $ObjectService->getContentStream($repositoryId, $objectId); $this->assertEqual($response['status_code'], 0); $this->assertNotNull($response['results']); // TEST // TODO test setContentStream? unused at the moment // tear down the folder/doc tree structure with which we were testing $this->cleanupFolderDocStructure(); // test printout if (DEBUG_CMIS) { echo '<div> </div>'; } }
/** * Moves a fileable object from one folder to another. * * @param object $repositoryId * @param object $objectId * @param object $changeToken [optional] * @param object $targetFolderId * @param object $sourceFolderId [optional] */ public function moveObject($repositoryId, $objectId, $changeToken = '', $targetFolderId, $sourceFolderId = null) { $result = parent::moveObject($repositoryId, $objectId, $changeToken, $targetFolderId, $sourceFolderId); if ($result['status_code'] == 0) { return $result['results']; } else { return new PEAR_Error($result['message']); } }