1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Tests for media_ckeditor.module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Defines base class for media test cases.
|
10
|
*/
|
11
|
abstract class MediaCkeditorTestHelper extends DrupalWebTestCase {
|
12
|
|
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_ckeditor';
|
22
|
$modules[] = 'media_wysiwyg';
|
23
|
$modules[] = 'media';
|
24
|
$modules[] = 'file_entity';
|
25
|
$modules[] = 'token';
|
26
|
$modules[] = 'views';
|
27
|
$modules[] = 'ctools';
|
28
|
|
29
|
parent::setUp($modules);
|
30
|
}
|
31
|
|
32
|
/**
|
33
|
* Generates markup to be inserted for a file.
|
34
|
*
|
35
|
* This is a PHP version of InsertMedia.insert() from js/wysiwyg-media.js.
|
36
|
*
|
37
|
* @param int $fid
|
38
|
* Drupal file id.
|
39
|
* @param int $count
|
40
|
* Quantity of markup to insert.
|
41
|
* @param array $attributes
|
42
|
* Extra attributes to insert.
|
43
|
* @param array $fields
|
44
|
* Extra field values to insert.
|
45
|
*
|
46
|
* @return string
|
47
|
* Filter markup.
|
48
|
*/
|
49
|
protected function generateJsonTokenMarkup($fid, $count = 1, array $attributes = array(), array $fields = array()) {
|
50
|
$markup = '';
|
51
|
// Merge default atttributes.
|
52
|
$attributes += array(
|
53
|
'height' => 100,
|
54
|
'width' => 100,
|
55
|
'classes' => 'media-element file_preview',
|
56
|
);
|
57
|
|
58
|
// Build the data that is used in a media tag.
|
59
|
$data = array(
|
60
|
'fid' => $fid,
|
61
|
'type' => 'media',
|
62
|
'view_mode' => 'preview',
|
63
|
'attributes' => $attributes,
|
64
|
'fields' => $fields,
|
65
|
);
|
66
|
|
67
|
// Create the file usage markup.
|
68
|
for ($i = 1; $i <= $count; $i++) {
|
69
|
$markup .= '<p>[[' . drupal_json_encode($data) . ']]</p>';
|
70
|
}
|
71
|
|
72
|
return $markup;
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* Utility function to create a test node.
|
77
|
*
|
78
|
* @param array $fields
|
79
|
* Extra field values to insert.
|
80
|
*
|
81
|
* @return int
|
82
|
* Returns the node id
|
83
|
*/
|
84
|
protected function createNode(array $fields = array()) {
|
85
|
$markup = 'test';
|
86
|
// If (! empty($fid)) {
|
87
|
// $markup = $this->generateJsonTokenMarkup($fid, 1, $attributes, $fields);
|
88
|
// }
|
89
|
// Create an article node with file markup in the body field.
|
90
|
$edit = array(
|
91
|
'title' => $this->randomName(8),
|
92
|
'body[und][0][value]' => $markup,
|
93
|
);
|
94
|
// Save the article node. First argument is the URL, then the value array
|
95
|
// and the third is the label the button that should be "clicked".
|
96
|
$this->drupalPost('node/add/article', $edit, t('Save'));
|
97
|
|
98
|
// Get the article node that was saved by the unique title.
|
99
|
$node = $this->drupalGetNodeByTitle($edit['title']);
|
100
|
return $node->nid;
|
101
|
}
|
102
|
|
103
|
}
|
104
|
|
105
|
/**
|
106
|
* Defines base class for media_ckeditor_view_mode test cases.
|
107
|
*/
|
108
|
class MediaCkeditorViewModeTestHelper extends MediaCkeditorTestHelper {
|
109
|
|
110
|
/**
|
111
|
* Get information function.
|
112
|
*/
|
113
|
public static function getInfo() {
|
114
|
return array(
|
115
|
'name' => 'Media Ckeditor ViewMode test',
|
116
|
'description' => 'Tests the media ckeditor ViewMode.',
|
117
|
'group' => 'Media',
|
118
|
);
|
119
|
}
|
120
|
|
121
|
/**
|
122
|
* Set up function.
|
123
|
*/
|
124
|
public function setUp() {
|
125
|
parent::setUp();
|
126
|
|
127
|
/* Reset the permissions cache prior to calling drupalCreateUser
|
128
|
* see notes here: https://api.drupal.org/comment/28739#comment-28739
|
129
|
*/
|
130
|
$this->checkPermissions(array(), TRUE);
|
131
|
|
132
|
$web_user = $this->drupalCreateUser(array(
|
133
|
'access administration pages',
|
134
|
'administer file types',
|
135
|
'view files',
|
136
|
'use media wysiwyg',
|
137
|
'create article content',
|
138
|
'edit own article content',
|
139
|
'edit any article content',
|
140
|
'administer nodes',
|
141
|
));
|
142
|
$this->drupalLogin($web_user);
|
143
|
|
144
|
}
|
145
|
|
146
|
/**
|
147
|
* Tests the behavior of node and file deletion.
|
148
|
*/
|
149
|
public function testCreateNodeAndDelete() {
|
150
|
// Create a new node with file markup.
|
151
|
$nid = $this->createNode(array('test_field'));
|
152
|
|
153
|
// Delete the node.
|
154
|
node_delete($nid);
|
155
|
$node = node_load($nid);
|
156
|
$this->assertEqual(empty($node), TRUE, t('Node has been deleted.'));
|
157
|
}
|
158
|
|
159
|
}
|