#320161 by Dave Reid: Fix problems with drupalGetTestFiles() that causes upload.test to break on some systems.

merge-requests/26/head
Angie Byron 2008-10-12 08:30:05 +00:00
parent bc22653541
commit f95f58cc05
2 changed files with 13 additions and 8 deletions

View File

@ -486,13 +486,19 @@ class DrupalWebTestCase {
}
/**
* 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;
}
/**

View File

@ -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.