function MediaInternetYouTubeTestCase::testYouTubeFileHandling in Media: YouTube 7.3
Tests YouTube file handler.
File
- ./
media_youtube.test, line 51 - Tests for media_youtube.module.
Class
- MediaInternetYouTubeTestCase
- Test the MediaInternetYouTubeHandler provider.
Code
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.');
}