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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

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

webchick’s picture

Status: Needs review » Needs work

Looks 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! :)

Dave Reid’s picture

Status: Needs work » Needs review
FileSize
2.57 KB

Alright, 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.

Dave Reid’s picture

Revised documentation.

Dave Reid’s picture

Revised again. Removed @return. It's obvious by inline docs what this does now.

webchick’s picture

Status: Needs review » Fixed

Confirmed 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!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.