# Test_Directory/ sfAssetFolder # Test_Sub-directory/ sfAssetFolder2 # Test_Sub-sub-directory/ sfAssetFolder3 # toto # raikkonen.jpg // Bug in Propel instance pooling + NestedSets... $folderProvider->clearInstancePool(); $root = $folderProvider->retrieveByPk($rootId); $sfAssetFolder2 = $folderProvider->retrieveByPk($id2); $sfAssetFolder3 = $folderProvider->retrieveByPk($id3); $t->is($sfAssetFolder2->retrieveParent()->getId(), $root->getId(), 'move() gives the correct parent'); $t->is($sfAssetFolder3->retrieveParent()->retrieveParent()->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'); $assetProvider->clearInstancePool(); $sfAsset = $assetProvider->retrieveByPk($sf_asset_id); $sfAsset2 = $assetProvider->retrieveByPk($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 $e->getMessage(); } // reset DB $con->rollBack(); function debugTree($root) { echo $root->getName(), ' ', $root->getTreeLeft(), '/', $root->getTreeRight(), "\n"; foreach ($root->getDescendants() as $folder) { echo str_repeat(' ', $folder->getLevel()), $folder->getName(), ' ', $folder->getTreeLeft(), '/', $folder->getTreeRight(), "\n"; } }
$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'); $t->is($asset1->getFilename(), 'raikkonen2.jpg', 'move() changes filename'); $t->is($asset1->getUrl(), $root->getUrl() . DIRECTORY_SEPARATOR . $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 = $assetProvider->retrieveByPk($old_id); $t->ok(!$null, 'delete() removes asset from DB'); } catch (Exception $e) { echo $e->getMessage(); } // reset DB $con->rollBack();