silverstripe-framework/tests/filesystem/FolderTest.php
Ingo Schommer 1e9aeaef3e BUGFIX Fixed Folder writing by overloading validate() (was inheriting File->validate() which does extension checks)
BUGFIX Fixed Folder::findOrMake() not to create "new-folder" through File->setName() if using a trailing slash in the path (which causes an empty name). Added FolderTest to verify this.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@101266 467b73ca-7a2a-4603-9d3b-597d59a354a9
2011-02-02 14:19:04 +13:00

36 lines
1.1 KiB
PHP

<?php
/**
* @author Ingo Schommer (ingo at silverstripe dot com)
* @todo There's currently no way to save outside of assets/ folder
*
* @package sapphire
* @subpackage tests
*/
class FolderTest extends SapphireTest {
function tearDown() {
$testPath = ASSETS_PATH . '/FolderTest';
if(file_exists($testPath)) Filesystem::removeFolder($testPath);
parent::tearDown();
}
function testFindOrMake() {
$path = '/FolderTest/testFindOrMake/';
$folder = Folder::findOrMake($path);
$this->assertEquals(ASSETS_DIR . $path,$folder->getRelativePath(),
'Nested path information is correctly saved to database (with trailing slash)'
);
$this->assertTrue(file_exists(ASSETS_PATH . $path), 'File');
$parentFolder = DataObject::get_one('Folder', '"Name" = \'FolderTest\'');
$this->assertNotNull($parentFolder);
$this->assertEquals($parentFolder->ID, $folder->ParentID);
$path = '/FolderTest/testFindOrMake';
$folder = Folder::findOrMake($path);
$this->assertEquals(ASSETS_DIR . $path . '/',$folder->getRelativePath(),
'Path information is correctly saved to database (without trailing slash)'
);
}
}