Projet

Général

Profil

Paste
Télécharger (3,46 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / media_youtube / media_youtube.test @ 5e632cae

1
<?php
2

    
3
/**
4
 * @file
5
 * Tests for media_youtube.module.
6
 */
7

    
8
/**
9
 * Provides methods specifically for testing Media YouTube's YouTube video handling.
10
 */
11
class MediaYouTubeTestHelper extends MediaInternetTestHelper {
12
  function setUp() {
13
    // Since this is a base class for many test cases, support the same
14
    // flexibility that DrupalWebTestCase::setUp() has for the modules to be
15
    // passed in as either an array or a variable number of string arguments.
16
    $modules = func_get_args();
17
    if (isset($modules[0]) && is_array($modules[0])) {
18
      $modules = $modules[0];
19
    }
20
    $modules[] = 'media_youtube';
21
    parent::setUp($modules);
22
  }
23
}
24

    
25
/**
26
 * Test the MediaInternetYouTubeHandler provider.
27
 */
28
class MediaInternetYouTubeTestCase extends MediaYouTubeTestHelper {
29
  public static function getInfo() {
30
    return array(
31
      'name' => 'YouTube file handler provider',
32
      'description' => 'Test the YouTube handler provider.',
33
      'group' => 'Media YouTube',
34
    );
35
  }
36

    
37
  function setUp() {
38
    parent::setUp('media_youtube_test');
39

    
40
    // Disable the private file system which is automatically enabled by
41
    // DrupalTestCase so we can test the upload wizard correctly.
42
    variable_del('file_private_path');
43

    
44
    $web_user = $this->drupalCreateUser(array('create files', 'add media from remote sources', 'edit own video files'));
45
    $this->drupalLogin($web_user);
46
  }
47

    
48
  /**
49
   * Tests YouTube file handler.
50
   */
51
  function testYouTubeFileHandling() {
52
    // Step 1: Add a video file by providing a URL to the resource on YouTube.
53
    $edit = array();
54
    $edit['embed_code'] = 'https://www.youtube.com/watch?v=9g2U12SsRns';
55
    $this->drupalPost('file/add/web', $edit, t('Next'));
56

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

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

    
65
    // Verify that the video formatter is used to render the full video.
66
    $video_info = array(
67
      'uri' => $file->uri,
68
      'options' => array(
69
        'width' => 640,
70
        'height' => 390,
71
        'autohide' => 2,
72
        'autoplay' => FALSE,
73
        'color' => 'red',
74
        'enablejsapi' => FALSE,
75
        'loop' => FALSE,
76
        'modestbranding' => FALSE,
77
        'nocookie' => FALSE,
78
        'origin' => '',
79
        'protocol' => 'https:',
80
        'protocol_specify' => FALSE,
81
        'rel' => FALSE,
82
        'controls' => FALSE,
83
        'showinfo' => TRUE,
84
        'theme' => 'dark',
85
        'captions' => FALSE,
86
      ),
87
    );
88
    $default_output = theme('media_youtube_video', $video_info);
89
    $this->assertRaw($default_output, 'Video displayed using the Media: YouTube Video formatter.');
90

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

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