MINOR: Unit test fails if the previous build left temp files behind, so they are removed at the start of the test

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@104050 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Mark Stephens 2010-05-04 06:06:32 +00:00 committed by Sam Minnee
parent 98a299d00c
commit b36fc700da

View File

@ -210,6 +210,18 @@ class UploadTest extends SapphireTest {
}
// Delete files in the default uploads directory that match the name pattern.
// @param String $namePattern A regular expression applied to files in the directory. If the name matches
// the pattern, it is deleted. Directories, . and .. are excluded.
function deleteTestUploadFiles($namePattern) {
$tmpFolder = ASSETS_PATH . "/" . Upload::$uploads_folder;
$files = scandir($tmpFolder);
foreach ($files as $f) {
if ($f == "." || $f == ".." || is_dir("$tmpFolder/$f")) continue;
if (preg_match($namePattern, $f)) unlink("$tmpFolder/$f");
}
}
function testUploadTarGzFileTwiceAppendsNumber() {
// create tmp file
$tmpFileName = 'UploadTest_testUpload.tar.gz';
@ -228,6 +240,9 @@ class UploadTest extends SapphireTest {
'error' => UPLOAD_ERR_OK,
);
// Make sure there are none here, otherwise they get renamed incorrectly for the test.
$this->deleteTestUploadFiles("/UploadTesttestUpload.*tar\.gz/");
// test upload into default folder
$u = new Upload();
$u->load($tmpFile);
@ -269,6 +284,9 @@ class UploadTest extends SapphireTest {
'error' => UPLOAD_ERR_OK,
);
// Make sure there are none here, otherwise they get renamed incorrectly for the test.
$this->deleteTestUploadFiles("/UploadTesttestUpload.*/");
$v = new UploadTest_Validator();
$v->setAllowedExtensions(array(''));