예제 #1
0
 /**
  * Parent ID of a new object cannot be 0
  */
 public function ___testParentIs0()
 {
     $this->printTestName();
     $savedObject = Test_Tool::createEmptyObject("", false);
     $this->assertTrue($savedObject->getId() == 0);
     $savedObject->setParentId(0);
     try {
         $savedObject->save();
         $this->fail("Expected an exception");
     } catch (Exception $e) {
     }
 }
예제 #2
0
 public function testLazyLoading()
 {
     //reset registry
     Test_Tool::resetRegistry();
     //find an object with data
     $objectList = new Object_List();
     $objectList->setCondition("o_key like '%_data' and o_type = 'object'");
     $objects = $objectList->load();
     $this->assertTrue($objects[0] instanceof Object_Abstract);
     //check for lazy loading elements
     $this->assertTrue($objects[0]->lazyObjects === null);
     $this->assertTrue(is_array($objects[0]->getLazyObjects()));
     $this->assertTrue($objects[0]->lazyMultihref === null);
     $this->assertTrue(is_array($objects[0]->getLazyMultihref()));
     $this->assertTrue($objects[0]->lazyHref === null);
     $this->assertTrue(is_object($objects[0]->getLazyHref()));
 }
예제 #3
0
 public function testObjectConcrete()
 {
     $client = $this->getSoapClient();
     //get an object list with 3 elements
     $condition = "o_type='object'";
     $generalCondition = $this->getListCondition();
     if (!empty($generalCondition)) {
         if (!empty($condition)) {
             $condition .= " AND " . $generalCondition;
         } else {
             $condition = $generalCondition;
         }
     }
     $order = "";
     $orderKey = "";
     $offset = 0;
     $limit = 3;
     $groupBy = "";
     $wsDocument = $client->getObjectList($condition, $order, $orderKey, $offset, $limit, $groupBy);
     $this->assertTrue(is_array($wsDocument) and $wsDocument[0] instanceof Webservice_Data_Object_List_Item);
     //take first element and fetch object
     $id = $wsDocument[0]->id;
     $this->assertTrue(is_numeric($id));
     $wsDocument = $client->getObjectConcreteById($id);
     $this->assertTrue($wsDocument instanceof Webservice_Data_Object_Concrete_Out);
     $className = "Object_" . ucfirst($wsDocument->className);
     $this->assertTrue(class_exists($className));
     $object = new $className();
     $wsDocument->reverseMap($object);
     //some checks to see if we got a valid object
     $this->assertTrue($object->getCreationDate() > 0);
     $this->assertTrue(strlen($object->getPath()) > 0);
     //copy the object retrieved from ws
     $new = clone $object;
     $new->id = null;
     $new->setKey($object->getKey() . "_phpUnitTestCopy");
     $new->setResource(null);
     //send new object back via ws
     $apiObject = Webservice_Data_Mapper::map($new, "Webservice_Data_Object_Concrete_In", "in");
     $id = $client->createObjectConcrete($apiObject);
     $this->assertTrue($id > 0);
     $wsDocument = $client->getObjectConcreteById($id);
     $this->assertTrue($wsDocument instanceof Webservice_Data_Object_Concrete_Out);
     $refetchObject = new $className();
     $wsDocument->reverseMap($refetchObject);
     //make sure we deal with 2 different objects
     $this->assertTrue($id == $refetchObject->getId());
     $this->assertTrue($id != $object->getId());
     //compare original object, and the one we mangled back and forth through the web service
     $localObject = Object_Abstract::getById($object->getId());
     //remove childs, this can not be set through WS
     $localObject->setChilds(null);
     $this->assertTrue(Test_Tool::objectsAreEqual($localObject, $refetchObject, true));
     //update object
     $refetchObject->setProperty("updateTest", "text", "a update test");
     $refetchObject->setInput("my updated test");
     $apiObject = Webservice_Data_Mapper::map($refetchObject, "Webservice_Data_Object_Concrete_In", "in");
     //        Logger::err(print_r($apiObject,true));
     $success = $client->updateObjectConcrete($apiObject);
     Logger::err($client->getLastRequest());
     $this->assertTrue($success);
     $id = $refetchObject->getId();
     Test_Tool::resetRegistry();
     $localObject = Object_Abstract::getById($id);
     $localObject->setChilds(null);
     $this->assertTrue(Test_Tool::objectsAreEqual($localObject, $refetchObject, true));
     //delete our test copy
     $success = $client->deleteObject($refetchObject->getId());
     $this->assertTrue($success);
 }
예제 #4
0
 protected function createObjectConcrete($class, $keySuffix, $minAmountLazyRelations)
 {
     $document = $this->createRandomDocument("page");
     $asset = $this->createRandomAssetImage();
     $object = $this->createRandomObject($class);
     $object->setKey($object->getKey() . $keySuffix);
     $this->assertTrue($object->getId() > 0);
     //$objectFetched = Object_Unittest::getById($object->getId());
     //$this->assertTrue($objectFetched instanceof Object_Unittest);
     $fd = $object->getClass()->getFieldDefinitions();
     $this->setFieldData($object, $fd, $document, $asset, $minAmountLazyRelations);
     //properties
     $object->setProperties($this->getRandomProperties("object"));
     $object->save();
     //new objects must be unpublished
     $refetch = Object_Abstract::getById($object->getId());
     $this->assertFalse($refetch->isPublished());
     $this->assertTrue(Test_Tool::objectsAreEqual($object, $refetch, false));
     return $object;
 }
예제 #5
0
 public function testAssetFile()
 {
     $client = $this->getSoapClient();
     //get an asset list with 3 elements
     $condition = "`type`='image'";
     $generalCondition = $this->getListCondition();
     if (!empty($generalCondition)) {
         if (!empty($condition)) {
             $condition .= " AND " . $generalCondition;
         } else {
             $condition = $generalCondition;
         }
     }
     $order = "";
     $orderKey = "";
     $offset = 0;
     $limit = 3;
     $groupBy = "";
     $wsDocument = $client->getAssetList($condition, $order, $orderKey, $offset, $limit, $groupBy);
     $this->assertTrue(is_array($wsDocument) and $wsDocument[0] instanceof Webservice_Data_Asset_List_Item);
     //take the first element and fetch asset image
     $id = $wsDocument[0]->id;
     $this->assertTrue(is_numeric($id));
     $wsDocument = $client->getAssetFileById($id);
     $this->assertTrue($wsDocument instanceof Webservice_Data_Asset_File_Out);
     $asset = new Asset_Image();
     $wsDocument->reverseMap($asset);
     //some checks to see if we got a valid object
     $this->assertTrue($asset->getCreationDate() > 0);
     $this->assertTrue(strlen($asset->getPath()) > 0);
     //copy the object retrieved from ws
     $new = clone $asset;
     $new->id = null;
     $new->setFilename("phpUnitTestCopy_" . $asset->getFilename());
     $new->setResource(null);
     //send new asset back via ws
     $apiAsset = Webservice_Data_Mapper::map($new, "Webservice_Data_Asset_File_In", "in");
     $id = $client->createAssetFile($apiAsset);
     $this->assertTrue($id > 0);
     $wsDocument = $client->getAssetFileById($id);
     $this->assertTrue($wsDocument instanceof Webservice_Data_Asset_File_Out);
     $refetchAsset = new Asset_Image();
     $wsDocument->reverseMap($refetchAsset);
     //compare to original
     $original = Asset::getById($id);
     $this->assertTrue(Test_Tool::assetsAreEqual($original, $refetchAsset, true));
     //update asset file and set custom settings
     $refetchAsset->setCustomSettings(array("customSettingTest" => "This is a test"));
     $refetchAsset->setData(file_get_contents(TESTS_PATH . "/resources/assets/images/image5.jpg"));
     $apiAsset = Webservice_Data_Mapper::map($refetchAsset, "Webservice_Data_Asset_File_In", "in");
     $success = $client->updateAssetFile($apiAsset);
     $this->assertTrue($success);
     $wsDocument = $client->getAssetFileById($id);
     $this->assertTrue($wsDocument instanceof Webservice_Data_Asset_File_Out);
     $refetchAsset = new Asset_Image();
     $wsDocument->reverseMap($refetchAsset);
     $cs = $refetchAsset->getCustomSettings();
     $this->assertTrue(is_array($cs));
     $this->assertTrue($cs["customSettingTest"] == "This is a test");
     Test_Tool::resetRegistry();
     //compare to original
     $original = Asset::getById($id);
     $this->assertTrue(Test_Tool::assetsAreEqual($original, $refetchAsset, true));
     //delete our test copy
     $success = $client->deleteAsset($refetchAsset->getId());
     $this->assertTrue($success);
 }
예제 #6
0
 public function testCopyAndDeleteAsset()
 {
     $assetList = new Asset_List();
     $assetList->setCondition("`filename` like '%_data%' and `type` = 'folder'");
     $assets = $assetList->load();
     $parent = $assets[0];
     $this->assertTrue($parent instanceof Asset_Folder);
     //remove childs if there are some
     if ($parent->hasChilds()) {
         foreach ($parent->getChilds() as $child) {
             $child->delete();
         }
     }
     $assetList = new Asset_List();
     $assetList->setCondition("`filename` like '%_data%' and `type` != 'folder'");
     $assets = $assetList->load();
     $image = $assets[0];
     $this->assertTrue($image instanceof Asset_Image);
     $this->assertFalse($parent->hasChilds());
     $service = new Asset_Service(User::getById(1));
     //copy as child
     $service->copyAsChild($parent, $parent);
     $this->assertTrue($parent->hasChilds());
     $this->assertTrue(count($parent->getChilds()) == 1);
     $childs = $parent->getChilds();
     $this->assertTrue(Test_Tool::assetsAreEqual($parent, $childs[0], true));
     //copy as child no. 2
     $service->copyAsChild($parent, $image);
     $this->assertTrue($parent->hasChilds());
     $this->assertTrue(count($parent->getChilds()) == 2);
     //copy recursivley
     $rootNode = Asset::getById(1);
     $copy = $service->copyRecursive($rootNode, $parent);
     $this->assertTrue($copy->hasChilds());
     $this->assertTrue(count($copy->getChilds()) == 2);
     $this->assertTrue(Test_Tool::assetsAreEqual($parent, $copy, true));
     //create unequal assets
     $asset1 = Asset_Image::create(1, array("filename" => uniqid() . rand(10, 99) . ".jpg", "data" => file_get_contents(TESTS_PATH . "/resources/assets/images/image1" . ".jpg"), "userOwner" => 1));
     $asset2 = Asset_Image::create(1, array("filename" => uniqid() . rand(10, 99) . ".jpg", "data" => file_get_contents(TESTS_PATH . "/resources/assets/images/image2" . ".jpg"), "userOwner" => 1));
     $this->assertFalse(Test_Tool::assetsAreEqual($asset1, $asset2, true));
     //copy contents
     $asset1 = $service->copyContents($asset1, $asset2);
     $this->assertTrue(Test_Tool::assetsAreEqual($asset1, $asset2, 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 = Asset::getById($id);
         $this->assertFalse($o instanceof Asset);
     }
 }
예제 #7
0
 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);
 }