mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Checking that Folder::findOrMake() can create an assets/assets/ folder (from r107276)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112567 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
07494a5f93
commit
706553ee95
@ -61,7 +61,8 @@ class Folder extends File {
|
|||||||
* Find the given folder or create it both as {@link Folder} database records
|
* Find the given folder or create it both as {@link Folder} database records
|
||||||
* and on the filesystem. If necessary, creates parent folders as well.
|
* 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
|
* @return Folder
|
||||||
*/
|
*/
|
||||||
static function findOrMake($folderPath) {
|
static function findOrMake($folderPath) {
|
||||||
@ -74,10 +75,9 @@ class Folder extends File {
|
|||||||
$parts = explode("/",$folderPath);
|
$parts = explode("/",$folderPath);
|
||||||
|
|
||||||
$parentID = 0;
|
$parentID = 0;
|
||||||
|
$item = null;
|
||||||
foreach($parts as $part) {
|
foreach($parts as $part) {
|
||||||
if(!$part) continue; // happens for paths with a trailing slash
|
if(!$part) continue; // happens for paths with a trailing slash
|
||||||
|
|
||||||
$item = DataObject::get_one("Folder", "\"Name\" = '$part' AND \"ParentID\" = $parentID");
|
$item = DataObject::get_one("Folder", "\"Name\" = '$part' AND \"ParentID\" = $parentID");
|
||||||
if(!$item) {
|
if(!$item) {
|
||||||
$item = new Folder();
|
$item = new Folder();
|
||||||
@ -91,6 +91,7 @@ class Folder extends File {
|
|||||||
}
|
}
|
||||||
$parentID = $item->ID;
|
$parentID = $item->ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,11 +43,17 @@ class FolderTest extends SapphireTest {
|
|||||||
$this->assertNotNull($parentFolder);
|
$this->assertNotNull($parentFolder);
|
||||||
$this->assertEquals($parentFolder->ID, $folder->ParentID);
|
$this->assertEquals($parentFolder->ID, $folder->ParentID);
|
||||||
|
|
||||||
$path = '/FolderTest/testFindOrMake';
|
$path = '/FolderTest/testFindOrMake'; // no trailing slash
|
||||||
$folder = Folder::findOrMake($path);
|
$folder = Folder::findOrMake($path);
|
||||||
$this->assertEquals(ASSETS_DIR . $path . '/',$folder->getRelativePath(),
|
$this->assertEquals(ASSETS_DIR . $path . '/',$folder->getRelativePath(),
|
||||||
'Path information is correctly saved to database (without trailing slash)'
|
'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'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user