1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Tests for media_internet.module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Provides methods specifically for testing Media Internet module's remote media handling.
|
10
|
*/
|
11
|
class MediaInternetTestHelper extends DrupalWebTestCase {
|
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_internet';
|
21
|
parent::setUp($modules);
|
22
|
}
|
23
|
|
24
|
/**
|
25
|
* Get a file from the database based on its filename.
|
26
|
*
|
27
|
* @param $filename
|
28
|
* A file filename, usually generated by $this->randomName().
|
29
|
* @param $reset
|
30
|
* (optional) Whether to reset the internal file_load() cache.
|
31
|
*
|
32
|
* @return
|
33
|
* A file object matching $filename.
|
34
|
*/
|
35
|
function getFileByFilename($filename, $reset = FALSE) {
|
36
|
$files = file_load_multiple(array(), array('filename' => $filename), $reset);
|
37
|
// Load the first file returned from the database.
|
38
|
$returned_file = reset($files);
|
39
|
return $returned_file;
|
40
|
}
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* Tests the media browser 'Web' tab.
|
45
|
*/
|
46
|
class MediaInternetBrowserWebTabTestCase extends MediaInternetTestHelper {
|
47
|
public static function getInfo() {
|
48
|
return array(
|
49
|
'name' => 'Media browser web tab test',
|
50
|
'description' => 'Tests the media browser web tab.',
|
51
|
'group' => 'Media Internet',
|
52
|
'dependencies' => array('fake'), // @todo remove when File Entity > alpha3 is released. This test currently fails on drupal.org due to testbot dependency issues.
|
53
|
);
|
54
|
}
|
55
|
|
56
|
function setUp() {
|
57
|
parent::setUp();
|
58
|
|
59
|
$web_user = $this->drupalCreateUser(array('access media browser', 'add media from remote sources'));
|
60
|
$this->drupalLogin($web_user);
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* Tests that the views sorting works on the media browser 'Library' tab.
|
65
|
*/
|
66
|
function testMediaBrowserWebTab() {
|
67
|
// Load only the 'Library' tab of the media browser.
|
68
|
$options = array(
|
69
|
'query' => array(
|
70
|
'enabledPlugins' => array(
|
71
|
'media_internet' => 'media_internet',
|
72
|
),
|
73
|
),
|
74
|
);
|
75
|
|
76
|
$this->drupalGet('media/browser', $options);
|
77
|
$this->assertResponse(200);
|
78
|
|
79
|
// Check that the web tab is available and has an 'embed code' field.
|
80
|
$this->assertRaw(t('Web'), t('The web tab was found.'));
|
81
|
$this->assertFieldByName('embed_code', '', t('Embed code form field found.'));
|
82
|
}
|
83
|
}
|
84
|
|
85
|
/**
|
86
|
* Test file creation through the file upload wizard with remote media.
|
87
|
*/
|
88
|
class MediaInternetCreationTestCase extends MediaInternetTestHelper {
|
89
|
public static function getInfo() {
|
90
|
return array(
|
91
|
'name' => 'Remote media file creation',
|
92
|
'description' => 'Test file creation with remote media.',
|
93
|
'group' => 'Media Internet',
|
94
|
'dependencies' => array('fake'), // @todo remove when File Entity > alpha3 is released. This test currently fails on drupal.org due to testbot dependency issues.
|
95
|
);
|
96
|
}
|
97
|
|
98
|
function setUp() {
|
99
|
parent::setUp();
|
100
|
|
101
|
$web_user = $this->drupalCreateUser(array('create files', 'add media from remote sources', 'edit own document files'));
|
102
|
$this->drupalLogin($web_user);
|
103
|
}
|
104
|
|
105
|
/**
|
106
|
* Tests file creation with remote media.
|
107
|
*/
|
108
|
function testRemoteMediaFileCreation() {
|
109
|
// Create a file.
|
110
|
$edit = array();
|
111
|
$edit['embed_code'] = file_create_url('README.txt');
|
112
|
$this->drupalPost('file/add/web', $edit, t('Next'));
|
113
|
|
114
|
// Step 2: Scheme selection
|
115
|
if ($this->xpath('//input[@name="scheme"]')) {
|
116
|
$this->drupalPost(NULL, array(), t('Next'));
|
117
|
}
|
118
|
|
119
|
// Check that the document file has been uploaded.
|
120
|
$this->assertRaw(t('!type %name was uploaded.', array('!type' => 'Document', '%name' => 'README.txt')), t('Document file uploaded.'));
|
121
|
|
122
|
// Check that the file exists in the database.
|
123
|
$file = $this->getFileByFilename('README.txt');
|
124
|
$this->assertTrue($file, t('File found in database.'));
|
125
|
}
|
126
|
}
|
127
|
|
128
|
/**
|
129
|
* Tests custom media provider APIs.
|
130
|
*/
|
131
|
class MediaInternetProviderTestCase extends MediaInternetTestHelper {
|
132
|
public static function getInfo() {
|
133
|
return array(
|
134
|
'name' => 'Custom media provider test',
|
135
|
'description' => 'Tests the custom media provider APIs.',
|
136
|
'group' => 'Media Internet',
|
137
|
'dependencies' => array('fake'), // @todo remove when File Entity > alpha3 is released. This test currently fails on drupal.org due to testbot dependency issues.
|
138
|
);
|
139
|
}
|
140
|
|
141
|
function setUp() {
|
142
|
parent::setUp('media_internet_test');
|
143
|
|
144
|
$web_user = $this->drupalCreateUser(array('access media browser', 'create files', 'add media from remote sources', 'edit own video files'));
|
145
|
$this->drupalLogin($web_user);
|
146
|
}
|
147
|
|
148
|
/**
|
149
|
* Tests file creation with a custom media provider.
|
150
|
*/
|
151
|
function testFilesBrowserSort() {
|
152
|
$this->drupalGet('file/add/web');
|
153
|
$this->assertResponse(200);
|
154
|
|
155
|
// Check that the provider is listed as supported.
|
156
|
$supported_providers = 'Media Internet Test';
|
157
|
$this->assertRaw(t('Supported internet media providers: !providers.', array('!providers' => '<strong>' . $supported_providers . '</strong>')), t('The example media provider is enabled.'));
|
158
|
|
159
|
// Create a file.
|
160
|
$edit = array();
|
161
|
$edit['embed_code'] = 'http://www.example.com/video/123';
|
162
|
$this->drupalPost('file/add/web', $edit, t('Next'));
|
163
|
|
164
|
// Step 2: Scheme selection
|
165
|
if ($this->xpath('//input[@name="scheme"]')) {
|
166
|
$this->drupalPost(NULL, array(), t('Next'));
|
167
|
}
|
168
|
|
169
|
// Check that the video file has been uploaded.
|
170
|
$this->assertRaw(t('!type %name was uploaded.', array('!type' => 'Video', '%name' => 'Drupal')), t('Video file uploaded.'));
|
171
|
|
172
|
// Check that the file exists in the database.
|
173
|
$file = $this->getFileByFilename('Drupal');
|
174
|
$this->assertTrue($file, t('File found in database.'));
|
175
|
}
|
176
|
}
|