public function configure()
 {
     // remove unneeded fields
     unset($this['folder_id'], $this['filename'], $this['description'], $this['author'], $this['copyright'], $this['type'], $this['filesize'], $this['created_at'], $this['updated_at']);
     // add parent folder select
     $this->widgetSchema['parent_folder'] = new sfWidgetFormDoctrineChoice(array('model' => 'sfAssetFolder', 'query' => sfAssetFolderTable::getInstance()->getAllPathsButOneCriteria($this->getObject()->getFolder())));
     $this->validatorSchema['parent_folder'] = new sfValidatorDoctrineChoice(array('model' => 'sfAssetFolder', 'column' => 'id', 'required' => true));
     // avoid id conflict for id
     $this->widgetSchema['id']->setIdFormat('move_%s');
 }
 public function configure()
 {
     // remove unneeded fields
     unset($this['name'], $this['lft'], $this['rgt'], $this['level'], $this['relative_path'], $this['created_at'], $this['updated_at']);
     // add parent folder select
     $this->widgetSchema['parent_folder'] = new sfWidgetFormDoctrineChoice(array('model' => 'sfAssetFolder', 'query' => sfAssetFolderTable::getInstance()->getAllNonDescendantsPathsCriteria($this->getObject())));
     $this->validatorSchema['parent_folder'] = new sfValidatorDoctrineChoice(array('model' => 'sfAssetFolder', 'column' => 'id', 'required' => true));
     // avoid id conflict for id
     $this->widgetSchema['id']->setIdFormat('move_%s');
 }
 /**
  * save
  * @param Doctrine_connection $con
  */
 protected function doSave($con = null)
 {
     if (null === $con) {
         $con = $this->getConnection();
     }
     $this->updateObject();
     $parent = sfAssetFolderTable::getInstance()->find($this->getValue('parent_folder'));
     $this->getObject()->getNode()->insertAsLastChildOf($parent);
     $this->getObject()->save($con);
     // embedded forms
     $this->saveEmbeddedForms($con);
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     if (sfAssetFolderTable::getInstance()->getRoot()) {
         throw new sfException('The asset library already has a root');
     }
     $this->logSection('asset', sprintf('Creating root node at %s...', sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media')), null, 'COMMENT');
     $folder = new sfAssetFolder();
     $folder->setName(sfConfig::get('app_sfAssetsLibrary_upload_dir', 'media'));
     $tree = sfAssetFolderTable::getInstance()->getTree()->createRoot($folder);
     $folder->save();
     $this->logSection('asset', 'Root Node Created', null, 'INFO');
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     if (!($rootFolder = sfAssetFolderTable::getInstance()->getRoot())) {
         $task = new sfAssetCreateRootTask($this->dispatcher, $this->formatter);
         $task->setCommandApplication($this->commandApplication);
         $taskOption = array('--env=' . $options['env'], '--connection=' . $options['connection']);
         if ($options['application']) {
             $taskOption[] = '--application=' . $options['application'];
         }
         $ret = $task->run(array(), $taskOption);
         $rootFolder = sfAssetFolderTable::getInstance()->getRoot();
     }
     $this->logSection('asset', sprintf('Comparing files from %s with assets stored in the database...', $arguments['dirname']), null, 'COMMENT');
     try {
         $rootFolder->synchronizeWith($arguments['dirname'], $options['verbose'], $options['removeOrphanAssets'], $options['removeOrphanFolders']);
     } catch (sfAssetException $e) {
         throw new sfException(strtr($e->getMessage(), $e->getMessageParams()));
     }
     $this->logSection('asset', 'Synchronization complete', null, 'INFO');
 }
<?php

$app = 'frontend';
include dirname(__FILE__) . '/../../../../test/bootstrap/functional.php';
include $configuration->getSymfonyLibDir() . '/vendor/lime/lime.php';
$databaseManager = new sfDatabaseManager($configuration);
$con = Doctrine::getConnectionByTableName('sfAsset');
$con->beginTransaction();
try {
    // prepare test environment
    sfAssetFolderTable::getInstance()->createQuery()->delete()->execute();
    sfAssetTable::getInstance()->createQuery()->delete()->execute();
    sfConfig::set('app_sfAssetsLibrary_upload_dir', 'mediaTEST');
    $root = new sfAssetFolder();
    $root->setName(sfConfig::get('app_sfAssetsLibrary_upload_dir'));
    $tree = sfAssetFolderTable::getInstance()->getTree();
    $tree->createRoot($root);
    $root->save();
    // run the tests
    $t = new lime_test(23, array('options' => new lime_output_color(), 'error_reporting' => true));
    $t->diag('sfAsset');
    $sfAsset = new sfAsset();
    $sfAsset->setFolder($root);
    $t->isa_ok($sfAsset->getFolder(), 'sfAssetFolder', 'sfAsset can have root as folder');
    $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' . DIRECTORY_SEPARATOR . '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' . DIRECTORY_SEPARATOR . 'large_filename.jpg', 'getFullPath(\'large\') returns the complete large thumbnail path on the disk');
 /**
  * move asset
  * @param sfWebRequest $request
  */
 public function executeMoveAsset(sfWebRequest $request)
 {
     $this->forward404Unless($request->getMethod() == sfRequest::POST, 'method not allowed');
     $sfAsset = $request->getParameter('sf_asset');
     $asset = sfAssetTable::getInstance()->find($sfAsset['id']);
     $this->forward404Unless($asset, 'asset not found');
     $destFolder = sfAssetFolderTable::getInstance()->find($sfAsset['parent_folder']);
     $this->forward404Unless($destFolder, 'destination folder not found');
     $this->form = new sfAssetMoveForm($asset);
     $this->form->bind($request->getParameter($this->form->getName()));
     if ($this->form->isValid() && $destFolder->getId() != $asset->getFolderId()) {
         try {
             $asset->move($destFolder);
             $asset->save();
             $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $asset)));
             $this->getUser()->setFlash('notice', 'The file has been moved');
         } catch (sfAssetException $e) {
             $this->getUser()->setFlash('warning_message', $e->getMessage());
             $this->getUser()->setFlash('warning_params', $e->getMessageParams());
         }
     } else {
         $this->getUser()->setFlash('warning', 'The asset has not been moved.');
     }
     return $this->redirect('@sf_asset_library_edit?id=' . $asset->getId());
 }
include dirname(__FILE__) . '/../../../../test/bootstrap/functional.php';
include $configuration->getSymfonyLibDir() . '/vendor/lime/lime.php';
$databaseManager = new sfDatabaseManager($configuration);
$con = Doctrine::getConnectionByTableName('sfAsset');
$con->beginTransaction();
try {
    // prepare test environment
    sfAssetFolderTable::getInstance()->createQuery()->delete()->execute();
    sfAssetTable::getInstance()->createQuery()->delete()->execute();
    sfConfig::set('app_sfAssetsLibrary_upload_dir', 'mediaTEST');
    $f = new sfAssetFolder();
    $f->setName(sfConfig::get('app_sfAssetsLibrary_upload_dir'));
    $tree = sfAssetFolderTable::getInstance()->getTree();
    $tree->createRoot($f);
    $f->save();
    $t = new lime_test(5, array('options' => new lime_output_color(), 'error_reporting' => true));
    $t->diag('sfAssetPeer');
    $t->is(sfAssetTable::getInstance()->retrieveFromUrl(sfAssetFolderTable::getInstance()->getRoot()->getRelativePath() . '/filename.jpg'), null, 'sfAssetPeer::retrieveFromUrl() returns null when a URL is not found');
    $t->is(sfAssetTable::getInstance()->exists(sfAssetFolderTable::getInstance()->getRoot()->getId(), 'filename.jpg'), false, 'sfAssetPeer::exists() returns false when an asset is not found');
    $sfAsset = new sfAsset();
    $sfAsset->setFolder(sfAssetFolderTable::getInstance()->getRoot());
    $sfAsset->setFilename('filename.jpg');
    $sfAsset->save();
    $t->is(sfAssetTable::getInstance()->retrieveFromUrl(sfAssetFolderTable::getInstance()->getRoot()->getRelativePath() . '/filename.jpg')->getId(), $sfAsset->getId(), 'sfAssetPeer::retrieveFromUrl() finds an asset from its URL');
    $t->is(sfAssetTable::getInstance()->retrieveFromUrl($sfAsset->getUrl())->getId(), $sfAsset->getId(), 'sfAssetPeer::retrieveFromUrl() finds an asset from the result of `getUrl()`');
    $t->is(sfAssetTable::getInstance()->exists(sfAssetFolderTable::getInstance()->getRoot()->getId(), 'filename.jpg'), true, 'sfAssetPeer::exists() returns true when an asset is found');
} catch (Exception $e) {
    echo $e->getMessage();
}
// reset DB
$con->rollBack();
    $tree = sfAssetFolderTable::getInstance()->getTree();
    $tree->createRoot($f);
    $f->save();
    // run the test
    $t = new lime_test(13, array('options' => new lime_output_color(), 'error_reporting' => true));
    $t->diag('sfAssetFolderTable');
    $sfAssetFolder = sfAssetFolderTable::getInstance()->retrieveByPath(sfConfig::get('app_sfAssetsLibrary_upload_dir', 'mediaTEST'));
    $t->ok($sfAssetFolder->isRoot(), 'retrieveByPath() retrieves root from app_sfAssetsLibrary_upload_dir string: ' . sfConfig::get('app_sfAssetsLibrary_upload_dir', 'mediaTEST'));
    $sfAssetFolder = sfAssetFolderTable::getInstance()->retrieveByPath();
    $t->ok($sfAssetFolder->isRoot(), 'retrieveByPath() retrieves root from empty string');
    $sfAssetFolder = sfAssetFolderTable::getInstance()->createFromPath(sfConfig::get('app_sfAssetsLibrary_upload_dir', 'mediaTEST') . DIRECTORY_SEPARATOR . 'simple');
    $t->isa_ok($sfAssetFolder, 'sfAssetFolder', 'createFromPath() creates a sfAssetFolder from simple string');
    $t->isa_ok($sfAssetFolder->getParent(), 'sfAssetFolder', 'createFromPath() from simple string has a parent');
    $t->ok($sfAssetFolder->getParent()->isRoot(), 'createFromPath() creates a root child from simple string');
    $sfAssetFolder2 = sfAssetFolderTable::getInstance()->createFromPath(sfConfig::get('app_sfAssetsLibrary_upload_dir', 'mediaTEST') . DIRECTORY_SEPARATOR . 'simple' . DIRECTORY_SEPARATOR . 'subfolder');
    $t->isa_ok($sfAssetFolder2, 'sfAssetFolder', 'createFromPath() creates a sfAssetFolder from simple string');
    $t->is($sfAssetFolder2->getParent()->getId(), $sfAssetFolder->getId(), 'createFromPath() from simple string parent is correct');
    $sfAssetFolder = sfAssetFolderTable::getInstance()->createFromPath(sfConfig::get('app_sfAssetsLibrary_upload_dir', 'mediaTEST') . DIRECTORY_SEPARATOR . 'second' . DIRECTORY_SEPARATOR . 'subfolder');
    $t->ok($sfAssetFolder instanceof sfAssetFolder, 'createFromPath() creates a sfAssetFolder from simple string');
    $t->ok($sfAssetFolder->getParent() instanceof sfAssetFolder, 'createFromPath() from composed string has a parent');
    $t->ok($sfAssetFolder->getParent()->getParent()->isRoot(), 'createFromPath() creates a root child from composed string');
    $sfAssetFolder = sfAssetFolderTable::getInstance()->createFromPath('third' . DIRECTORY_SEPARATOR . 'subfolder');
    $t->ok($sfAssetFolder instanceof sfAssetFolder, 'createFromPath() creates a sfAssetFolder from simple string');
    $t->ok($sfAssetFolder->getParent() instanceof sfAssetFolder, 'createFromPath() from composed string has a parent');
    $t->ok($sfAssetFolder->getParent()->getParent()->isRoot(), 'createFromPath() creates a root child from composed string');
} catch (Exception $e) {
    // do nothing
    echo $e->getMessage() . PHP_EOL;
}
// reset DB
$con->rollBack();
 /**
  * get files of folder, sorted
  * @param  array  $dirs
  * @param  string $sortOrder
  * @return array
  */
 public function getSortedFiles($dirs, $sortOrder)
 {
     $query = sfAssetTable::getInstance()->createQuery();
     $query->where('folder_id = ?', $this->getId());
     switch ($sortOrder) {
         case 'date':
             $dirs = sfAssetFolderTable::getInstance()->sortByDate($dirs);
             $query->orderBy('created_at DESC');
             //        $c->addDescendingOrderByColumn(sfAssetPeer::CREATED_AT);
             break;
         default:
             $dirs = sfAssetFolderTable::getInstance()->sortByName($dirs);
             $query->orderBy('filename ASC');
             //        $c->addAscendingOrderByColumn(sfAssetPeer::FILENAME);
     }
     return $query->execute();
 }
    $t->diag('sfAssetFolder::move()');
    # move $sfAssetFolder2 from /root/Test_Directory/Test_Sub-directory to /root/Test_Sub-directory
    $sfAssetFolder2->move($root);
    $sfAssetFolder2->save();
    # So now we have:
    # root/
    #   Test_Directory/             sfAssetFolder
    #   Test_Sub-directory/         sfAssetFolder2
    #     Test_Sub-sub-directory/   sfAssetFolder3
    #       toto
    #     raikkonen.jpg
    // Bug in Propel instance pooling + NestedSets...
    //  sfAssetFolderPeer::clearInstancePool(); clear()
    $root = sfAssetFolderTable::getInstance()->find($rootId);
    $sfAssetFolder2 = sfAssetFolderTable::getInstance()->find($id2);
    $sfAssetFolder3 = sfAssetFolderTable::getInstance()->find($id3);
    $t->is($sfAssetFolder2->getParent()->getId(), $root->getId(), 'move() gives the correct parent');
    $t->is($sfAssetFolder3->getParent()->getParent()->getId(), $root->getId(), 'move() also moves children');
    $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');
    //  sfAssetPeer::clearInstancePool();
    $sfAsset = sfAssetTable::getInstance()->find($sf_asset_id);
    $sfAsset2 = sfAssetTable::getInstance()->find($sf_asset2_id);
    $t->ok(is_file($sfAsset->getFullPath()), 'move() also moves assets under the moved folder');
    $t->ok(is_file($sfAsset2->getFullPath()), 'move() also moves assets under the moved folder');
} catch (Exception $e) {
    echo 'errore: ' . $e->getMessage() . PHP_EOL;
    echo $e->getTraceAsString() . PHP_EOL;
}
// reset DB
$con->rollBack();
<?php

include dirname(__FILE__) . '/../bootstrap/functional.php';
$subdir1 = sfAssetFolderTable::getInstance()->retrieveByPath('TESTsubdir1', '/');
$subdir2 = sfAssetFolderTable::getInstance()->retrieveByPath('TESTsubdir2', '/');
if (!$subdir1) {
    include dirname(__FILE__) . '/../../../../test/bootstrap/unit.php';
    $t = new lime_test(1, array('options' => new lime_output_color(), 'error_reporting' => true));
    $t->fail('subdir1 doesn\'t exist.');
    exit;
}
if (!$subdir2) {
    include dirname(__FILE__) . '/../../../../test/bootstrap/unit.php';
    $t = new lime_test(1, array('options' => new lime_output_color(), 'error_reporting' => true));
    $t->fail('subdir2 doesn\'t exist.');
    exit;
}
$browser = new sfTestFunctional(new sfBrowser());
$browser->setTester('doctrine', 'sfTesterDoctrine');
$browser->info('assets list')->get('/sfAsset/dir/media')->with('request')->begin()->isParameter('module', 'sfAsset')->isParameter('action', 'list')->end()->with('response')->begin()->isStatusCode(200)->checkElement('div#sf_asset_bar p:first-child', '/media/')->checkElement('div#sf_asset_bar p:nth-child(2)', '/2 subfolders/')->checkElement('div#sf_asset_bar p:nth-child(3)', '/3 files, 3 KiB/')->checkElement('div#sf_asset_container div.assetImage', 5)->checkElement('div#sf_asset_container div.assetImage img[src$="folder.png"]', 2)->checkElement('div#sf_asset_container div.assetImage img[src$="asset1.png"]', 1)->checkElement('div#sf_asset_container div.assetImage:nth-child(4)', '/asset1/')->checkElement('div#sf_asset_container div.assetImage:nth-child(5)', '/asset2/')->checkElement('div#sf_asset_container div.assetImage:nth-child(6)', '/asset3/')->end()->info('sorting options')->click('Sort by date')->with('response')->begin()->checkElement('div#sf_asset_container div.assetImage:nth-child(4)', '/asset3/')->checkElement('div#sf_asset_container div.assetImage:nth-child(5)', '/asset2/')->checkElement('div#sf_asset_container div.assetImage:nth-child(6)', '/asset1/')->end()->click('Sort by name')->with('response')->begin()->checkElement('div#sf_asset_container div.assetImage:nth-child(4)', '/asset1/')->checkElement('div#sf_asset_container div.assetImage:nth-child(5)', '/asset2/')->checkElement('div#sf_asset_container div.assetImage:nth-child(6)', '/asset3/')->end()->info('enter first subfolder')->click('a[href$="media/TESTsubdir1"]')->with('request')->begin()->isParameter('module', 'sfAsset')->isParameter('action', 'list')->end()->with('response')->begin()->isStatusCode(200)->checkElement('div#sf_asset_bar p:first-child', '/TESTsubdir1/')->checkElement('div#sf_asset_container div.assetImage', 2)->checkElement('div#sf_asset_container div.assetComment', '/\\.\\./')->end()->info('return to list')->click('a[href$="media"]')->with('request')->begin()->isParameter('module', 'sfAsset')->isParameter('action', 'list')->end()->info('add new asset')->click('a[href$="media/TESTsubdir1"]')->click('input[value="Add"]', array('sf_asset' => array('file' => '')))->with('form')->begin()->hasErrors(1)->isError('file', 'required')->end()->get('/sfAsset/dir/media/TESTsubdir1')->click('input[value="Add"]', array('sf_asset' => array('file' => dirname(__FILE__) . '/../data/demo.png')))->with('form')->hasErrors(false)->with('request')->begin()->isParameter('module', 'sfAsset')->isParameter('action', 'addQuick')->end()->with('response')->isRedirected()->followRedirect()->with('request')->begin()->isParameter('module', 'sfAsset')->isParameter('action', 'edit')->end()->with('response')->begin()->isStatusCode(200)->checkElement('div#sf_asset_container div.content', '/demo\\.png/')->end()->with('doctrine')->check('sfAsset', array('folder_id' => $subdir1->getId(), 'filename' => 'demo.png', 'description' => 'demo.png', 'type' => 'image', 'filesize' => 4))->info('edit asset')->click('input.sf_admin_action_save', array('sf_asset' => array('description' => 'this is a demo image', 'author' => 'Massimiliano Arione', 'copyright' => '2010')))->with('form')->hasErrors(false)->with('response')->isRedirected()->followRedirect()->with('response')->begin()->checkElement('div.save-ok', '/Your modifications have been saved/')->end()->with('doctrine')->check('sfAsset', array('folder_id' => $subdir1->getId(), 'filename' => 'demo.png', 'description' => 'this is a demo image', 'author' => 'Massimiliano Arione', 'type' => 'image', 'filesize' => 4))->info('create a new folder')->click('TESTsubdir1')->click('input[value="Create"]', array('sf_asset_folder' => array('name' => '')))->with('form')->begin()->hasErrors(1)->isError('name', 'required')->end()->get('/sfAsset/dir/media/TESTsubdir1')->click('input[value="Create"]', array('sf_asset_folder' => array('name' => 'foobar')))->with('form')->hasErrors(false)->with('doctrine')->check('sfAssetFolder', array('lft' => 3, 'rgt' => 4, 'name' => 'foobar', 'relative_path' => 'media/TESTsubdir1/foobar'))->info('rename folder')->with('response')->isRedirected()->followRedirect()->click('input[value="Rename"]', array('sf_asset_folder' => array('name' => 'barfoo')))->with('form')->hasErrors(false)->with('doctrine')->check('sfAssetFolder', array('lft' => 3, 'rgt' => 4, 'name' => 'barfoo', 'relative_path' => 'media/TESTsubdir1/barfoo'))->info('delete folder')->with('response')->isRedirected()->followRedirect()->click('Delete folder', array(), array('method' => 'delete', '_with_csrf' => true))->with('request')->begin()->isParameter('module', 'sfAsset')->isParameter('action', 'deleteFolder')->end()->with('doctrine')->check('sfAssetFolder', array('lft' => 3, 'rgt' => 4, 'name' => 'barfoo', 'relative_path' => 'media/TESTsubdir1/barfoo'), false)->with('response')->isRedirected()->followRedirect()->with('response')->begin()->checkElement('div.save-ok', '/The folder has been deleted/')->end()->info('move folder')->click('input[value="Move"]', array('sf_asset_folder' => array('parent_folder' => $subdir2->getId())))->with('form')->hasErrors(false)->with('request')->begin()->isParameter('module', 'sfAsset')->isParameter('action', 'moveFolder')->end()->with('doctrine')->check('sfAssetFolder', array('lft' => 3, 'rgt' => 6, 'name' => 'TESTsubdir1', 'relative_path' => 'media/TESTsubdir2/TESTsubdir1'))->with('response')->isRedirected()->followRedirect()->with('response')->begin()->checkElement('div.save-ok', '/The folder has been moved/')->end()->info('move asset')->click('a[title="demo.png"]')->click('input[value="Move"]', array('sf_asset' => array('parent_folder' => $subdir2->getId())))->with('form')->hasErrors(false)->with('request')->begin()->isParameter('module', 'sfAsset')->isParameter('action', 'moveAsset')->end()->with('response')->isRedirected()->followRedirect()->with('response')->begin()->checkElement('div.save-ok', '/The file has been moved/')->end()->with('doctrine')->check('sfAsset', array('folder_id' => $subdir2->getId(), 'filename' => 'demo.png', 'description' => 'this is a demo image', 'type' => 'image', 'filesize' => 4))->info('rename asset')->click('input[value="Rename"]', array('sf_asset' => array('filename' => 'demorenamed.png')))->with('form')->hasErrors(false)->with('request')->begin()->isParameter('module', 'sfAsset')->isParameter('action', 'renameAsset')->end()->with('response')->isRedirected()->followRedirect()->with('response')->begin()->checkElement('div.save-ok', '/The file has been renamed/')->end()->with('doctrine')->check('sfAsset', array('folder_id' => $subdir2->getId(), 'filename' => 'demorenamed.png', 'description' => 'this is a demo image', 'type' => 'image'))->info('replace asset')->click('input[value="Replace"]', array('sf_asset' => array('file' => dirname(__FILE__) . '/../data/propel.gif')))->with('form')->hasErrors(false)->with('request')->begin()->isParameter('module', 'sfAsset')->isParameter('action', 'replaceAsset')->end()->with('response')->isRedirected()->followRedirect()->with('request')->begin()->isParameter('module', 'sfAsset')->isParameter('action', 'edit')->end()->with('response')->begin()->checkElement('div.save-ok', '/The file has been replaced/')->end()->with('doctrine')->check('sfAsset', array('folder_id' => $subdir2->getId(), 'filename' => 'demorenamed.png', 'description' => 'this is a demo image', 'type' => 'image'))->info('delete asset')->click('Delete', array(), array('method' => 'delete', '_with_csrf' => true))->with('request')->begin()->isParameter('module', 'sfAsset')->isParameter('action', 'deleteAsset')->end()->with('doctrine')->check('sfAsset', array('folder_id' => $subdir2->getId(), 'filename' => 'propel.gif', 'type' => 'image'), false)->with('response')->isRedirected()->followRedirect()->with('response')->begin()->checkElement('div.save-ok', '/The file has been deleted/')->end()->info('mass upload')->click('media')->click('Mass upload')->with('request')->begin()->isParameter('module', 'sfAsset')->isParameter('action', 'massUpload')->end()->with('response')->begin()->isValid(true)->end()->click('Upload', array('sf_asset' => array('folder_id' => $subdir1->getId(), 'file_1' => dirname(__FILE__) . '/../data/demo2.png', 'file_2' => dirname(__FILE__) . '/../data/propel2.gif')))->with('form')->hasErrors(false)->with('doctrine')->begin()->check('sfAsset', array('folder_id' => $subdir1->getId(), 'filename' => 'demo2.png', 'type' => 'image'))->check('sfAsset', array('folder_id' => $subdir1->getId(), 'filename' => 'propel2.gif', 'type' => 'image'))->end()->info('search')->get('/sfAsset/dir/media')->click('input[value="Search"]')->with('form')->begin()->hasErrors(false)->end()->with('request')->begin()->isParameter('module', 'sfAsset')->isParameter('action', 'search')->end()->with('response')->begin()->checkElement('div.search_result', 7)->end()->click('input[value="Search"]', array('sf_asset_filters' => array('filename' => array('text' => 'asset1'))))->with('form')->begin()->hasErrors(false)->end()->with('request')->begin()->isParameter('module', 'sfAsset')->isParameter('action', 'search')->end()->with('response')->begin()->checkElement('div.search_result', 3)->end()->info('delete folder with sub folder')->get('/sfAsset/dir/media')->click('input[value="Create"]', array('sf_asset_folder' => array('name' => 'sub')))->with('response')->isRedirected()->followRedirect()->click('input[value="Create"]', array('sf_asset_folder' => array('name' => 'sub2')))->with('response')->isRedirected()->followRedirect()->info('create sub folder')->get('/sfAsset/dir/media/sub')->info('delete folder with sub folder')->click('Delete folder', array(), array('method' => 'delete', '_with_csrf' => true))->with('request')->begin()->isParameter('module', 'sfAsset')->isParameter('action', 'deleteFolder')->end()->with('response')->isRedirected()->followRedirect()->with('response')->begin()->checkElement('div.save-ok', '/The folder has been deleted/')->end();
// TODO more tests...
 /**
  * process search
  * @param  array    $params
  * @param  string   $sort
  * @return Doctrine_Query
  */
 protected function search(array $params, $sort = 'name')
 {
     $query = $this->createQuery('a');
     if (isset($params['folder_id']) && $params['folder_id'] !== '') {
         if (null != ($folder = sfAssetFolderTable::getInstance()->find($params['folder_id']))) {
             if (false) {
                 $folder = new sfAssetFolder();
             }
             $query->leftJoin('a.Folder f');
             $query->where('f.lft >= ?', $folder->getNode()->getLeftValue());
             $query->andWhere('f.rgt <= ?', $folder->getNode()->getRightValue());
         }
     }
     //    if (isset($params['filename']['is_empty']))
     //    {
     //      $query->andWhere('filename = \'\' or filename is null', null);
     ////      $criterion = $c->getNewCriterion(self::FILENAME, '');
     ////      $criterion->addOr($c->getNewCriterion(self::FILENAME, null, Criteria::ISNULL));
     ////      $c->add($criterion);
     //    }
     //    else
     if (isset($params['filename']['text']) && strlen($params['filename']['text'])) {
         $query->andWhere('filename like ?', '%' . trim($params['filename']['text'], '*%') . '%');
     }
     if (isset($params['author']['is_empty'])) {
         $query->andWhere('author = \'\' or author is null');
     } elseif (isset($params['author']['text']) && strlen($params['author']['text'])) {
         $query->andWhere('author like ?', '%' . trim($params['author']['text'], '*%') . '%');
     }
     if (isset($params['copyright']['is_empty'])) {
         $query->andWhere('copyright = \'\' or copyright is null');
     } elseif (isset($params['copyright']['text']) && strlen($params['copyright']['text'])) {
         $query->andWhere('copyright like ?', '%' . trim($params['copyright']['text'], '*%') . '%');
     }
     if (isset($params['created_at'])) {
         // TODO query
         //      if (isset($params['created_at']['from']) && $params['created_at']['from'] !== array())  // TODO check this
         //      {
         //        $criterion = $c->getNewCriterion(self::CREATED_AT, $params['created_at']['from'], Criteria::GREATER_EQUAL);
         //      }
         //      if (isset($params['created_at']['to']) && $params['created_at']['to'] !== array())  // TODO check this
         //      {
         //        if (isset($criterion))
         //        {
         //          $criterion->addAnd($c->getNewCriterion(self::CREATED_AT, $params['created_at']['to'], Criteria::LESS_EQUAL));
         //        }
         //        else
         //        {
         //          $criterion = $c->getNewCriterion(self::CREATED_AT, $params['created_at']['to'], Criteria::LESS_EQUAL);
         //        }
         //      }
         //      if (isset($criterion))
         //      {
         //        $c->add($criterion);
         //      }
     }
     if (isset($params['description']['is_empty'])) {
         $query->andWhere('description = \'\' or description is null');
     } else {
         if (isset($params['description']) && $params['description'] !== '') {
             $query->andWhere('description like ?', '%' . trim($params['description']['text'], '*%') . '%');
         }
     }
     switch ($sort) {
         case 'date':
             $query->orderBy('created_at DESC');
             break;
         default:
             $query->orderBy('filename ASC');
     }
     return $query;
 }