Example #1
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()));
 }
Example #2
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);
 }
Example #3
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);
 }