1 file.test public FileUploadWizardTestCase::testFileUploadWizardMultiple()

Test uploading multiple files of different types through the wizard.

When more than one file is uploaded at once the wizard skips all steps and saves every file immediately using the default scheme, with each file marked permanent.

File

core/modules/file/tests/file.test, line 2504
Tests for file.module.

Class

FileUploadWizardTestCase
Tests creating new file entities through the file upload wizard.

Code

public function testFileUploadWizardMultiple() {
  $txt_file = $this->getTestFile('text');
  $image_file = $this->getTestFile('image');

  // Record the highest fid before the upload so we can find the new files.
  $previous_last_fid = $this->getLastFileId();

  // Upload a text file and an image file simultaneously.
  $edit = array();
  $edit['files[upload][]'] = array(
    backdrop_realpath($txt_file->uri),
    backdrop_realpath($image_file->uri),
  );
  $this->backdropPost('file/add', $edit, t('Next'));

  // Both files should have been saved immediately without wizard steps.
  $new_fids = db_query('SELECT fid FROM {file_managed} WHERE fid > :prev ORDER BY fid ASC', array(':prev' => $previous_last_fid))->fetchCol();
  $new_files = file_load_multiple($new_fids);
  $this->assertEqual(2, count($new_files), 'Both uploaded files were saved to the database.');

  foreach ($new_files as $file) {
    // Each file should be reported as uploaded. The wizard bypasses type
    // detection for multi-file uploads, so only check that the filename and
    // "was uploaded" appear together on the page.
    $this->assertText($file->filename . ' was uploaded.', format_string('Upload message shown for %name.', array('%name' => $file->filename)));

    // Each file should exist on disk and in the database.
    $this->assertFileExists($file, format_string('File %name exists on disk.', array('%name' => $file->filename)));
    $this->assertFileEntryExists($file, format_string('File %name entry exists in the database.', array('%name' => $file->filename)));

    // Each file must be marked permanent.
    $this->assertEqual(FILE_STATUS_PERMANENT, $file->status, format_string('File %name is marked permanent.', array('%name' => $file->filename)));
  }
}