Revision b0d73b57
Added by Assos Assos over 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 |
|
|
44 | 24 |
/** |
45 | 25 |
* Get a file from the database based on its filename. |
46 | 26 |
* |
... | ... | |
58 | 38 |
$returned_file = reset($files); |
59 | 39 |
return $returned_file; |
60 | 40 |
} |
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 |
} |
|
76 | 41 |
} |
77 | 42 |
|
78 | 43 |
/** |
... | ... | |
84 | 49 |
'name' => 'Media browser web tab test', |
85 | 50 |
'description' => 'Tests the media browser web tab.', |
86 | 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. |
|
87 | 53 |
); |
88 | 54 |
} |
89 | 55 |
|
... | ... | |
117 | 83 |
} |
118 | 84 |
|
119 | 85 |
/** |
120 |
* Test the default MediaInternetFileHandler provider.
|
|
86 |
* Test file creation through the file upload wizard with remote media.
|
|
121 | 87 |
*/ |
122 |
class MediaInternetRemoteFileTestCase extends MediaInternetTestHelper {
|
|
88 |
class MediaInternetCreationTestCase extends MediaInternetTestHelper {
|
|
123 | 89 |
public static function getInfo() { |
124 | 90 |
return array( |
125 |
'name' => 'Remote media file handler provider',
|
|
126 |
'description' => 'Test the default remote file handler provider.',
|
|
91 |
'name' => 'Remote media file creation',
|
|
92 |
'description' => 'Test file creation with remote media.',
|
|
127 | 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. |
|
128 | 95 |
); |
129 | 96 |
} |
130 | 97 |
|
131 | 98 |
function setUp() { |
132 | 99 |
parent::setUp(); |
133 | 100 |
|
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')); |
|
101 |
$web_user = $this->drupalCreateUser(array('create files', 'add media from remote sources', 'edit own document files')); |
|
139 | 102 |
$this->drupalLogin($web_user); |
140 | 103 |
} |
141 | 104 |
|
142 | 105 |
/** |
143 |
* Tests the default remote file handler.
|
|
106 |
* Tests file creation with remote media.
|
|
144 | 107 |
*/ |
145 |
function testRemoteFileHandling() {
|
|
146 |
// Step 1: Add a basic document file by providing a URL to the file.
|
|
108 |
function testRemoteMediaFileCreation() {
|
|
109 |
// Create a file.
|
|
147 | 110 |
$edit = array(); |
148 | 111 |
$edit['embed_code'] = file_create_url('README.txt'); |
149 | 112 |
$this->drupalPost('file/add/web', $edit, t('Next')); |
150 | 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 |
|
|
151 | 122 |
// Check that the file exists in the database. |
152 |
$fid = $this->getLastFileId(); |
|
153 |
$file = file_load($fid); |
|
123 |
$file = $this->getFileByFilename('README.txt'); |
|
154 | 124 |
$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.')); |
|
158 | 125 |
} |
159 | 126 |
} |
160 | 127 |
|
... | ... | |
167 | 134 |
'name' => 'Custom media provider test', |
168 | 135 |
'description' => 'Tests the custom media provider APIs.', |
169 | 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. |
|
170 | 138 |
); |
171 | 139 |
} |
172 | 140 |
|
173 | 141 |
function setUp() { |
174 | 142 |
parent::setUp('media_internet_test'); |
175 | 143 |
|
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')); |
|
144 |
$web_user = $this->drupalCreateUser(array('access media browser', 'create files', 'add media from remote sources', 'edit own video files')); |
|
185 | 145 |
$this->drupalLogin($web_user); |
186 | 146 |
} |
187 | 147 |
|
188 | 148 |
/** |
189 |
* Test the basic file upload wizard functionality.
|
|
149 |
* Tests file creation with a custom media provider.
|
|
190 | 150 |
*/ |
191 |
function testMediaInternetCustomProviderWizardBasic() {
|
|
151 |
function testFilesBrowserSort() {
|
|
192 | 152 |
$this->drupalGet('file/add/web'); |
193 | 153 |
$this->assertResponse(200); |
194 | 154 |
|
195 | 155 |
// Check that the provider is listed as supported. |
196 |
$this->assertRaw(t('Supported internet media providers: !providers.', array('!providers' => '<strong>' . 'Media Internet Test' . '</strong>')), t('The example media provider is enabled.')); |
|
197 |
|
|
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. |
|
207 |
$edit = array(); |
|
208 |
$edit['embed_code'] = 'http://www.example.com/video/123'; |
|
209 |
$this->drupalPost('file/add/web', $edit, t('Next')); |
|
210 |
|
|
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')); |
|
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.')); |
|
237 | 158 |
|
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. |
|
159 |
// Create a file. |
|
255 | 160 |
$edit = array(); |
256 | 161 |
$edit['embed_code'] = 'http://www.example.com/video/123'; |
257 | 162 |
$this->drupalPost('file/add/web', $edit, t('Next')); |
258 | 163 |
|
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.')); |
|
164 |
// Step 2: Scheme selection |
|
165 |
if ($this->xpath('//input[@name="scheme"]')) { |
|
166 |
$this->drupalPost(NULL, array(), t('Next')); |
|
167 |
} |
|
267 | 168 |
|
268 | 169 |
// Check that the video file has been 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')); |
|
170 |
$this->assertRaw(t('!type %name was uploaded.', array('!type' => 'Video', '%name' => 'Drupal')), t('Video file uploaded.')); |
|
300 | 171 |
|
301 | 172 |
// Check that the file exists in the database. |
302 |
$fid = $this->getLastFileId(); |
|
303 |
$file = file_load($fid); |
|
173 |
$file = $this->getFileByFilename('Drupal'); |
|
304 | 174 |
$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 |
} |
|
393 | 175 |
} |
394 | 176 |
} |
Also available in: Unified diff
Revert media to 2.0-alpha4