You are here

function MediaInternetProviderTestCase::testMediaInternetCustomProviderWizardStepSkipping in D7 Media 7.3

Same name and namespace in other branches
  1. 7.4 modules/media_internet/tests/media_internet.test \MediaInternetProviderTestCase::testMediaInternetCustomProviderWizardStepSkipping()
  2. 7.2 modules/media_internet/tests/media_internet.test \MediaInternetProviderTestCase::testMediaInternetCustomProviderWizardStepSkipping()

Test skipping each of the file upload wizard steps.

File

modules/media_internet/tests/media_internet.test, line 313
Tests for media_internet.module.

Class

MediaInternetProviderTestCase
Tests custom media provider APIs.

Code

function testMediaInternetCustomProviderWizardStepSkipping() {
  $filename = $this
    ->randomName();

  // Ensure that the file is affected by every step.
  variable_set('file_private_path', $this->private_files_directory);
  $this
    ->createFileType(array(
    'type' => 'video1',
    'label' => 'Video 1',
    'mimetypes' => array(
      'video/mediainternettest',
    ),
  ));
  $this
    ->createFileType(array(
    'type' => 'video2',
    'label' => 'Video 2',
    'mimetypes' => array(
      'video/mediainternettest',
    ),
  ));
  $field_name = drupal_strtolower($this
    ->randomName() . '_field_name');
  $field = array(
    'field_name' => $field_name,
    'type' => 'text',
  );
  field_create_field($field);
  $instance = array(
    'field_name' => $field_name,
    'entity_type' => 'file',
    'bundle' => 'video2',
    'label' => $this
      ->randomName() . '_label',
  );
  field_create_instance($instance);

  // Test skipping each upload wizard step.
  foreach (array(
    'types',
    'schemes',
    'fields',
  ) as $step) {

    // Step to skip.
    switch ($step) {
      case 'types':
        variable_set('file_entity_file_upload_wizard_skip_file_type', TRUE);
        break;
      case 'schemes':
        variable_set('file_entity_file_upload_wizard_skip_scheme', TRUE);
        break;
      case 'fields':
        variable_set('file_entity_file_upload_wizard_skip_fields', TRUE);
        break;
    }

    // Step 1: Upload a basic video file.
    $edit = array();
    $edit['embed_code'] = 'http://www.example.com/video/123';
    $this
      ->drupalPost('file/add/web', $edit, t('Next'));

    // Step 2: File type selection.
    if ($step != 'types') {
      $edit = array();
      $edit['type'] = 'video2';
      $this
        ->drupalPost(NULL, $edit, t('Next'));
    }

    // Step 3: Users should not be able to select a scheme for files with
    // read-only stream wrappers.
    $this
      ->assertNoFieldByName('scheme');

    // Step 4: Attached fields.
    if ($step != 'fields') {

      // Skipping file type selection essentially skips this step as well
      // because the file will not be assigned a type so no fields will be
      // available.
      if ($step != 'types') {
        $edit = array();
        $edit['filename'] = $filename;
        $edit[$field_name . '[' . LANGUAGE_NONE . '][0][value]'] = $this
          ->randomName();
        $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.'));

    // Determine the file's file type.
    $type = file_type_load($file->type);

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

    // Reset 'skip' variables.
    variable_del('file_entity_file_upload_wizard_skip_file_type');
    variable_del('file_entity_file_upload_wizard_skip_scheme');
    variable_del('file_entity_file_upload_wizard_skip_fields');
  }
}