protected function doClean($values) { $my_id = 0; if ($values['parent_id']) { $parent = lyMediaFolderTable::getInstance()->find($values['parent_id']); } else { $my_id = $values['id']; $object = lyMediaFolderTable::getInstance()->find($my_id); $parent = $object->getNode()->getParent(); } $fs = new lyMediaFileSystem(); if (!$fs->is_dir($parent->getRelativePath()) || !$fs->is_writable($parent->getRelativePath())) { throw new sfValidatorError($this, 'parent_unwritable', array('name' => $values['name'], 'parent' => $parent->getName())); } if (!$parent || !$parent->getNode()->isValidNode()) { throw new sfValidatorError($this, 'invalid'); } if ($children = $parent->getNode()->getChildren()) { foreach ($children as $c) { if ($values['name'] == $c->getName() && $c->getId() != $my_id) { throw new sfValidatorError($this, 'folder_exists', array('name' => $values['name'], 'parent' => $parent->getName())); } } } return $values; }
protected function doClean($values) { $folder = lyMediaFolderTable::getInstance()->find($values['folder_id']); if ($folder === false) { throw new sfValidatorError($this, 'invalid'); } $fs = new lyMediaFileSystem(); if (!$fs->is_dir($folder->getRelativePath()) || !$fs->is_writable($folder->getRelativePath())) { throw new sfValidatorError($this, 'folder_unwritable', array('folder' => $folder->getRelativePath())); } $my_id = empty($values['id']) ? 0 : $values['id']; $assets = $folder->getAssets(); foreach ($assets as $a) { if ($values['filename'] == $a->getFilename() && $a->getId() != $my_id) { throw new sfValidatorError($this, 'file_exists', array('name' => $values['filename'], 'folder' => $folder->getName())); } } return $values; }
$fs = new lyMediaFileSystem(); $t = new lime_test(30, new lime_output_color()); $t->info('Create first level folder'); $folder = new lyMediaFolder(); $folder->setName('test'); $folder->create($root); $folder->refresh(); /* * test_root * -- test */ $t->is($folder->getName(), 'test', '->getName()'); $t->is($folder->getRelativePath(), 'test_root/test/', '->getRelativePath()'); $t->ok($folder->getNode()->isValidNode(), 'Folder is a valid node'); $t->is($folder->getNode()->getPath('/', true), 'test_root/test', 'Folder has right path'); $t->ok($fs->is_dir($folder->getRelativePath()), 'Folder exists in filesystem'); $t->info('Create sub-folder'); $sub = new lyMediaFolder(); $sub->setName('test-sub'); $sub->create($folder); $sub->refresh(); /* * test_root * -- test * -- -- test-sub */ $t->is($sub->getRelativePath(), 'test_root/test/test-sub/', '->getRelativePath()'); $t->ok($sub->getNode()->isValidNode(), 'Folder is a valid node'); $t->is($sub->getNode()->getPath('/', true), 'test_root/test/test-sub', 'Subfolder has right path'); $t->ok($fs->is_dir($sub->getRelativePath()), 'Folder exists in filesystem'); $folder2 = new lyMediaFolder();
include dirname(__FILE__) . '/../bootstrap/unit.php'; $conn = lyMediaFolderTable::getInstance()->getConnection(); $root = lyMediaFolderTable::getInstance()->createRoot('test_root'); $fs = new lyMediaFileSystem(); $t = new lime_test(15, new lime_output_color()); $t->info('Create first level folder'); $folder = new lyMediaFolder(); $folder->setName('test'); $folder->create($root); $folder->refresh(); $t->is($folder->getName(), 'test', '->getName()'); $t->is($folder->getRelativePath(), 'test_root/test/', '->getRelativePath()'); $t->ok($folder->getNode()->isValidNode(), 'Folder is a valid node'); $t->is($folder->getNode()->getPath('/', true), 'test_root/test', 'Folder has right path'); $t->ok($fs->is_dir($folder->getRelativePath()), 'Folder exists in filesystem'); $t->info('Create sub-folder'); $sub = new lyMediaFolder(); $sub->setName('test-sub'); $sub->create($folder); $sub->refresh(); $t->is($sub->getRelativePath(), 'test_root/test/test-sub/', '->getRelativePath()'); $t->ok($sub->getNode()->isValidNode(), 'Folder is a valid node'); $t->is($sub->getNode()->getPath('/', true), 'test_root/test/test-sub', 'Subfolder has right path'); $t->ok($fs->is_dir($sub->getRelativePath()), 'Folder exists in filesystem'); $folder2 = new lyMediaFolder(); $folder2->setName('test2'); $folder2->create($root); $folder2->refresh(); $t->info('Move folder'); $folder2->move($folder);
<?php include dirname(__FILE__) . '/../bootstrap/unit.php'; $fs = new lyMediaFileSystem(); $t = new lime_test(5, new lime_output_color()); $t->info('->createRoot()'); $root = lyMediaFolderTable::getInstance()->createRoot('test_root'); $t->is($root->getRelativePath(), 'test_root/', '->getRelativePath()'); $t->ok($root->getNode()->isValidNode(), 'Folder is valid node'); $t->ok($root->getNode()->isRoot(), 'Folder is root'); $t->ok($fs->is_dir($root->getRelativePath()), 'Root dir created in filesystem'); $t->info('->getRoot()'); $t->is_deeply($root->toArray(), lyMediaFolderTable::getInstance()->getRoot()->toArray(), '->getRoot()');