1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Tests for Panels IPE.
|
5
|
*/
|
6
|
|
7
|
class PanelizerWithPanelsIPE extends PanelizerTestHelper {
|
8
|
|
9
|
/**
|
10
|
* {@inheritdoc}
|
11
|
*/
|
12
|
public static function getInfo() {
|
13
|
return array(
|
14
|
'name' => 'Panelizer IPE',
|
15
|
'description' => 'Tests for IPE.',
|
16
|
'group' => 'Panelizer',
|
17
|
);
|
18
|
}
|
19
|
|
20
|
/**
|
21
|
* {@inheritdoc}
|
22
|
*/
|
23
|
function setUp(array $modules = array()) {
|
24
|
$modules[] = 'panels_ipe';
|
25
|
parent::setUp($modules);
|
26
|
|
27
|
// Enable Panelizer for the 'page' content type.
|
28
|
$this->togglePanelizer();
|
29
|
// Enable the Panels view mode too.
|
30
|
$this->simpleEnablePage('node_view');
|
31
|
|
32
|
// Reset the static variable used to identify permissions, otherwise the
|
33
|
// permissions check in drupalCreateUser will fail because of the new perms
|
34
|
// added for the newly Panelizered entity display.
|
35
|
$this->checkPermissions(array(), TRUE);
|
36
|
}
|
37
|
|
38
|
/**
|
39
|
* Test whether the IPE 'content' permissions work correctly.
|
40
|
*/
|
41
|
function testIpeContentAccess() {
|
42
|
$perms = array(
|
43
|
// Standard node permissions.
|
44
|
'create page content',
|
45
|
'administer content types',
|
46
|
'administer nodes',
|
47
|
'bypass node access',
|
48
|
|
49
|
'access administration pages',
|
50
|
|
51
|
// Panels IPE.
|
52
|
'use panels in place editing',
|
53
|
|
54
|
// Panelizer.
|
55
|
'administer panelizer',
|
56
|
|
57
|
// Permission to manage the 'content', i.e. the display.
|
58
|
'administer panelizer node page content',
|
59
|
);
|
60
|
$web_user = $this->drupalCreateUser($perms);
|
61
|
$this->drupalLogin($web_user);
|
62
|
|
63
|
// Just 'cause.
|
64
|
drupal_flush_all_caches();
|
65
|
// Create a test node.
|
66
|
$node = $this->createNode();
|
67
|
|
68
|
// Enable IPE for this node.
|
69
|
$this->drupalGet('node/' . $node->nid . '/panelizer/page_manager/settings');
|
70
|
$this->assertResponse(200);
|
71
|
$this->assertFieldByName('pipeline');
|
72
|
$edit = array(
|
73
|
'pipeline' => 'ipe',
|
74
|
);
|
75
|
$this->drupalPost(NULL, $edit, t('Save'));
|
76
|
$this->assertText(t('The settings have been updated.'));
|
77
|
|
78
|
// Load the node view page.
|
79
|
$this->drupalGet('node/' . $node->nid);
|
80
|
$this->assertResponse(200);
|
81
|
|
82
|
// Confirm the IPE link is on the form.
|
83
|
$this->assertLink(t('Customize this page'));
|
84
|
$path = 'panels/ajax/ipe/save_form/panelizer:node:' . $node->nid . ':page_manager:' . $node->vid;
|
85
|
$query_string = array('destination' => 'node/' . $node->nid);
|
86
|
$full_path = url($path, array('query' => array('destination' => $query_string['destination'])));
|
87
|
$this->assertLinkByHref($full_path);
|
88
|
// Confirm the link via xpath.
|
89
|
$xpath = $this->xpath("//a[@id='panels-ipe-customize-page']");
|
90
|
$this->assertEqual(count($xpath), 1, 'Found the "Customize this page" link.');
|
91
|
$this->assertEqual($xpath[0]['href'], $full_path);//, 'The "Customize this Page" link is what was expected.');
|
92
|
|
93
|
// Load the API path when logged in. This should give an AJAX response with
|
94
|
// two commands - the first should be "settings" and the second one should
|
95
|
// be "initIPE".
|
96
|
$json = $this->drupalGetAJAX($path, array('query' => $query_string));
|
97
|
$this->assertResponse(200);
|
98
|
$this->verbose('<pre>' . print_r($json, TRUE) . '</pre>');
|
99
|
// @todo What permission does this need to get a proper response?
|
100
|
$this->assertEqual(count($json), 2);
|
101
|
$this->assertTrue(isset($json[0]['command']));
|
102
|
$this->assertEqual($json[0]['command'], 'settings');
|
103
|
$this->assertTrue(isset($json[0]['settings']));
|
104
|
$this->assertTrue(isset($json[0]['merge']));
|
105
|
$this->assertEqual($json[0]['merge'], 'TRUE');
|
106
|
$this->assertTrue(isset($json[1]['command']));
|
107
|
$this->assertEqual($json[1]['command'], 'initIPE');
|
108
|
$this->assertTrue(isset($json[1]['key']));
|
109
|
$this->assertEqual($json[1]['key'], 'panelizer-node-' . $node->nid . '-page-manager-' . $node->vid);
|
110
|
$this->assertTrue(isset($json[1]['data']));
|
111
|
$this->assertTrue(isset($json[1]['lockPath']));
|
112
|
|
113
|
// Log out.
|
114
|
$this->drupalLogout();
|
115
|
|
116
|
// Load the API path when logged out. This should give a 404-by-AJAX
|
117
|
// response.
|
118
|
$json = $this->drupalGetAJAX($path, array('query' => $query_string));
|
119
|
$this->assertResponse(200);
|
120
|
$this->verbose('<pre>' . print_r($json, TRUE) . '</pre>');
|
121
|
$this->assertEqual(count($json), 2);
|
122
|
$this->assertTrue(isset($json[1]['command']));
|
123
|
$this->assertEqual($json[1]['command'], 'alert');
|
124
|
$this->assertTrue(isset($json[1]['text']));
|
125
|
$this->assertEqual($json[1]['text'], t('You are not authorized to access this page.'));
|
126
|
$this->assertFalse(isset($json[1]['key']));
|
127
|
$this->assertFalse(isset($json[1]['data']));
|
128
|
$this->assertFalse(isset($json[1]['lockPath']));
|
129
|
}
|
130
|
|
131
|
/**
|
132
|
* Test whether the IPE 'layout' permissions work correctly.
|
133
|
*/
|
134
|
function testIpeLayoutAccess() {
|
135
|
$perms = array(
|
136
|
// Standard node permissions.
|
137
|
'create page content',
|
138
|
'administer content types',
|
139
|
'administer nodes',
|
140
|
'bypass node access',
|
141
|
|
142
|
// Panels IPE.
|
143
|
'use panels in place editing',
|
144
|
// Adds the "Change layout" functionality to IPE.
|
145
|
'change layouts in place editing',
|
146
|
|
147
|
// Panelizer.
|
148
|
'administer panelizer',
|
149
|
|
150
|
// Permission to modify the layout.
|
151
|
'administer panelizer node page layout',
|
152
|
);
|
153
|
$web_user = $this->drupalCreateUser($perms);
|
154
|
$this->drupalLogin($web_user);
|
155
|
|
156
|
// Just 'cause.
|
157
|
drupal_flush_all_caches();
|
158
|
|
159
|
// Create a test node.
|
160
|
$node = $this->createNode();
|
161
|
|
162
|
// Enable IPE for this node.
|
163
|
$this->drupalGet('node/' . $node->nid . '/panelizer/page_manager/settings');
|
164
|
$this->assertResponse(200);
|
165
|
$this->assertFieldByName('pipeline');
|
166
|
$edit = array(
|
167
|
'pipeline' => 'ipe',
|
168
|
);
|
169
|
$this->drupalPost(NULL, $edit, t('Save'));
|
170
|
$this->assertText(t('The settings have been updated.'));
|
171
|
|
172
|
// Load the node view page.
|
173
|
$this->drupalGet('node/' . $node->nid);
|
174
|
$this->assertResponse(200);
|
175
|
|
176
|
// Confirm the IPE link is on the form.
|
177
|
$this->assertLink(t('Change layout'));
|
178
|
$path = 'panels/ajax/ipe/change_layout/panelizer:node:' . $node->nid . ':page_manager:' . $node->vid;
|
179
|
$query_string = array('destination' => 'node/' . $node->nid);
|
180
|
$full_path = url($path, array('query' => array('destination' => $query_string['destination'])));
|
181
|
$this->assertLinkByHref($full_path);
|
182
|
// Confirm the link via xpath.
|
183
|
$xpath = $this->xpath("//a[@id='ajax-link']");
|
184
|
$this->assertEqual(count($xpath), 1, 'Found the "Change layout" link.');
|
185
|
$this->assertEqual($xpath[0]['href'], $full_path);//, 'The "Change layout" link is what was expected.');
|
186
|
|
187
|
// Load the API path when logged in. This should give an AJAX response with
|
188
|
// three commands - the first should be "settings", the second one should be
|
189
|
// "modal_display" and the third "IPEsetLockState".
|
190
|
$json = $this->drupalGetAJAX($path, array('query' => $query_string));
|
191
|
$this->assertResponse(200);
|
192
|
$this->verbose('<pre>' . print_r($json, TRUE) . '</pre>');
|
193
|
// @todo What permission does this need to get a proper response?
|
194
|
$this->assertEqual(count($json), 3);
|
195
|
$this->assertTrue(isset($json[0]['command']));
|
196
|
$this->assertEqual($json[0]['command'], 'settings');
|
197
|
$this->assertTrue(isset($json[0]['settings']));
|
198
|
$this->assertTrue(isset($json[0]['merge']));
|
199
|
$this->assertEqual($json[0]['merge'], 'TRUE');
|
200
|
$this->assertTrue(isset($json[1]['command']));
|
201
|
$this->assertEqual($json[1]['command'], 'modal_display');
|
202
|
$this->assertTrue(isset($json[1]['title']));
|
203
|
$this->assertEqual($json[1]['title'], t('Change layout'));
|
204
|
$this->assertTrue(isset($json[2]['command']));
|
205
|
$this->assertEqual($json[2]['command'], 'IPEsetLockState');
|
206
|
$this->assertTrue(isset($json[2]['key']));
|
207
|
$this->assertEqual($json[2]['key'], 'panelizer-node-' . $node->nid . '-page-manager-' . $node->vid);
|
208
|
$this->assertTrue(isset($json[2]['lockPath']));
|
209
|
|
210
|
// Log out.
|
211
|
$this->drupalLogout();
|
212
|
|
213
|
// Load the API path when logged out. This should give a 404-by-AJAX
|
214
|
// response.
|
215
|
$json = $this->drupalGetAJAX($path, array('query' => $query_string));
|
216
|
$this->assertResponse(200);
|
217
|
$this->verbose('<pre>' . print_r($json, TRUE) . '</pre>');
|
218
|
$this->assertEqual(count($json), 2);
|
219
|
$this->assertTrue(isset($json[1]['command']));
|
220
|
$this->assertEqual($json[1]['command'], 'alert');
|
221
|
$this->assertTrue(isset($json[1]['text']));
|
222
|
$this->assertEqual($json[1]['text'], t('You are not authorized to access this page.'));
|
223
|
$this->assertFalse(isset($json[1]['key']));
|
224
|
$this->assertFalse(isset($json[1]['data']));
|
225
|
$this->assertFalse(isset($json[1]['lockPath']));
|
226
|
}
|
227
|
|
228
|
/**
|
229
|
* Test whether the IPE 'content' permissions work correctly w entity perms.
|
230
|
*/
|
231
|
function testIpeContentEntityAccess() {
|
232
|
$perms = array(
|
233
|
// Standard node permissions.
|
234
|
'create page content',
|
235
|
'administer content types',
|
236
|
'administer nodes',
|
237
|
'bypass node access',
|
238
|
|
239
|
// Panels IPE.
|
240
|
'use panels in place editing',
|
241
|
|
242
|
// Panelizer.
|
243
|
'administer panelizer',
|
244
|
|
245
|
// Permission to manage the 'content', i.e. the display.
|
246
|
'administer panelizer node page content',
|
247
|
);
|
248
|
$web_user = $this->drupalCreateUser($perms);
|
249
|
$this->drupalLogin($web_user);
|
250
|
|
251
|
// Just 'cause.
|
252
|
drupal_flush_all_caches();
|
253
|
// Create a test node.
|
254
|
$node = $this->createNode();
|
255
|
|
256
|
// Enable IPE for this node.
|
257
|
$this->drupalGet('node/' . $node->nid . '/panelizer/page_manager/settings');
|
258
|
$this->assertResponse(200);
|
259
|
$this->assertFieldByName('pipeline');
|
260
|
$edit = array(
|
261
|
'pipeline' => 'ipe',
|
262
|
);
|
263
|
$this->drupalPost(NULL, $edit, t('Save'));
|
264
|
$this->assertText(t('The settings have been updated.'));
|
265
|
|
266
|
// Load the node view page.
|
267
|
$this->drupalGet('node/' . $node->nid);
|
268
|
$this->assertResponse(200);
|
269
|
|
270
|
// Confirm the IPE link is on the form.
|
271
|
$this->assertLink(t('Customize this page'));
|
272
|
$path = 'panels/ajax/ipe/save_form/panelizer:node:' . $node->nid . ':page_manager:' . $node->vid;
|
273
|
$query_string = array('destination' => 'node/' . $node->nid);
|
274
|
$full_path = url($path, array('query' => array('destination' => $query_string['destination'])));
|
275
|
$this->assertLinkByHref($full_path);
|
276
|
// Confirm the link via xpath.
|
277
|
$xpath = $this->xpath("//a[@id='panels-ipe-customize-page']");
|
278
|
$this->assertEqual(count($xpath), 1, 'Found the "Customize this page" link.');
|
279
|
$this->assertEqual($xpath[0]['href'], $full_path);//, 'The "Customize this Page" link is what was expected.');
|
280
|
|
281
|
// Log out.
|
282
|
$this->drupalLogout();
|
283
|
|
284
|
$perms = array(
|
285
|
// Need to be able to access the node.
|
286
|
'access content',
|
287
|
|
288
|
// Panels IPE.
|
289
|
'use panels in place editing',
|
290
|
|
291
|
// Adds the "Change layout" functionality to IPE.
|
292
|
'change layouts in place editing',
|
293
|
|
294
|
// Panelizer.
|
295
|
'administer panelizer',
|
296
|
|
297
|
// Permission to manage the 'content', i.e. the display.
|
298
|
'administer panelizer node page content',
|
299
|
'administer panelizer node page layout',
|
300
|
);
|
301
|
$web_user = $this->drupalCreateUser($perms);
|
302
|
$this->drupalLogin($web_user);
|
303
|
|
304
|
// Load the node view page.
|
305
|
$this->drupalGet('node/' . $node->nid);
|
306
|
$this->assertResponse(200);
|
307
|
|
308
|
// Confirm the IPE link is not on the form.
|
309
|
$this->assertNoLink(t('Customize this page'));
|
310
|
$path = 'panels/ajax/ipe/save_form/panelizer:node:' . $node->nid . ':page_manager:' . $node->vid;
|
311
|
$query_string = array('destination' => 'node/' . $node->nid);
|
312
|
$full_path = url($path, array('query' => array('destination' => $query_string['destination'])));
|
313
|
$this->assertNoLinkByHref($full_path);
|
314
|
|
315
|
// Confirm the IPE link is not on the form.
|
316
|
$this->assertNoLink(t('Change layout'));
|
317
|
$path = 'panels/ajax/ipe/change_layout/panelizer:node:' . $node->nid . ':Apage_manager:' . $node->vid;
|
318
|
$query_string = array('destination' => 'node/' . $node->nid);
|
319
|
$full_path = url($path, array('query' => array('destination' => $query_string['destination'])));
|
320
|
$this->assertNoLinkByHref($full_path);
|
321
|
}
|
322
|
|
323
|
}
|