MINOR Checking that Folder::findOrMake() can create an assets/assets/ folder

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@107276 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-06-29 04:59:50 +00:00 committed by Sam Minnee
parent 9a1c997818
commit d55e38b6ab
2 changed files with 11 additions and 4 deletions

View File

@ -25,7 +25,8 @@ class Folder extends File {
* Find the given folder or create it both as {@link Folder} database records
* and on the filesystem. If necessary, creates parent folders as well.
*
* @param $folderPath string Absolute or relative path to the file
* @param $folderPath string Absolute or relative path to the file.
* If path is relative, its interpreted relative to the "assets/" directory.
* @return Folder
*/
static function findOrMake($folderPath) {
@ -38,10 +39,9 @@ class Folder extends File {
$parts = explode("/",$folderPath);
$parentID = 0;
$item = null;
foreach($parts as $part) {
if(!$part) continue; // happens for paths with a trailing slash
$item = DataObject::get_one("Folder", "\"Name\" = '$part' AND \"ParentID\" = $parentID");
if(!$item) {
$item = new Folder();
@ -55,6 +55,7 @@ class Folder extends File {
}
$parentID = $item->ID;
}
return $item;
}

View File

@ -43,11 +43,17 @@ class FolderTest extends SapphireTest {
$this->assertNotNull($parentFolder);
$this->assertEquals($parentFolder->ID, $folder->ParentID);
$path = '/FolderTest/testFindOrMake';
$path = '/FolderTest/testFindOrMake'; // no trailing slash
$folder = Folder::findOrMake($path);
$this->assertEquals(ASSETS_DIR . $path . '/',$folder->getRelativePath(),
'Path information is correctly saved to database (without trailing slash)'
);
$path = '/assets/'; // relative to "assets/" folder, should produce "assets/assets/"
$folder = Folder::findOrMake($path);
$this->assertEquals(ASSETS_DIR . $path,$folder->getRelativePath(),
'A folder named "assets/" within "assets/" is allowed'
);
}
/**