MINOR Making FileTest->setUp()/tearDown() more resilient against in-test file/folder renames (from r107271)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112560 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-10-15 03:16:33 +00:00
parent 8b88f4aaf4
commit 9d227ba2e4

View File

@ -131,10 +131,10 @@ class FileTest extends SapphireTest {
if(!file_exists(ASSETS_PATH)) mkdir(ASSETS_PATH); if(!file_exists(ASSETS_PATH)) mkdir(ASSETS_PATH);
/* Create a test folders for each of the fixture references */ /* Create a test folders for each of the fixture references */
$fileIDs = $this->allFixtureIDs('Folder'); $folderIDs = $this->allFixtureIDs('Folder');
foreach($fileIDs as $fileID) { foreach($folderIDs as $folderID) {
$file = DataObject::get_by_id('Folder', $fileID); $folder = DataObject::get_by_id('Folder', $folderID);
if(!file_exists(BASE_PATH."/$file->Filename")) mkdir(BASE_PATH."/$file->Filename"); if(!file_exists(BASE_PATH."/$folder->Filename")) mkdir(BASE_PATH."/$folder->Filename");
} }
/* Create a test files for each of the fixture references */ /* Create a test files for each of the fixture references */
@ -152,14 +152,14 @@ class FileTest extends SapphireTest {
$fileIDs = $this->allFixtureIDs('File'); $fileIDs = $this->allFixtureIDs('File');
foreach($fileIDs as $fileID) { foreach($fileIDs as $fileID) {
$file = DataObject::get_by_id('File', $fileID); $file = DataObject::get_by_id('File', $fileID);
if(file_exists(BASE_PATH."/$file->Filename")) unlink(BASE_PATH."/$file->Filename"); if($file && file_exists(BASE_PATH."/$file->Filename")) unlink(BASE_PATH."/$file->Filename");
} }
/* Remove the test folders that we've crated */ /* Remove the test folders that we've crated */
$fileIDs = $this->allFixtureIDs('Folder'); $folderIDs = $this->allFixtureIDs('Folder');
foreach($fileIDs as $fileID) { foreach($folderIDs as $folderID) {
$file = DataObject::get_by_id('Folder', $fileID); $folder = DataObject::get_by_id('Folder', $folderID);
if(file_exists(BASE_PATH."/$file->Filename")) rmdir(BASE_PATH."/$file->Filename"); if($folder && file_exists(BASE_PATH."/$folder->Filename")) rmdir(BASE_PATH."/$folder->Filename");
} }
parent::tearDown(); parent::tearDown();