示例#1
0
 /**
  * creates an asset folder "unittestassets" to hold assets used later in tests
  * @return void
  */
 public function testAssetFolderCreate()
 {
     $asset = Asset_Folder::create(1, array("filename" => uniqid() . "_data", "type" => "folder", "userOwner" => 1));
     $this->assertTrue($asset->getId() > 0);
     //properties
     $asset->setProperties($this->getRandomProperties("asset"));
     $asset->save();
     $refetch = Asset_Folder::getById($asset->getId());
     $this->assertTrue(Test_Tool::assetsAreEqual($asset, $refetch, false));
 }
示例#2
0
 public function testAssetFolder()
 {
     $client = $this->getSoapClient();
     //get an asset list with 3 elements
     $condition = "`type`='folder'";
     $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 second element, first will be home
     $id = $wsDocument[0]->id;
     $this->assertTrue(is_numeric($id));
     $wsDocument = $client->getAssetFolderById($id);
     $this->assertTrue($wsDocument instanceof Webservice_Data_Asset_Folder_Out);
     $asset = new Asset_Folder();
     $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($asset->getFilename() . "_phpUnitTestCopy");
     $new->setResource(null);
     //send new asset back via ws
     $apiAsset = Webservice_Data_Mapper::map($new, "Webservice_Data_Asset_Folder_In", "in");
     $id = $client->createAssetFolder($apiAsset);
     $this->assertTrue($id > 0);
     $wsDocument = $client->getAssetFolderById($id);
     $this->assertTrue($wsDocument instanceof Webservice_Data_Asset_Folder_Out);
     $refetchAsset = new Asset_Folder();
     $wsDocument->reverseMap($refetchAsset);
     //compare to original
     $original = Asset::getById($id);
     $original->getProperties();
     $this->assertTrue(Test_Tool::assetsAreEqual($original, $refetchAsset, true));
     //update asset file and set custom settings
     $refetchAsset->setCustomSettings(array("customSettingTest" => "This is a test"));
     $apiAsset = Webservice_Data_Mapper::map($refetchAsset, "Webservice_Data_Asset_Folder_In", "in");
     $success = $client->updateAssetFolder($apiAsset);
     $this->assertTrue($success);
     $wsDocument = $client->getAssetFolderById($id);
     $this->assertTrue($wsDocument instanceof Webservice_Data_Asset_Folder_Out);
     $refetchAsset = new Asset_Folder();
     $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_Folder::getById($id);
     $this->assertTrue(Test_Tool::assetsAreEqual($original, $refetchAsset, true));
     //delete our test copy
     $success = $client->deleteAsset($refetchAsset->getId());
     $this->assertTrue($success);
 }
示例#3
0
 /**
  * @param string base64
  * @return Asset
  */
 public function convertToAsset($imgstr)
 {
     $uploadDir = PIMCORE_TMP_DIRECTORY . '/asset-temporary/';
     $content = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $imgstr));
     $name = uniqid() . '.png';
     $file = $uploadDir . $name;
     $success = file_put_contents($file, $content);
     if ($success) {
         $parentAsset = Asset_Folder::getById(71);
         $asset = Asset::create($parentAsset->getId(), array("filename" => $name, "data" => file_get_contents($file)));
         return $asset;
     } else {
         return false;
     }
 }