1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Tests for media_bulk_upload.module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Provides methods specifically for testing Media Bulk Upload module's bulk file uploading capabilities.
|
10
|
*/
|
11
|
class MediaBulkUploadTestHelper 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_bulk_upload';
|
21
|
parent::setUp($modules);
|
22
|
}
|
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
|
* Get a file from the database based on its filename.
|
39
|
*
|
40
|
* @param $filename
|
41
|
* A file filename, usually generated by $this->randomName().
|
42
|
* @param $reset
|
43
|
* (optional) Whether to reset the internal file_load() cache.
|
44
|
*
|
45
|
* @return
|
46
|
* A file object matching $filename.
|
47
|
*/
|
48
|
function getFileByFilename($filename, $reset = FALSE) {
|
49
|
$files = file_load_multiple(array(), array('filename' => $filename), $reset);
|
50
|
// Load the first file returned from the database.
|
51
|
$returned_file = reset($files);
|
52
|
return $returned_file;
|
53
|
}
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
* Test bulk file editing.
|
58
|
*/
|
59
|
class MediaBulkUploadEditTestCase extends MediaBulkUploadTestHelper {
|
60
|
public static function getInfo() {
|
61
|
return array(
|
62
|
'name' => 'Bulk file editing',
|
63
|
'description' => 'Test file editing with multiple files.',
|
64
|
'group' => 'Media Bulk Upload',
|
65
|
'dependencies' => array('multiform', 'plupload'),
|
66
|
);
|
67
|
}
|
68
|
|
69
|
function setUp() {
|
70
|
parent::setUp();
|
71
|
|
72
|
$web_user = $this->drupalCreateUser(array('create files', 'edit any document files', 'edit any image files'));
|
73
|
$this->drupalLogin($web_user);
|
74
|
}
|
75
|
|
76
|
/**
|
77
|
* Tests editing with multiple files.
|
78
|
*/
|
79
|
function testBulkFileEditing() {
|
80
|
$files = array();
|
81
|
|
82
|
// Create multiple files for testing.
|
83
|
foreach (array('image', 'text') as $type_name) {
|
84
|
$test_file = $this->getTestFile($type_name);
|
85
|
$file = file_save($test_file);
|
86
|
$files[$file->fid] = $file;
|
87
|
}
|
88
|
|
89
|
// Visit the bulk file edit page and verify that it performs as expected.
|
90
|
$path = media_bulk_upload_file_edit_url(array_keys($files));
|
91
|
$this->drupalGet($path);
|
92
|
|
93
|
foreach ($files as $file) {
|
94
|
// Verify that a filename for each file is present on the page.
|
95
|
$title = t('<em>Edit @type</em> @title', array('@type' => $file->type, '@title' => $file->filename));
|
96
|
$this->assertRaw('<h2>' . $title . '</h2>', 'The file has the correct filename.');
|
97
|
|
98
|
// Verify that the 'replace file' functionality is disabled.
|
99
|
$this->assertNoField('multiform[media_edit_' . $file->fid . '_' . ($file->fid - 1) . '][files][replace_upload]', 'Replace file field found.');
|
100
|
|
101
|
// Verify that the action buttons have been removed.
|
102
|
$this->assertNoLinkByHref('file/' . $file->fid);
|
103
|
}
|
104
|
}
|
105
|
}
|