1 |
ca0757b9
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Tests for media.module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Defines base class for media test cases.
|
10 |
|
|
*/
|
11 |
0ccfec7f
|
Assos Assos
|
abstract class MediaWYSIWYGTestHelper extends DrupalWebTestCase {
|
12 |
ca0757b9
|
Assos Assos
|
|
13 |
|
|
/**
|
14 |
|
|
* Enable media and file entity modules for testing.
|
15 |
|
|
*/
|
16 |
|
|
public function setUp() {
|
17 |
|
|
$modules = func_get_args();
|
18 |
|
|
if (isset($modules[0]) && is_array($modules[0])) {
|
19 |
|
|
$modules = $modules[0];
|
20 |
|
|
}
|
21 |
|
|
$modules[] = 'media_wysiwyg';
|
22 |
|
|
parent::setUp($modules);
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
/**
|
26 |
|
|
* Generates markup to be inserted for a file.
|
27 |
|
|
*
|
28 |
|
|
* This is a PHP version of InsertMedia.insert() from js/wysiwyg-media.js.
|
29 |
|
|
*
|
30 |
|
|
* @param int $fid
|
31 |
|
|
* Drupal file id
|
32 |
|
|
* @param int $count
|
33 |
|
|
* Quantity of markup to insert
|
34 |
|
|
* @param array $attributes
|
35 |
|
|
* Extra attributes to insert.
|
36 |
|
|
* @param array $fields
|
37 |
|
|
* Extra field values to insert.
|
38 |
|
|
*
|
39 |
|
|
* @return string
|
40 |
|
|
* Filter markup.
|
41 |
|
|
*/
|
42 |
|
|
protected function generateJsonTokenMarkup($fid, $count = 1, array $attributes = array(), array $fields = array()) {
|
43 |
|
|
$markup = '';
|
44 |
|
|
// Merge default atttributes.
|
45 |
|
|
$attributes += array(
|
46 |
|
|
'height' => 100,
|
47 |
|
|
'width' => 100,
|
48 |
|
|
'classes' => 'media-element file_preview',
|
49 |
|
|
);
|
50 |
|
|
|
51 |
|
|
// Build the data that is used in a media tag.
|
52 |
|
|
$data = array(
|
53 |
|
|
'fid' => $fid,
|
54 |
|
|
'type' => 'media',
|
55 |
|
|
'view_mode' => 'preview',
|
56 |
|
|
'attributes' => $attributes,
|
57 |
|
|
'fields' => $fields,
|
58 |
|
|
);
|
59 |
|
|
|
60 |
|
|
// Create the file usage markup.
|
61 |
|
|
for ($i = 1; $i <= $count; $i++) {
|
62 |
|
|
$markup .= '<p>[[' . drupal_json_encode($data) . ']]</p>';
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
return $markup;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
/**
|
69 |
|
|
* Utility function to create a test node.
|
70 |
|
|
*
|
71 |
|
|
* @param int $fid
|
72 |
|
|
* Create the node with media markup in the body field
|
73 |
|
|
* @param array $attributes
|
74 |
|
|
* Extra attributes to insert to the file.
|
75 |
|
|
* @param array $fields
|
76 |
|
|
* Extra field values to insert.
|
77 |
|
|
*
|
78 |
|
|
* @return int
|
79 |
|
|
* Returns the node id
|
80 |
|
|
*/
|
81 |
|
|
protected function createNode($fid = FALSE, array $attributes = array(), array $fields = array()) {
|
82 |
|
|
$markup = '';
|
83 |
|
|
if (! empty($fid)) {
|
84 |
|
|
$markup = $this->generateJsonTokenMarkup($fid, 1, $attributes, $fields);
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
// Create an article node with file markup in the body field.
|
88 |
|
|
$edit = array(
|
89 |
|
|
'title' => $this->randomName(8),
|
90 |
|
|
'body[und][0][value]' => $markup,
|
91 |
|
|
);
|
92 |
|
|
// Save the article node. First argument is the URL, then the value array
|
93 |
|
|
// and the third is the label the button that should be "clicked".
|
94 |
|
|
$this->drupalPost('node/add/article', $edit, t('Save'));
|
95 |
|
|
|
96 |
|
|
// Get the article node that was saved by the unique title.
|
97 |
|
|
$node = $this->drupalGetNodeByTitle($edit['title']);
|
98 |
|
|
return $node->nid;
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
}
|
102 |
1e39edcb
|
Assos Assos
|
|
103 |
|
|
/**
|
104 |
|
|
* Defines base class for media_wysiwyg_view_mode test cases.
|
105 |
|
|
*/
|
106 |
|
|
class MediaWYSIWYGViewModeTestHelper extends MediaWYSIWYGTestHelper {
|
107 |
|
|
function setUp() {
|
108 |
|
|
parent::setUp();
|
109 |
|
|
|
110 |
|
|
$web_user = $this->drupalCreateUser(array('access administration pages', 'administer file types', 'view files', 'use media wysiwyg'));
|
111 |
|
|
$this->drupalLogin($web_user);
|
112 |
|
|
}
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
/**
|
116 |
|
|
* Test configuring view modes available on the format form.
|
117 |
|
|
*/
|
118 |
|
|
class FormatFormViewModesTest extends MediaWYSIWYGViewModeTestHelper {
|
119 |
|
|
public static function getInfo() {
|
120 |
|
|
return array(
|
121 |
|
|
'name' => 'Format Form WYSIWYG View Modes',
|
122 |
|
|
'description' => 'Test configuring view modes available on the format form.',
|
123 |
|
|
'group' => 'Media WYSIWYG',
|
124 |
|
|
);
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
function setUp() {
|
128 |
|
|
parent::setUp();
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
/**
|
132 |
|
|
* Configure format form view mode restrictions and ensure that they are followed.
|
133 |
|
|
*/
|
134 |
|
|
function testAllowedFormatFormViewModes() {
|
135 |
|
|
// Create an image file to test with.
|
136 |
|
|
$files = $this->drupalGetTestFiles('image');
|
137 |
|
|
$files[0]->status = FILE_STATUS_PERMANENT;
|
138 |
|
|
$file = file_save($files[0]);
|
139 |
|
|
$fid = $file->fid;
|
140 |
|
|
|
141 |
|
|
// Teaser view mode should be selectable.
|
142 |
|
|
$this->drupalGet('media/' . $fid . '/format-form');
|
143 |
|
|
$this->assertResponse(200);
|
144 |
|
|
$this->assertOption('edit-format', 'teaser');
|
145 |
|
|
|
146 |
|
|
// Restrict the use of the default view mode.
|
147 |
|
|
$this->drupalGet('admin/structure/file-types/manage/image/file-display/teaser');
|
148 |
|
|
$this->assertResponse(200);
|
149 |
|
|
$edit = array(
|
150 |
|
|
'restrict_wysiwyg' => 1,
|
151 |
|
|
);
|
152 |
|
|
$this->drupalPost(NULL, $edit, t('Save configuration'));
|
153 |
|
|
$this->assertResponse(200);
|
154 |
|
|
|
155 |
|
|
// Teaser view mode should be restricted.
|
156 |
|
|
$this->drupalGet('media/' . $fid . '/format-form');
|
157 |
|
|
$this->assertResponse(200);
|
158 |
|
|
$this->assertNoOption('edit-format', 'teaser');
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
/**
|
162 |
|
|
* Assert that a select option in the current page exists.
|
163 |
|
|
*
|
164 |
|
|
* @param $id
|
165 |
|
|
* id of select field to assert.
|
166 |
|
|
* @param $option
|
167 |
|
|
* Option to assert.
|
168 |
|
|
*/
|
169 |
|
|
function assertOption($id, $option, $message = '', $group = 'Browser') {
|
170 |
|
|
$options = $this->xpath('//select[@id=:id]/option[@value=:option]', array(':id' => $id, ':option' => $option));
|
171 |
|
|
return $this->assertTrue(isset($options[0]), $message ? $message : t('Option @option for field @id exists.', array('@option' => $option, '@id' => $id)));
|
172 |
|
|
}
|
173 |
|
|
|
174 |
|
|
/**
|
175 |
|
|
* Assert that a select option in the current page does not exist.
|
176 |
|
|
*
|
177 |
|
|
* @param $id
|
178 |
|
|
* id of select field to assert.
|
179 |
|
|
* @param $option
|
180 |
|
|
* Option to assert.
|
181 |
|
|
*/
|
182 |
|
|
function assertNoOption($id, $option, $message = '', $group = 'Browser') {
|
183 |
|
|
$options = $this->xpath('//select[@id=:id]/option[@value=:option]', array(':id' => $id, ':option' => $option));
|
184 |
|
|
return $this->assertFalse(isset($options[0]), $message ? $message : t('Option @option for field @id does not exist.', array('@option' => $option, '@id' => $id)));
|
185 |
|
|
}
|
186 |
|
|
|
187 |
|
|
} |