You are here

function MediaLibraryUploadWizardTestCase::testMediaLibraryUploadWizardCheckbox in Media Library 7

Test the file upload wizard 'add to library' checkbox.

File

./media_library.test, line 161
Test integration for the Media Library module.

Class

MediaLibraryUploadWizardTestCase
Tests creating new file entities and adding them to the media library through the file upload wizard.

Code

function testMediaLibraryUploadWizardCheckbox() {
  $test_file = $this
    ->getTestFile('image');

  // 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 3: Scheme selection.
  $edit = array();
  $edit['scheme'] = 'public';
  $this
    ->drupalPost(NULL, $edit, t('Next'));

  // Step 4: Attached fields.
  $edit = array();
  $edit['library'] = TRUE;
  $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' => $file->filename,
  )), t('Image file uploaded.'));

  // Check that the image was included in the media library.
  $this
    ->assertEqual($file->library, INCLUDE_IN_LIBRARY, t('File was included in the media library.'));
}