You are here

class MediaInternetYouTubeTestCase in Media: YouTube 7.3

Test the MediaInternetYouTubeHandler provider.

Hierarchy

Expanded class hierarchy of MediaInternetYouTubeTestCase

File

./media_youtube.test, line 28
Tests for media_youtube.module.

View source
class MediaInternetYouTubeTestCase extends MediaYouTubeTestHelper {
  public static function getInfo() {
    return array(
      'name' => 'YouTube file handler provider',
      'description' => 'Test the YouTube handler provider.',
      'group' => 'Media YouTube',
    );
  }
  function setUp() {
    parent::setUp('media_youtube_test');

    // Disable the private file system which is automatically enabled by
    // DrupalTestCase so we can test the upload wizard correctly.
    variable_del('file_private_path');
    $web_user = $this
      ->drupalCreateUser(array(
      'create files',
      'add media from remote sources',
      'edit own video files',
    ));
    $this
      ->drupalLogin($web_user);
  }

  /**
   * Tests YouTube file handler.
   */
  function testYouTubeFileHandling() {

    // Step 1: Add a video file by providing a URL to the resource on YouTube.
    $edit = array();
    $edit['embed_code'] = 'https://www.youtube.com/watch?v=9g2U12SsRns';
    $this
      ->drupalPost('file/add/web', $edit, t('Next'));

    // 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 video file has been uploaded.
    $this
      ->assertRaw(t('!type %name was uploaded.', array(
      '!type' => 'Video',
      '%name' => $file->filename,
    )), t('Video file uploaded.'));

    // Verify that the video formatter is used to render the full video.
    $video_info = array(
      'uri' => $file->uri,
      'options' => array(
        'width' => 640,
        'height' => 390,
        'autohide' => 2,
        'autoplay' => FALSE,
        'color' => 'red',
        'enablejsapi' => FALSE,
        'loop' => FALSE,
        'modestbranding' => FALSE,
        'nocookie' => FALSE,
        'origin' => '',
        'protocol' => 'https:',
        'protocol_specify' => FALSE,
        'rel' => FALSE,
        'controls' => FALSE,
        'showinfo' => TRUE,
        'theme' => 'dark',
        'captions' => FALSE,
      ),
    );
    $default_output = theme('media_youtube_video', $video_info);
    $this
      ->assertRaw($default_output, 'Video displayed using the Media: YouTube Video formatter.');

    // Edit the file.
    $this
      ->drupalGet('file/' . $file->fid . '/edit');

    // Verify that the image formatter is used to render the video preview.
    $wrapper = file_stream_wrapper_get_instance_by_uri($file->uri);
    $image_info = array(
      'uri' => $file->uri,
      'style_name' => 'media_thumbnail',
      'path' => $wrapper
        ->getLocalThumbnailPath(),
      'alt' => isset($file->override['attributes']['alt']) ? $file->override['attributes']['alt'] : $file->filename,
    );
    $default_output = theme('image_style', $image_info);
    $this
      ->assertRaw($default_output, 'Video displayed using the Media: YouTube Image formatter.');
  }

}

Members