1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Functionality tests for Menu attributes.
|
6
|
*
|
7
|
* @ingroup menu_attributes
|
8
|
*/
|
9
|
|
10
|
/**
|
11
|
* Helper test class with some added functions for testing.
|
12
|
*/
|
13
|
class MenuAttributesTestHelper extends DrupalWebTestCase {
|
14
|
protected $admin_user;
|
15
|
protected $menu_attributes_new;
|
16
|
protected $menu_attributes_edit;
|
17
|
|
18
|
function setUp(array $modules = array()) {
|
19
|
$modules[] = 'menu';
|
20
|
$modules[] = 'menu_attributes';
|
21
|
parent::setUp($modules);
|
22
|
|
23
|
// Create and login user.
|
24
|
$this->admin_user = $this->drupalCreateUser(array(
|
25
|
'administer menu attributes',
|
26
|
'access administration pages',
|
27
|
'administer content types',
|
28
|
'administer menu',
|
29
|
'create page content',
|
30
|
'edit any page content',
|
31
|
'delete any page content',
|
32
|
));
|
33
|
|
34
|
$this->menu_attributes_new = array(
|
35
|
'title' => $this->randomName(10),
|
36
|
'id' => $this->randomName(10),
|
37
|
'name' => $this->randomName(10),
|
38
|
'rel' => $this->randomName(10),
|
39
|
'class' => $this->randomName(10),
|
40
|
'style' => $this->randomName(10),
|
41
|
'target' => '_top',
|
42
|
'accesskey' => $this->randomName(1),
|
43
|
);
|
44
|
|
45
|
$this->menu_attributes_edit = array(
|
46
|
'title' => $this->randomName(10),
|
47
|
'id' => $this->randomName(10),
|
48
|
'name' => $this->randomName(10),
|
49
|
'rel' => $this->randomName(10),
|
50
|
'class' => $this->randomName(10),
|
51
|
'style' => $this->randomName(10),
|
52
|
'target' => '_self',
|
53
|
'accesskey' => $this->randomName(1),
|
54
|
);
|
55
|
}
|
56
|
|
57
|
/**
|
58
|
* Add or edit a menu link using the menu module UI.
|
59
|
*
|
60
|
* @param integer $plid Parent menu link id.
|
61
|
* @param string $link Link path.
|
62
|
* @param string $menu_name Menu name.
|
63
|
*
|
64
|
* @return array Menu link created.
|
65
|
*/
|
66
|
function crudMenuLink($mlid = 0, $plid = 0, $link = '<front>', $menu_name = 'navigation') {
|
67
|
// View add/edit menu link page.
|
68
|
if (empty($mlid)) {
|
69
|
$this->drupalGet("admin/structure/menu/manage/$menu_name/add");
|
70
|
$menu_attributes = $this->menu_attributes_new;
|
71
|
}
|
72
|
else {
|
73
|
$this->drupalGet("admin/structure/menu/item/$mlid/edit");
|
74
|
$menu_attributes = $this->menu_attributes_edit;
|
75
|
}
|
76
|
$this->assertResponse(200);
|
77
|
|
78
|
$title = '!link_' . $this->randomName(16);
|
79
|
$edit = array(
|
80
|
'link_path' => $link,
|
81
|
'link_title' => $title,
|
82
|
'enabled' => TRUE, // Use this to disable the menu and test.
|
83
|
'expanded' => TRUE, // Setting this to true should test whether it works when we do the std_user tests.
|
84
|
'parent' => $menu_name . ':' . $plid,
|
85
|
'weight' => '0',
|
86
|
'options[attributes][title]' => $menu_attributes['title'],
|
87
|
'options[attributes][id]' => $menu_attributes['id'],
|
88
|
'options[attributes][name]' => $menu_attributes['name'],
|
89
|
'options[attributes][rel]' => $menu_attributes['rel'],
|
90
|
'options[attributes][class]' => $menu_attributes['class'],
|
91
|
'options[attributes][style]' => $menu_attributes['style'],
|
92
|
'options[attributes][target]' => $menu_attributes['target'],
|
93
|
'options[attributes][accesskey]' => $menu_attributes['accesskey'],
|
94
|
);
|
95
|
|
96
|
// Add menu link.
|
97
|
$this->drupalPost(NULL, $edit, t('Save'));
|
98
|
|
99
|
$item = db_query('SELECT * FROM {menu_links} WHERE link_title = :title', array(':title' => $title))->fetchAssoc();
|
100
|
|
101
|
return $item;
|
102
|
}
|
103
|
|
104
|
function assertMenuAttributes($form_parent, $action = 'new') {
|
105
|
if ($action == 'new') {
|
106
|
foreach ($this->menu_attributes_new as $attribute => $value) {
|
107
|
$this->assertFieldByName($form_parent . '[' . $attribute . ']', $value, t("'$attribute' attribute correct in edit form."));
|
108
|
}
|
109
|
}
|
110
|
else {
|
111
|
foreach ($this->menu_attributes_edit as $attribute => $value) {
|
112
|
$this->assertFieldByName($form_parent . '[' . $attribute . ']', $value, t("New '$attribute' attribute correct in edit form."));
|
113
|
}
|
114
|
}
|
115
|
}
|
116
|
}
|
117
|
|
118
|
/**
|
119
|
* Test basic functionality.
|
120
|
*/
|
121
|
class MenuAttributesTestCase extends MenuAttributesTestHelper {
|
122
|
public static function getInfo() {
|
123
|
return array(
|
124
|
'name' => 'Menu attributes',
|
125
|
'description' => 'Tests menu attributes functionality.',
|
126
|
'group' => 'Menu',
|
127
|
);
|
128
|
}
|
129
|
|
130
|
function setUp(array $modules = array()) {
|
131
|
parent::setUp($modules);
|
132
|
}
|
133
|
|
134
|
/**
|
135
|
* Tests menu attributes functionality.
|
136
|
*/
|
137
|
function testMenuAttributes() {
|
138
|
// Login the user.
|
139
|
$this->drupalLogin($this->admin_user);
|
140
|
|
141
|
$menu_name = 'navigation';
|
142
|
|
143
|
// Add a node to be used as a link for menu links.
|
144
|
$node = $this->drupalCreateNode(array('type' => 'page'));
|
145
|
|
146
|
// Add a menu link.
|
147
|
$item = $this->crudMenuLink(0, 0, 'node/' . $node->nid, $menu_name);
|
148
|
|
149
|
$this->drupalGet('admin/structure/menu/item/' . $item['mlid'] . '/edit');
|
150
|
$this->assertMenuAttributes('options[attributes]', 'new');
|
151
|
|
152
|
// Edit the previously created menu link.
|
153
|
$item = $this->crudMenuLink($item['mlid'], 0, 'node/' . $node->nid, $menu_name);
|
154
|
|
155
|
$this->drupalGet('admin/structure/menu/item/' . $item['mlid'] . '/edit');
|
156
|
$this->assertMenuAttributes('options[attributes]', 'edit');
|
157
|
}
|
158
|
}
|
159
|
|
160
|
/**
|
161
|
* Test menu attributes settings for nodes.
|
162
|
*/
|
163
|
class MenuAttributesNodeTestCase extends MenuAttributesTestHelper {
|
164
|
public static function getInfo() {
|
165
|
return array(
|
166
|
'name' => 'Menu attributes settings for nodes',
|
167
|
'description' => 'Add, edit, and delete a node with menu link.',
|
168
|
'group' => 'Menu',
|
169
|
);
|
170
|
}
|
171
|
|
172
|
function setUp(array $modules = array()) {
|
173
|
parent::setUp($modules);
|
174
|
$this->drupalLogin($this->admin_user);
|
175
|
}
|
176
|
|
177
|
/**
|
178
|
* Test creating, editing, deleting menu links via node form widget.
|
179
|
*/
|
180
|
function testMenuNodeFormWidget() {
|
181
|
// Enable Navigation menu as available menu.
|
182
|
$edit = array(
|
183
|
'menu_options[navigation]' => 1,
|
184
|
);
|
185
|
$this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
|
186
|
// Change default parent item to Navigation menu, so we can assert more
|
187
|
// easily.
|
188
|
$edit = array(
|
189
|
'menu_parent' => 'navigation:0',
|
190
|
);
|
191
|
$this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
|
192
|
|
193
|
// Create a node.
|
194
|
$node_title = $this->randomName();
|
195
|
$language = LANGUAGE_NONE;
|
196
|
$edit = array(
|
197
|
"title" => $node_title,
|
198
|
"body[$language][0][value]" => $this->randomString(),
|
199
|
);
|
200
|
$this->drupalPost('node/add/page', $edit, t('Save'));
|
201
|
$node = $this->drupalGetNodeByTitle($node_title);
|
202
|
// Assert that there is no link for the node.
|
203
|
$this->drupalGet('');
|
204
|
$this->assertNoLink($node_title);
|
205
|
|
206
|
// Edit the node, enable the menu link setting, but skip the link title.
|
207
|
$edit = array(
|
208
|
'menu[enabled]' => 1,
|
209
|
);
|
210
|
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
|
211
|
// Assert that there is no link for the node.
|
212
|
$this->drupalGet('');
|
213
|
$this->assertNoLink($node_title);
|
214
|
|
215
|
// Edit the node and create a menu link with attributes.
|
216
|
$edit = array(
|
217
|
'menu[enabled]' => 1,
|
218
|
'menu[link_title]' => $node_title,
|
219
|
'menu[weight]' => 17,
|
220
|
'menu[options][attributes][title]' => $this->menu_attributes_new['title'],
|
221
|
'menu[options][attributes][id]' => $this->menu_attributes_new['id'],
|
222
|
'menu[options][attributes][name]' => $this->menu_attributes_new['name'],
|
223
|
'menu[options][attributes][rel]' => $this->menu_attributes_new['rel'],
|
224
|
'menu[options][attributes][class]' => $this->menu_attributes_new['class'],
|
225
|
'menu[options][attributes][style]' => $this->menu_attributes_new['style'],
|
226
|
'menu[options][attributes][target]' => $this->menu_attributes_new['target'],
|
227
|
'menu[options][attributes][accesskey]' => $this->menu_attributes_new['accesskey'],
|
228
|
);
|
229
|
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
|
230
|
// Assert that the link exists.
|
231
|
$this->drupalGet('');
|
232
|
$this->assertLink($node_title);
|
233
|
|
234
|
// Assert that the link attributes exist.
|
235
|
$this->drupalGet('node/' . $node->nid . '/edit');
|
236
|
$this->assertMenuAttributes('menu[options][attributes]', 'new');
|
237
|
|
238
|
// Edit the node again and change the menu link attributes.
|
239
|
$edit = array(
|
240
|
'menu[enabled]' => 1,
|
241
|
'menu[link_title]' => $node_title,
|
242
|
'menu[weight]' => 17,
|
243
|
'menu[options][attributes][title]' => $this->menu_attributes_edit['title'],
|
244
|
'menu[options][attributes][id]' => $this->menu_attributes_edit['id'],
|
245
|
'menu[options][attributes][name]' => $this->menu_attributes_edit['name'],
|
246
|
'menu[options][attributes][rel]' => $this->menu_attributes_edit['rel'],
|
247
|
'menu[options][attributes][class]' => $this->menu_attributes_edit['class'],
|
248
|
'menu[options][attributes][style]' => $this->menu_attributes_edit['style'],
|
249
|
'menu[options][attributes][target]' => $this->menu_attributes_edit['target'],
|
250
|
'menu[options][attributes][accesskey]' => $this->menu_attributes_edit['accesskey'],
|
251
|
);
|
252
|
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
|
253
|
|
254
|
// Assert that the link attributes exist.
|
255
|
$this->drupalGet('node/' . $node->nid . '/edit');
|
256
|
$this->assertMenuAttributes('menu[options][attributes]', 'edit');
|
257
|
|
258
|
// Edit the node and remove the menu link.
|
259
|
$edit = array(
|
260
|
'menu[enabled]' => FALSE,
|
261
|
);
|
262
|
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
|
263
|
// Assert that there is no link for the node.
|
264
|
$this->drupalGet('');
|
265
|
$this->assertNoLink($node_title);
|
266
|
}
|
267
|
}
|