public function testCopyAndDeleteDocument() { $documentList = new Document_List(); $documentList->setCondition("`key` like '%_data%' and `type` = 'page'"); $documents = $documentList->load(); $parent = $documents[0]; $this->assertTrue($parent instanceof Document_Page); //remove childs if there are some if ($parent->hasChilds()) { foreach ($parent->getChilds() as $child) { $child->delete(); } } $this->assertFalse($parent->hasChilds()); $service = new Document_Service(User::getById(1)); //copy as child $service->copyAsChild($parent, $parent); $this->assertTrue($parent->hasChilds()); $this->assertTrue(count($parent->getChilds()) == 1); //copy as child no. 2 $service->copyAsChild($parent, $parent); $this->assertTrue($parent->hasChilds()); $this->assertTrue(count($parent->getChilds()) == 2); $childs = $parent->getChilds(); $this->assertTrue(Test_Tool::documentsAreEqual($parent, $childs[0], true)); $this->assertTrue(Test_Tool::documentsAreEqual($parent, $childs[1], true)); //copy recursivley $rootNode = Document::getById(1); $copy = $service->copyRecursive($rootNode, $parent); $this->assertTrue($copy->hasChilds()); $this->assertTrue(count($copy->getChilds()) == 2); $this->assertTrue(Test_Tool::documentsAreEqual($parent, $copy, true)); //create empty document $emptyDoc = Document_Page::create(1, array("userOwner" => 1, "key" => uniqid() . rand(10, 99))); $this->assertFalse(Test_Tool::documentsAreEqual($emptyDoc, $copy, true)); //copy contents $emptyDoc = $service->copyContents($emptyDoc, $copy); $this->assertTrue(Test_Tool::documentsAreEqual($emptyDoc, $copy, true)); //todo copy contents must fail if types differ //delete recusively $shouldBeDeleted[] = $copy->getId(); $childs = $copy->getChilds(); foreach ($childs as $child) { $shouldBeDeleted[] = $child->getId(); } $copy->delete(); foreach ($shouldBeDeleted as $id) { $o = Document::getById($id); $this->assertFalse($o instanceof Document); } }
/** * creates a new document * @return void * @depends testDocumentPageCreate */ public function testDocumentLinkCreate() { $document = $this->createRandomDocument("link"); $this->assertTrue($document->getId() > 0); $document->setKey($document->getKey() . "_data"); $document->setProperties($this->getRandomProperties("document")); $refetch = Document_Link::getById($document->getId()); //$this->assertTrue($refetch instanceof Document_Link); $linkedDoc = $this->createRandomDocument("page"); $data["linktype"] = "internal"; $data["internalType"] = "document"; $data["internal"] = $linkedDoc->getId(); $document->setObject($linkedDoc); $document->setValues($data); $document->save(); $this->assertTrue(Test_Tool::documentsAreEqual($document, $refetch, false)); }
protected function documentTest($subtype) { $client = $this->getSoapClient(); //get an document list with 3 elements $condition = "`type`= '" . $subtype . "'"; $generalCondition = $this->getListCondition(); if (!empty($generalCondition)) { if (!empty($condition)) { $condition .= " AND " . $generalCondition; } else { $condition = $generalCondition; } } $order = ""; $orderKey = ""; $offset = 0; $limit = 3; $groupBy = ""; $wsDocument = $client->getDocumentList($condition, $order, $orderKey, $offset, $limit, $groupBy); $this->assertTrue(is_array($wsDocument) and $wsDocument[0] instanceof Webservice_Data_Document_List_Item); //take the first element and fetch $documentId = $wsDocument[0]->id; $this->assertTrue(is_numeric($documentId)); $wsMethod = "getDocument" . ucfirst($subtype) . "ById"; $wsDocument = $client->{$wsMethod}($documentId); $wsDataClassIn = "Webservice_Data_Document_" . ucfirst($subtype) . "_In"; $wsDataClassOut = "Webservice_Data_Document_" . ucfirst($subtype) . "_Out"; $localClass = "Document_" . ucfirst($subtype); $this->assertTrue($wsDocument instanceof $wsDataClassOut); $document = new $localClass(); $wsDocument->reverseMap($document); //some checks to see if we got a valid document $this->assertTrue($document->getCreationDate() > 0); $this->assertTrue(strlen($document->getPath()) > 0); //copy the document retrieved from ws $new = clone $document; $new->id = null; $new->setKey($document->getKey() . "_phpUnitTestCopy"); $new->setResource(null); //send new document back via ws $apiPage = Webservice_Data_Mapper::map($new, $wsDataClassIn, "in"); $wsMethod = "createDocument" . ucfirst($subtype); $id = $client->{$wsMethod}($apiPage); $this->assertTrue($id > 0); $wsMethod = "getDocument" . ucfirst($subtype) . "ById"; $wsDocument = $client->{$wsMethod}($id); $this->assertTrue($wsDocument instanceof $wsDataClassOut); $refetchDocument = new $localClass(); $wsDocument->reverseMap($refetchDocument); $this->assertTrue($refetchDocument->getId() > 1); $localDocument = $localClass::getById($documentId); Document_Service::loadAllDocumentFields($localDocument); //do that now, later id is null $localDocument->getProperties(); //remove childs, this can not be set through WS $localDocument->childs = null; $this->assertTrue(Test_Tool::documentsAreEqual($localDocument, $refetchDocument, true)); //update document if ($document instanceof Document_PageSnippet) { $refetchDocument->setPublished(!$refetchDocument->getPublished()); } $refetchDocument->setProperty("updateTest", "text", "a update test"); $apiPage = Webservice_Data_Mapper::map($refetchDocument, $wsDataClassIn, "in"); $wsMethod = "updateDocument" . ucfirst($subtype); $success = $client->{$wsMethod}($apiPage); $this->assertTrue($success); $documentId = $refetchDocument->getId(); $localDocument = $localClass::getById($documentId); $localDocument->getProperties(); $localDocument->childs = null; $this->assertTrue(Test_Tool::documentsAreEqual($localDocument, $refetchDocument, true)); //delete our test copy $success = $client->deleteDocument($refetchDocument->getId()); $this->assertTrue($success); }