mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
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:
parent
98a299d00c
commit
b36fc700da
@ -209,7 +209,19 @@ class UploadTest extends SapphireTest {
|
||||
$this->assertEquals(1, count($u->getErrors()), 'There is a single error of the file extension');
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 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';
|
||||
@ -227,7 +239,10 @@ class UploadTest extends SapphireTest {
|
||||
'extension' => 'tar.gz',
|
||||
'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,15 +284,18 @@ 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(''));
|
||||
|
||||
|
||||
// test upload into default folder
|
||||
$u = new Upload();
|
||||
$u->setValidator($v);
|
||||
$u->load($tmpFile);
|
||||
$file = $u->getFile();
|
||||
|
||||
|
||||
$this->assertEquals(
|
||||
'UploadTesttestUpload',
|
||||
$file->Name,
|
||||
|
Loading…
x
Reference in New Issue
Block a user