/**
  * Checks if asset file and asset thumbnails (if supported) exist in filesystem.
  *
  * @param lyMediaAsset $asset
  * @param boolean $exist true=must exist, false=must not exist
  * 
  * @return lyMediaTestFunctional current lyMediaTestFunctional instance
  */
 protected function checkFile($asset, $exist = true)
 {
     $fs = new lyMediaFileSystem();
     $file_path = $asset->getPath();
     $this->test()->is($fs->is_file($file_path), $exist, 'File ' . $file_path . ($exist ? ' has ' : ' has not ') . 'been found');
     if ($asset->supportsThumbnails()) {
         $tn = new lyMediaThumbnails($file_path, in_array($asset->getType(), array('image/png', 'image/gif')) ? $asset->getType() : 'image/jpeg', $asset->getThumbnailFile(null));
         foreach ($tn->getThumbnailPaths() as $file_path) {
             $this->test()->is($fs->is_file($file_path), $exist, 'Thumbnail ' . basename($file_path) . ($exist ? ' has ' : ' has not ') . 'been found');
         }
     }
     return $this;
 }
$root = lyMediaFolderTable::getInstance()->createRoot('test_root');
$folder = new lyMediaFolder();
$folder->setName('test');
$folder->create($root);
$base = sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . 'test_root' . DIRECTORY_SEPARATOR;
$t = new lime_test(31, new lime_output_color());
$t->info('Create asset');
$file = dirname(__FILE__) . '/../data/assets/asset1.png';
$a = new lyMediaAsset();
$a->setFolder($root);
$a->setFilename($file);
$a->save();
$a->refresh();
$t->is($a->getFilename(), 'asset1.png', '->getFilename()');
$t->is($a->getType(), 'image/png', '->getType()');
$t->is($a->getPath(), 'test_root/asset1.png', '->getPath()');
$t->ok(file_exists($base . 'asset1.png'), 'File exists');
$t->ok(file_exists($base . 'thumbs/small_asset1.png'), 'Small thumbnail exists');
$t->ok(file_exists($base . 'thumbs/medium_asset1.png'), 'Medium thumbnail exists');
$t->info('Create another asset with the same file');
$a2 = new lyMediaAsset();
$a2->setFolder($root);
$a2->setFilename($file);
$a2->save();
$a2->refresh();
$t->is($a2->getFilename(), 'asset1(1).png', 'Filename is unique');
$t->info('Rename asset: asset1.png > renamed.png');
$a->setFilename('renamed.png');
$a->save();
$a->refresh();
$t->is($a->getPath(), 'test_root/renamed.png', '->getPath()');