You are here

function FileEntityUploadWizardTestCase::testFileEntityUploadWizardFields in File Entity (fieldable files) 7.2

Same name and namespace in other branches
  1. 7.3 file_entity.test \FileEntityUploadWizardTestCase::testFileEntityUploadWizardFields()

Test the file upload wizard field step.

File

./file_entity.test, line 520
Test integration for the file_entity module.

Class

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

Code

function testFileEntityUploadWizardFields() {
  $test_file = $this
    ->getTestFile('image');
  $filename = $this
    ->randomName();
  $alt = $this
    ->randomName();
  $title = $this
    ->randomName();

  // Step 1: Upload a basic image file.
  $edit = array();
  $edit['files[upload]'] = drupal_realpath($test_file->uri);
  $this
    ->drupalPost('file/add', $edit, t('Next'));

  // Step 4: Attached fields.
  $edit = array();
  $edit['filename'] = $filename;
  $edit['field_file_image_alt_text[' . LANGUAGE_NONE . '][0][value]'] = $alt;
  $edit['field_file_image_title_text[' . LANGUAGE_NONE . '][0][value]'] = $title;
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Check that the file exists in the database.
  $fid = $this
    ->getLastFileId();
  $file = file_load($fid);
  $this
    ->assertTrue($file, t('File found in database.'));

  // Check that the image file has been uploaded.
  $this
    ->assertRaw(t('!type %name was uploaded.', array(
    '!type' => 'Image',
    '%name' => $filename,
  )), t('Image file uploaded.'));

  // Check that the alt and title text was loaded from the fields.
  $this
    ->assertEqual($file->alt, $alt, t('Alt text was stored as file metadata.'));
  $this
    ->assertEqual($file->title, $title, t('Title text was stored as file metadata.'));
}