$sfAsset->setsfAssetFolder($sfAssetFolder2); $sfAsset->create($test_asset, false); $sfAsset->save(); $t->ok(is_file($sfAsset->getFullPath()), 'asset found'); $sf_asset_id = $sfAsset->getId(); $sfAssetFolder3 = new sfAssetFolder(); $sfAssetFolder3->insertAsFirstChildOf($sfAssetFolder2); $sfAssetFolder3->setName('Test_Sub-sub-directory'); $sfAssetFolder3->save(); $t->is($sfAssetFolder3->getRelativePath(), $sfAssetFolder2->getRelativePath() . '/' . $sfAssetFolder3->getName(), 'getRelativePath() is updated on save for subfolders'); $sfAsset2 = new sfAsset(); $sfAsset2->setsfAssetFolder($sfAssetFolder3); $sfAsset2->setFilename('toto'); $sfAsset2->create($test_asset, false); $sfAsset2->save(); $t->ok(is_file($sfAsset2->getFullPath()), 'asset2 found'); $sf_asset2_id = $sfAsset2->getId(); $id3 = $sfAssetFolder3->getId(); $sfAssetFolder2->move($root); $sfAssetFolder3 = sfAssetFolderPeer::retrieveByPk($id3); $t->is($sfAssetFolder2->getParent()->getId(), $root->getId(), 'move() gives the correct parent'); $t->is($sfAssetFolder3->getParent()->getParent()->getId(), $root->getId(), 'move() changes descendants grandparents'); $t->is($sfAssetFolder2->getRelativePath(), $root->getRelativePath() . '/' . $sfAssetFolder2->getName(), 'move() changes descendants relative paths'); $t->is($sfAssetFolder3->getRelativePath(), $sfAssetFolder2->getRelativePath() . '/' . $sfAssetFolder3->getName(), 'move() changes descendants relative paths'); $sfAsset = sfAssetPeer::retrieveByPk($sf_asset_id); $sfAsset2 = sfAssetPeer::retrieveByPk($sf_asset2_id); $t->ok(is_file($sfAsset->getFullPath()), 'base asset of moved folder found'); $t->ok(is_file($sfAsset2->getFullPath()), 'deep asset of moved folder found'); } catch (Exception $e) { echo $e->getMessage(); }
$t->diag('sfAsset::create()'); $assets_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR; $test_asset = $assets_path . 'raikkonen.jpg'; $folder1 = new sfAssetFolder(); $folder1->getNode()->insertAsFirstChildOf($root); $folder1->setName('Test_Directory'); $folder1->save(); $asset1 = new sfAsset(); $asset1->setFolder($folder1); $asset1->create($test_asset, false); $asset_file_size = (int) (filesize($test_asset) / 1024); $t->is($asset1->getFilename(), 'raikkonen.jpg', 'create() sets the object filename according to the given asset'); $t->is($asset1->getFilesize(), 18, 'create() sets the object filesize according to the given asset'); $t->ok($asset1->isImage(), 'create() sets the object type according to the given asset'); $t->is($asset1->getUrl(), $folder1->getUrl() . '/' . $asset1->getFilename(), 'create() sets the object url according to the given asset and folder object'); $t->ok(is_file($asset1->getFullPath()), 'create() physically copies asset'); $t->ok(is_file($asset1->getFullPath('large')), 'create() physically creates thumbnail'); $t->diag('sfAsset::move()'); $old_path = $asset1->getFullPath(); $old_thumb_path = $asset1->getFullPath('large'); $asset1->move($root, 'raikkonen2.jpg'); $t->is($asset1->getFilename(), 'raikkonen2.jpg', 'move() changes filename'); $t->is($asset1->getUrl(), $root->getUrl() . '/' . $asset1->getFilename(), 'move() changes the object url according to the new folder'); $t->ok(is_file($asset1->getFullPath()), 'move() physically moves asset to the new location'); $t->ok(!is_file($old_path), 'move() physically removes asset from the previous location'); $t->ok(is_file($asset1->getFullPath('large')), 'move() physically moves thumbnail to the new location'); $t->ok(!is_file($old_thumb_path), 'move() physically removes thumbnail from the previous location'); $t->diag('sfAsset::delete()'); $old_path = $asset1->getFullPath(); $old_thumb_path = $asset1->getFullPath('large'); $old_id = $asset1->getId();
// sfConfig::set('sf_web_dir', 'var/www/myproject'); sfConfig::set('app_sfAssetsLibrary_upload_dir', 'medias'); $t->is($sfAsset->getFullPath(), sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media') . DIRECTORY_SEPARATOR . 'filename.jpg', 'getFullPath() gives complete path'); $t->is($sfAsset->getFullPath('large'), sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media') . DIRECTORY_SEPARATOR . 'thumbnail/large_filename.jpg', 'getFullPath() gives correct thumbnail path'); $t->is($sfAsset->getUrl(), DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media') . DIRECTORY_SEPARATOR . 'filename.jpg', 'getUrl() gives correct url'); $t->is($sfAsset->getUrl('small'), DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media') . DIRECTORY_SEPARATOR . 'thumbnail/small_filename.jpg', 'getUrl() gives correctthumbnail url'); $assets_path = dirname(__FILE__) . '/../assets/'; $test_asset = $assets_path . 'raikkonen.jpg'; $t->ok(is_file($test_asset), 'test asset found'); $sfAsset = new sfAsset(); $sfAsset->setsfAssetFolder(sfAssetFolderPeer::getRoot()); $sfAsset->create($test_asset, false); $t->is($sfAsset->getFilename(), 'raikkonen.jpg', 'create() gives correct filename'); $t->is($sfAsset->getFilesize(), 18, 'create() gives correct size'); $t->ok($sfAsset->isImage(), 'create() gives correct type'); $t->ok(is_file($sfAsset->getFullPath()), 'create() physically copies asset'); $t->ok(is_file($sfAsset->getFullPath('large')), 'create() physically creates thumbnail'); $old_path = $sfAsset->getFullPath(); $old_thumb_path = $sfAsset->getFullPath('large'); $sfAsset->move(sfAssetFolderPeer::getRoot(), 'raikkonen2.jpg'); $t->is($sfAsset->getFilename(), 'raikkonen2.jpg', 'move() changes filename'); $t->ok(is_file($sfAsset->getFullPath()), 'move() physically moves asset'); $t->ok(!is_file($old_path), 'move() physically moves asset'); $t->ok(is_file($sfAsset->getFullPath('large')), 'move() physically moves thumbnail'); $t->ok(!is_file($old_thumb_path), 'move() physically moves thumbnail'); $old_path = $sfAsset->getFullPath(); $old_thumb_path = $sfAsset->getFullPath('large'); $old_id = $sfAsset->getId(); $sfAsset->delete(); $t->ok(!is_file($old_path), 'delete() physically removes asset'); $t->ok(!is_file($old_thumb_path), 'delete() physically removes thumbnail');