Revision 2b3c8cc1
Added by Assos Assos about 9 years ago
drupal7/sites/all/modules/media/modules/media_internet/tests/media_internet.test | ||
---|---|---|
21 | 21 |
parent::setUp($modules); |
22 | 22 |
} |
23 | 23 |
|
24 |
/** |
|
25 |
* Retrieves a sample file of the specified type. |
|
26 |
*/ |
|
27 |
function getTestFile($type_name, $size = NULL) { |
|
28 |
// Get a file to upload. |
|
29 |
$file = current($this->drupalGetTestFiles($type_name, $size)); |
|
30 |
|
|
31 |
// Add a filesize property to files as would be read by file_load(). |
|
32 |
$file->filesize = filesize($file->uri); |
|
33 |
|
|
34 |
return $file; |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* Retrieves the fid of the last inserted file. |
|
39 |
*/ |
|
40 |
function getLastFileId() { |
|
41 |
return (int) db_query('SELECT MAX(fid) FROM {file_managed}')->fetchField(); |
|
42 |
} |
|
43 |
|
|
24 | 44 |
/** |
25 | 45 |
* Get a file from the database based on its filename. |
26 | 46 |
* |
... | ... | |
38 | 58 |
$returned_file = reset($files); |
39 | 59 |
return $returned_file; |
40 | 60 |
} |
61 |
|
|
62 |
protected function createFileType($overrides = array()) { |
|
63 |
$type = new stdClass(); |
|
64 |
$type->type = 'test'; |
|
65 |
$type->label = "Test"; |
|
66 |
$type->description = ''; |
|
67 |
$type->mimetypes = array('image/jpeg', 'image/gif', 'image/png', 'image/tiff'); |
|
68 |
|
|
69 |
foreach ($overrides as $k => $v) { |
|
70 |
$type->$k = $v; |
|
71 |
} |
|
72 |
|
|
73 |
file_type_save($type); |
|
74 |
return $type; |
|
75 |
} |
|
41 | 76 |
} |
42 | 77 |
|
43 | 78 |
/** |
... | ... | |
49 | 84 |
'name' => 'Media browser web tab test', |
50 | 85 |
'description' => 'Tests the media browser web tab.', |
51 | 86 |
'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 | 87 |
); |
54 | 88 |
} |
55 | 89 |
|
... | ... | |
83 | 117 |
} |
84 | 118 |
|
85 | 119 |
/** |
86 |
* Test file creation through the file upload wizard with remote media.
|
|
120 |
* Test the default MediaInternetFileHandler provider.
|
|
87 | 121 |
*/ |
88 |
class MediaInternetCreationTestCase extends MediaInternetTestHelper {
|
|
122 |
class MediaInternetRemoteFileTestCase extends MediaInternetTestHelper {
|
|
89 | 123 |
public static function getInfo() { |
90 | 124 |
return array( |
91 |
'name' => 'Remote media file creation',
|
|
92 |
'description' => 'Test file creation with remote media.',
|
|
125 |
'name' => 'Remote media file handler provider',
|
|
126 |
'description' => 'Test the default remote file handler provider.',
|
|
93 | 127 |
'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 | 128 |
); |
96 | 129 |
} |
97 | 130 |
|
98 | 131 |
function setUp() { |
99 | 132 |
parent::setUp(); |
100 | 133 |
|
101 |
$web_user = $this->drupalCreateUser(array('create files', 'add media from remote sources', 'edit own document files')); |
|
134 |
// Disable the private file system which is automatically enabled by |
|
135 |
// DrupalTestCase so we can test the upload wizard correctly. |
|
136 |
variable_del('file_private_path'); |
|
137 |
|
|
138 |
$web_user = $this->drupalCreateUser(array('create files', 'add media from remote sources')); |
|
102 | 139 |
$this->drupalLogin($web_user); |
103 | 140 |
} |
104 | 141 |
|
105 | 142 |
/** |
106 |
* Tests file creation with remote media.
|
|
143 |
* Tests the default remote file handler.
|
|
107 | 144 |
*/ |
108 |
function testRemoteMediaFileCreation() {
|
|
109 |
// Create a file.
|
|
145 |
function testRemoteFileHandling() {
|
|
146 |
// Step 1: Add a basic document file by providing a URL to the file.
|
|
110 | 147 |
$edit = array(); |
111 | 148 |
$edit['embed_code'] = file_create_url('README.txt'); |
112 | 149 |
$this->drupalPost('file/add/web', $edit, t('Next')); |
113 | 150 |
|
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 | 151 |
// Check that the file exists in the database. |
123 |
$file = $this->getFileByFilename('README.txt'); |
|
152 |
$fid = $this->getLastFileId(); |
|
153 |
$file = file_load($fid); |
|
124 | 154 |
$this->assertTrue($file, t('File found in database.')); |
155 |
|
|
156 |
// Check that the video file has been uploaded. |
|
157 |
$this->assertRaw(t('!type %name was uploaded.', array('!type' => 'Document', '%name' => $file->filename)), t('Document file uploaded.')); |
|
125 | 158 |
} |
126 | 159 |
} |
127 | 160 |
|
... | ... | |
134 | 167 |
'name' => 'Custom media provider test', |
135 | 168 |
'description' => 'Tests the custom media provider APIs.', |
136 | 169 |
'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 | 170 |
); |
139 | 171 |
} |
140 | 172 |
|
141 | 173 |
function setUp() { |
142 | 174 |
parent::setUp('media_internet_test'); |
143 | 175 |
|
144 |
$web_user = $this->drupalCreateUser(array('access media browser', 'create files', 'add media from remote sources', 'edit own video files')); |
|
176 |
// Disable the private file system which is automatically enabled by |
|
177 |
// DrupalTestCase so we can test the upload wizard correctly. |
|
178 |
variable_del('file_private_path'); |
|
179 |
|
|
180 |
// Enable media_internet_test.module's hook_media_internet_providers() |
|
181 |
// implementation. |
|
182 |
variable_set('media_internet_test_media_internet_providers', TRUE); |
|
183 |
|
|
184 |
$web_user = $this->drupalCreateUser(array('create files', 'view own private files', 'add media from remote sources')); |
|
145 | 185 |
$this->drupalLogin($web_user); |
146 | 186 |
} |
147 | 187 |
|
148 | 188 |
/** |
149 |
* Tests file creation with a custom media provider.
|
|
189 |
* Test the basic file upload wizard functionality.
|
|
150 | 190 |
*/ |
151 |
function testFilesBrowserSort() {
|
|
191 |
function testMediaInternetCustomProviderWizardBasic() {
|
|
152 | 192 |
$this->drupalGet('file/add/web'); |
153 | 193 |
$this->assertResponse(200); |
154 | 194 |
|
155 | 195 |
// 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.')); |
|
196 |
$this->assertRaw(t('Supported internet media providers: !providers.', array('!providers' => '<strong>' . 'Media Internet Test' . '</strong>')), t('The example media provider is enabled.')); |
|
158 | 197 |
|
159 |
// Create a file. |
|
198 |
// Enable media_internet_test.module's |
|
199 |
// hook_media_browser_plugin_info_alter_alter() implementation and ensure it |
|
200 |
// is working as designed. |
|
201 |
variable_set('media_internet_test_media_internet_providers_alter', TRUE); |
|
202 |
|
|
203 |
$this->drupalGet('file/add/web'); |
|
204 |
$this->assertRaw(t('Supported internet media providers: !providers.', array('!providers' => '<strong>' . 'Altered provider title' . '</strong>')), t('The example media provider was successfully altered.')); |
|
205 |
|
|
206 |
// Step 1: Upload a basic video file. |
|
160 | 207 |
$edit = array(); |
161 | 208 |
$edit['embed_code'] = 'http://www.example.com/video/123'; |
162 | 209 |
$this->drupalPost('file/add/web', $edit, t('Next')); |
163 | 210 |
|
164 |
// Step 2: Scheme selection |
|
165 |
if ($this->xpath('//input[@name="scheme"]')) { |
|
166 |
$this->drupalPost(NULL, array(), t('Next')); |
|
167 |
} |
|
211 |
// Check that the file exists in the database. |
|
212 |
$fid = $this->getLastFileId(); |
|
213 |
$file = file_load($fid); |
|
214 |
$this->assertTrue($file, t('File found in database.')); |
|
215 |
|
|
216 |
// Check that the video file has been uploaded. |
|
217 |
$this->assertRaw(t('!type %name was uploaded.', array('!type' => 'Video', '%name' => $file->filename)), t('Video file uploaded.')); |
|
218 |
} |
|
219 |
|
|
220 |
/** |
|
221 |
* Test the file upload wizard type step. |
|
222 |
*/ |
|
223 |
function testMediaInternetCustomProviderWizardTypes() { |
|
224 |
// Create multiple file types with the same mime types. |
|
225 |
$this->createFileType(array('type' => 'video1', 'label' => 'Video 1', 'mimetypes' => array('video/mediainternettest'))); |
|
226 |
$this->createFileType(array('type' => 'video2', 'label' => 'Video 2', 'mimetypes' => array('video/mediainternettest'))); |
|
227 |
|
|
228 |
// Step 1: Upload a basic video file. |
|
229 |
$edit = array(); |
|
230 |
$edit['embed_code'] = 'http://www.example.com/video/123'; |
|
231 |
$this->drupalPost('file/add/web', $edit, t('Next')); |
|
232 |
|
|
233 |
// Step 2: File type selection. |
|
234 |
$edit = array(); |
|
235 |
$edit['type'] = 'video2'; |
|
236 |
$this->drupalPost(NULL, $edit, t('Next')); |
|
237 |
|
|
238 |
// Check that the file exists in the database. |
|
239 |
$fid = $this->getLastFileId(); |
|
240 |
$file = file_load($fid); |
|
241 |
$this->assertTrue($file, t('File found in database.')); |
|
242 |
|
|
243 |
// Check that the video file has been uploaded. |
|
244 |
$this->assertRaw(t('!type %name was uploaded.', array('!type' => 'Video 2', '%name' => $file->filename)), t('Video 2 file uploaded.')); |
|
245 |
} |
|
246 |
|
|
247 |
/** |
|
248 |
* Test the file upload wizard scheme step. |
|
249 |
*/ |
|
250 |
function testMediaInternetCustomProviderWizardSchemes() { |
|
251 |
// Enable the private file system. |
|
252 |
variable_set('file_private_path', $this->private_files_directory); |
|
253 |
|
|
254 |
// Step 1: Upload a basic video file. |
|
255 |
$edit = array(); |
|
256 |
$edit['embed_code'] = 'http://www.example.com/video/123'; |
|
257 |
$this->drupalPost('file/add/web', $edit, t('Next')); |
|
258 |
|
|
259 |
// Step 3: Users should not be able to select a scheme for files with |
|
260 |
// read-only stream wrappers. |
|
261 |
$this->assertNoFieldByName('scheme'); |
|
262 |
|
|
263 |
// Check that the file exists in the database. |
|
264 |
$fid = $this->getLastFileId(); |
|
265 |
$file = file_load($fid); |
|
266 |
$this->assertTrue($file, t('File found in database.')); |
|
168 | 267 |
|
169 | 268 |
// 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.')); |
|
269 |
$this->assertRaw(t('!type %name was uploaded.', array('!type' => 'Video', '%name' => $file->filename)), t('Video file uploaded.')); |
|
270 |
} |
|
271 |
|
|
272 |
/** |
|
273 |
* Test the file upload wizard field step. |
|
274 |
*/ |
|
275 |
function testMediaInternetCustomProviderWizardFields() { |
|
276 |
$filename = $this->randomName(); |
|
277 |
|
|
278 |
// Add a text field to the video file type. |
|
279 |
$field_name = drupal_strtolower($this->randomName() . '_field_name'); |
|
280 |
$field = array('field_name' => $field_name, 'type' => 'text'); |
|
281 |
field_create_field($field); |
|
282 |
$instance = array( |
|
283 |
'field_name' => $field_name, |
|
284 |
'entity_type' => 'file', |
|
285 |
'bundle' => 'video', |
|
286 |
'label' => $this->randomName() . '_label', |
|
287 |
); |
|
288 |
field_create_instance($instance); |
|
289 |
|
|
290 |
// Step 1: Upload a basic video file. |
|
291 |
$edit = array(); |
|
292 |
$edit['embed_code'] = 'http://www.example.com/video/123'; |
|
293 |
$this->drupalPost('file/add/web', $edit, t('Next')); |
|
294 |
|
|
295 |
// Step 4: Attached fields. |
|
296 |
$edit = array(); |
|
297 |
$edit['filename'] = $filename; |
|
298 |
$edit[$field_name . '[' . LANGUAGE_NONE . '][0][value]'] = $this->randomName(); |
|
299 |
$this->drupalPost(NULL, $edit, t('Save')); |
|
171 | 300 |
|
172 | 301 |
// Check that the file exists in the database. |
173 |
$file = $this->getFileByFilename('Drupal'); |
|
302 |
$fid = $this->getLastFileId(); |
|
303 |
$file = file_load($fid); |
|
174 | 304 |
$this->assertTrue($file, t('File found in database.')); |
305 |
|
|
306 |
// Check that the video file has been uploaded. |
|
307 |
$this->assertRaw(t('!type %name was uploaded.', array('!type' => 'Video', '%name' => $filename)), t('Video file uploaded.')); |
|
308 |
} |
|
309 |
|
|
310 |
/** |
|
311 |
* Test skipping each of the file upload wizard steps. |
|
312 |
*/ |
|
313 |
function testMediaInternetCustomProviderWizardStepSkipping() { |
|
314 |
$filename = $this->randomName(); |
|
315 |
|
|
316 |
// Ensure that the file is affected by every step. |
|
317 |
variable_set('file_private_path', $this->private_files_directory); |
|
318 |
|
|
319 |
$this->createFileType(array('type' => 'video1', 'label' => 'Video 1', 'mimetypes' => array('video/mediainternettest'))); |
|
320 |
$this->createFileType(array('type' => 'video2', 'label' => 'Video 2', 'mimetypes' => array('video/mediainternettest'))); |
|
321 |
|
|
322 |
$field_name = drupal_strtolower($this->randomName() . '_field_name'); |
|
323 |
$field = array('field_name' => $field_name, 'type' => 'text'); |
|
324 |
field_create_field($field); |
|
325 |
$instance = array( |
|
326 |
'field_name' => $field_name, |
|
327 |
'entity_type' => 'file', |
|
328 |
'bundle' => 'video2', |
|
329 |
'label' => $this->randomName() . '_label', |
|
330 |
); |
|
331 |
field_create_instance($instance); |
|
332 |
|
|
333 |
// Test skipping each upload wizard step. |
|
334 |
foreach (array('types', 'schemes', 'fields') as $step) { |
|
335 |
// Step to skip. |
|
336 |
switch ($step) { |
|
337 |
case 'types': |
|
338 |
variable_set('file_entity_file_upload_wizard_skip_file_type', TRUE); |
|
339 |
break; |
|
340 |
case 'schemes': |
|
341 |
variable_set('file_entity_file_upload_wizard_skip_scheme', TRUE); |
|
342 |
break; |
|
343 |
case 'fields': |
|
344 |
variable_set('file_entity_file_upload_wizard_skip_fields', TRUE); |
|
345 |
break; |
|
346 |
} |
|
347 |
|
|
348 |
// Step 1: Upload a basic video file. |
|
349 |
$edit = array(); |
|
350 |
$edit['embed_code'] = 'http://www.example.com/video/123'; |
|
351 |
$this->drupalPost('file/add/web', $edit, t('Next')); |
|
352 |
|
|
353 |
// Step 2: File type selection. |
|
354 |
if ($step != 'types') { |
|
355 |
$edit = array(); |
|
356 |
$edit['type'] = 'video2'; |
|
357 |
$this->drupalPost(NULL, $edit, t('Next')); |
|
358 |
} |
|
359 |
|
|
360 |
// Step 3: Users should not be able to select a scheme for files with |
|
361 |
// read-only stream wrappers. |
|
362 |
$this->assertNoFieldByName('scheme'); |
|
363 |
|
|
364 |
// Step 4: Attached fields. |
|
365 |
if ($step != 'fields') { |
|
366 |
// Skipping file type selection essentially skips this step as well |
|
367 |
// because the file will not be assigned a type so no fields will be |
|
368 |
// available. |
|
369 |
if ($step != 'types') { |
|
370 |
$edit = array(); |
|
371 |
$edit['filename'] = $filename; |
|
372 |
$edit[$field_name . '[' . LANGUAGE_NONE . '][0][value]'] = $this->randomName(); |
|
373 |
$this->drupalPost(NULL, $edit, t('Save')); |
|
374 |
} |
|
375 |
} |
|
376 |
|
|
377 |
// Check that the file exists in the database. |
|
378 |
$fid = $this->getLastFileId(); |
|
379 |
$file = file_load($fid); |
|
380 |
$this->assertTrue($file, t('File found in database.')); |
|
381 |
|
|
382 |
// Determine the file's file type. |
|
383 |
$type = file_type_load($file->type); |
|
384 |
|
|
385 |
// Check that the video file has been uploaded. |
|
386 |
$this->assertRaw(t('!type %name was uploaded.', array('!type' => $type->label, '%name' => $file->filename)), t('Video file uploaded.')); |
|
387 |
|
|
388 |
// Reset 'skip' variables. |
|
389 |
variable_del('file_entity_file_upload_wizard_skip_file_type'); |
|
390 |
variable_del('file_entity_file_upload_wizard_skip_scheme'); |
|
391 |
variable_del('file_entity_file_upload_wizard_skip_fields'); |
|
392 |
} |
|
175 | 393 |
} |
176 | 394 |
} |
Also available in: Unified diff
Weekly update of contrib modules