Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have always gotten one error in the upload tests. I narrowed it down to the drupalGetTestFiles and drupalCompareFiles functions.
The error I was getting in the upload.test file was in:
// Attempt to upload .html file when .html is only extension allowed.
$html_files = array_values($this->drupalGetTestFiles('html'));
// Use the HTML file with the .html extension, $html_files[0] has a .txt
// extension.
$html_file = $html_files[1]->filename;
$this->uploadFile($node, $html_file);
$this->assertNoRaw(t('The specified file %name could not be uploaded.', array('%name' => basename($html_file))), t('File '. $html_file . ' was allowed to be uploaded'));
On my system both the html-1.txt and html-2.txt files are 24KB. The drupalSortFile was using stat to compare file sizes:
function drupalCompareFiles($file1, $file2) {
if (stat($file1->filename) > stat($file2->filename)) {
return 1;
}
return -1;
}
... which was messing up the expected order on my system between those two files for some reason. I changed drupalCompareFiles to use filesize, and it works for me now. To test this patch, run the following test which call drupalGetTestFiles: blogapi, file, user, and upload.
Comment | File | Size | Author |
---|---|---|---|
#5 | drupal-get-test-files-D7.patch | 2.82 KB | Dave Reid |
#4 | drupal-get-test-files-D7.patch | 3 KB | Dave Reid |
#3 | drupal-get-test-files-D7.patch | 2.57 KB | Dave Reid |
drupal-get-test-files-D7.patch | 766 bytes | Dave Reid | |
Comments
Comment #1
Dave ReidNot sure why we're using stat to compare file sizes to begin with, since it returns a big array of detailed information, and not just the file size. Comparing two big arrays just for filesize seems silly.
Comment #2
webchickLooks like the only thing that calls that function is drupalGetTestFiles(). That in turn is called from blogapi, upload, and user tests.
However! Ironically, this patch causes the error you've been getting all along on my machine which previously was not. How frustrating. :)
Kudos for definitely nailing it down to the right function though! :)
Comment #3
Dave ReidAlright, so revised drupalCompareFiles uses filepath first, and if the files are equal, then uses strnatcmp to order filenames naturally. Tested on the four tests and they pass.
Comment #4
Dave ReidRevised documentation.
Comment #5
Dave ReidRevised again. Removed @return. It's obvious by inline docs what this does now.
Comment #6
webchickConfirmed things still work on my end. That @return statement was a doozy and I feel the inline comments add more clarity than that so I removed it, and committed this patch.
YAY!
Comment #7
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.