$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();
 $asset1->delete();
 $t->ok(!is_file($old_path), 'delete() physically removes asset');
 $t->ok(!is_file($old_thumb_path), 'delete() physically removes thumbnail');
 $null = sfAssetTable::getInstance()->find($old_id);
 $t->ok(!$null, 'delete() removes asset from DB');
Пример #2
0
    $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');
    $null = sfAssetPeer::retrieveByPk($old_id);
    $t->ok(!$null, 'delete() removes asset from DB');
} catch (Exception $e) {
    // do nothing