1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
<?php
/**
* @file
* Tests for media_bulk_upload.module.
*/
/**
* Provides methods specifically for testing Media Bulk Upload module's bulk file uploading capabilities.
*/
class MediaBulkUploadTestHelper extends DrupalWebTestCase {
function setUp() {
// Since this is a base class for many test cases, support the same
// flexibility that DrupalWebTestCase::setUp() has for the modules to be
// passed in as either an array or a variable number of string arguments.
$modules = func_get_args();
if (isset($modules[0]) && is_array($modules[0])) {
$modules = $modules[0];
}
$modules[] = 'media_bulk_upload';
parent::setUp($modules);
}
/**
* Retrieves a sample file of the specified type.
*/
function getTestFile($type_name, $size = NULL) {
// Get a file to upload.
$file = current($this->drupalGetTestFiles($type_name, $size));
// Add a filesize property to files as would be read by file_load().
$file->filesize = filesize($file->uri);
return $file;
}
/**
* Get a file from the database based on its filename.
*
* @param $filename
* A file filename, usually generated by $this->randomName().
* @param $reset
* (optional) Whether to reset the internal file_load() cache.
*
* @return
* A file object matching $filename.
*/
function getFileByFilename($filename, $reset = FALSE) {
$files = file_load_multiple(array(), array('filename' => $filename), $reset);
// Load the first file returned from the database.
$returned_file = reset($files);
return $returned_file;
}
}
/**
* Test bulk file editing.
*/
class MediaBulkUploadEditTestCase extends MediaBulkUploadTestHelper {
public static function getInfo() {
return array(
'name' => 'Bulk file editing',
'description' => 'Test file editing with multiple files.',
'group' => 'Media Bulk Upload',
'dependencies' => array('multiform', 'plupload'),
);
}
function setUp() {
parent::setUp();
$web_user = $this->drupalCreateUser(array('create files', 'edit any document files', 'edit any image files'));
$this->drupalLogin($web_user);
}
/**
* Tests editing with multiple files.
*/
function testBulkFileEditing() {
$files = array();
// Create multiple files for testing.
foreach (array('image', 'text') as $type_name) {
$test_file = $this->getTestFile($type_name);
$file = file_save($test_file);
$files[$file->fid] = $file;
}
// Visit the bulk file edit page and verify that it performs as expected.
$path = media_bulk_upload_file_edit_url(array_keys($files));
$this->drupalGet($path);
foreach ($files as $file) {
// Verify that a filename for each file is present on the page.
$title = t('<em>Edit @type</em> @title', array('@type' => $file->type, '@title' => $file->filename));
$this->assertRaw('<h2>' . $title . '</h2>', 'The file has the correct filename.');
// Verify that the 'replace file' functionality is disabled.
$this->assertNoField('multiform[media_edit_' . $file->fid . '_' . ($file->fid - 1) . '][files][replace_upload]', 'Replace file field found.');
// Verify that the action buttons have been removed.
$this->assertNoLinkByHref('file/' . $file->fid);
}
}
}
|