Beispiel #1
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);
 }
Beispiel #2
0
 /**
  * adds an asset image to the unittestassets folder
  * @depends  testAssetFolderCreate
  */
 public function testAssetImageCreate()
 {
     $asset = $this->createRandomAssetImage();
     $this->assertTrue($asset->getId() > 0);
     $asset->setFilename($asset->getKey() . "_data");
     $asset->setProperties($this->getRandomProperties("asset"));
     $asset->save();
     $refetch = Asset::getById($asset->getId());
     //$this->assertTrue($refetch instanceof Asset_Image);
     $this->assertTrue(Test_Tool::assetsAreEqual($asset, $refetch, false));
 }
Beispiel #3
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);
     }
 }