Commit f95f58cc authored by webchick's avatar webchick
Browse files

#320161 by Dave Reid: Fix problems with drupalGetTestFiles() that causes...

#320161 by Dave Reid: Fix problems with drupalGetTestFiles() that causes upload.test to break on some systems.
parent bc226535
......@@ -486,13 +486,19 @@ function drupalGetTestFiles($type, $size = NULL) {
}
/**
* Compare two files based on size.
* Compare two files based on size and file name.
*/
function drupalCompareFiles($file1, $file2) {
if (stat($file1->filename) > stat($file2->filename)) {
return 1;
// Determine which file is larger.
$compare_size = (filesize($file1->filename) > filesize($file2->filename));
if (!$compare_size) {
// Both files were the same size, so return whichever one is alphabetically greater.
return strnatcmp($file1->name, $file2->name);
}
else {
// Return TRUE if $file1 is larger than $file2.
return $compare_size;
}
return -1;
}
/**
......
......@@ -102,14 +102,13 @@ class UploadTestCase extends DrupalWebTestCase {
$node = $this->drupalCreateNode();
// Attempt to upload .txt file when .html is only extension allowed.
$text_files = array_values($this->drupalGetTestFiles('text'));
$text_file = current($this->drupalGetTestFiles('text'));
// Select a file that's less than the 1MB upload limit so we only test one
// limit at a time.
$text_file = $text_files[2]->filename;
$this->uploadFile($node, $text_file, FALSE);
$this->uploadFile($node, $text_file->filename, FALSE);
// Test the error message in two steps in case there are additional errors
// that change the error message's format.
$this->assertRaw(t('The specified file %name could not be uploaded.', array('%name' => basename($text_file))), t('File %filename was not allowed to be uploaded', array('%filename' => $text_file)));
$this->assertRaw(t('The specified file %name could not be uploaded.', array('%name' => $text_file->basename)), t('File %filename was not allowed to be uploaded', array('%filename' => $text_file->filename)));
$this->assertRaw(t('Only files with the following extensions are allowed: %files-allowed.', array('%files-allowed' => $settings['upload_extensions'])), t('File extension cited as reason for failure'));
// Attempt to upload .html file when .html is only extension allowed.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment