$sfAssetFolder->setName('Test_Directory'); $sfAssetFolder->insertAsFirstChildOf($root); $sfAssetFolder->save(); $t->is($sfAssetFolder->getName(), 'Test_Directory', 'getName() returns the folder name'); $t->diag('sfAssetFolder::getRelativePath()'); $t->is($sfAssetFolder->getRelativePath(), $root->getRelativePath() . '/' . $sfAssetFolder->getName(), 'getRelativePath() returns the folder relative path, including its own name'); # $sfAssetFolder2 is /root/Test_Directory/Test_Sub-directory $sfAssetFolder2 = new sfAssetFolder(); $sfAssetFolder2->setName('Test_Sub-directory'); $sfAssetFolder2->insertAsFirstChildOf($sfAssetFolder); $sfAssetFolder2->save(); $t->is($sfAssetFolder2->getRelativePath(), $sfAssetFolder->getRelativePath() . '/' . $sfAssetFolder2->getName(), 'getRelativePath() returns the folder relative path, including its parent name'); $id2 = $sfAssetFolder2->getId(); # $sfAssetFolder3 is /root/Test_Directory/Test_Sub-directory/Test_Sub-sub-directory $sfAssetFolder3 = new sfAssetFolder(); $sfAssetFolder3->insertAsFirstChildOf($sfAssetFolder2); $sfAssetFolder3->setName('Test_Sub-sub-directory'); $sfAssetFolder3->save(); $t->is($sfAssetFolder3->getRelativePath(), $sfAssetFolder2->getRelativePath() . '/' . $sfAssetFolder3->getName(), 'getRelativePath() returns the folder relative path, including its ancestors names'); $id3 = $sfAssetFolder3->getId(); # $sfAsset is /root/Test_Directory/Test_Sub-directory/raikkonen.jpg $assets_path = dirname(__FILE__) . '/../assets/'; $test_asset = $assets_path . 'raikkonen.jpg'; $sfAsset = new sfAsset(); $sfAsset->setFolder($sfAssetFolder2); $sfAsset->create($test_asset, false); $sfAsset->save(); $sf_asset_id = $sfAsset->getId(); # $sfAsset2 is /root/Test_Directory/Test_Sub-directory/Test_Sub-sub-directory/toto $sfAsset2 = new sfAsset(); $sfAsset2->setFolder($sfAssetFolder3);
$sfAsset->setFilename('filename.jpg'); $t->diag('sfAsset::getRelativePath()'); $t->is($sfAsset->getRelativePath(), sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'filename.jpg', 'getRelativePath() returns the path relative to the media directory'); $t->diag('sfAsset::getFullPath()'); $t->is($sfAsset->getFullPath(), sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'filename.jpg', 'getFullPath() returns the complete asset path on the disk'); $t->is($sfAsset->getFullPath('small'), sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'thumbnail/small_filename.jpg', 'getFullPath(\'small\') returns the complete small thumbnail path on the disk'); $t->is($sfAsset->getFullPath('large'), sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'thumbnail/large_filename.jpg', 'getFullPath(\'large\') returns the complete large thumbnail path on the disk'); $t->diag('sfAsset::getUrl()'); $t->is($sfAsset->getUrl(), DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'filename.jpg', 'getUrl() returns the asset URL'); $t->is($sfAsset->getUrl('small'), DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'thumbnail/small_filename.jpg', 'getUrl(\'small\') returns the small thumbnail url'); $t->is($sfAsset->getUrl('large'), DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'thumbnail/large_filename.jpg', 'getUrl(\'large\') returns the large thumbnail url'); $t->diag('sfAsset::create()'); $assets_path = dirname(__FILE__) . '/../assets/'; $test_asset = $assets_path . 'raikkonen.jpg'; $folder1 = new sfAssetFolder(); $folder1->insertAsFirstChildOf($root); $folder1->setName('Test_Directory'); $folder1->save(); $asset1 = new sfAsset(); $asset1->setsfAssetFolder($folder1); $asset1->create($test_asset, false); $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() . DIRECTORY_SEPARATOR . $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');