1 |
e5e66f93
|
Assos Assos
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* Test the node revisions functionality for Panelizer.
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
|
|
/**
|
8 |
|
|
* Verifies Panelizer configuration options for node revisions.
|
9 |
|
|
*/
|
10 |
|
|
class PanelizerNodeRevisionTest extends PanelizerTestHelper {
|
11 |
|
|
|
12 |
|
|
/**
|
13 |
|
|
* {@inheritdoc}
|
14 |
|
|
*/
|
15 |
|
|
public static function getInfo() {
|
16 |
|
|
return array(
|
17 |
|
|
'name' => 'Panelizer node revisions (excluding IPE)',
|
18 |
|
|
'description' => 'Test panelizer customization in node revisions, excluding IPE.',
|
19 |
|
|
'group' => 'Panelizer',
|
20 |
|
|
);
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
/**
|
24 |
|
|
* {@inheritdoc}
|
25 |
|
|
*/
|
26 |
|
|
function setUp(array $modules = array()) {
|
27 |
|
|
parent::setUp();
|
28 |
|
|
|
29 |
|
|
$perms = array(
|
30 |
|
|
'administer content types',
|
31 |
|
|
'administer nodes',
|
32 |
|
|
'bypass node access',
|
33 |
|
|
'administer page manager',
|
34 |
|
|
'use page manager',
|
35 |
|
|
'administer panelizer',
|
36 |
|
|
);
|
37 |
|
|
$web_user = $this->drupalCreateUser($perms);
|
38 |
|
|
$this->drupalLogin($web_user);
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
/**
|
42 |
|
|
* Confirm various aspects of revision handling work correctly.
|
43 |
|
|
*/
|
44 |
|
|
function testRevisionHandling() {
|
45 |
|
|
// Finding this class on the page will indicate it is using a default
|
46 |
|
|
// display.
|
47 |
|
|
$css_default_class = 'panelizer-default';
|
48 |
|
|
|
49 |
|
|
// Enable the node_view display in Page Manager.
|
50 |
|
|
$this->simpleEnablePage('node_view');
|
51 |
|
|
|
52 |
|
|
// Check the Page Manager admin page.
|
53 |
|
|
$this->drupalGet('admin/structure/pages');
|
54 |
|
|
$this->assertResponse(200);
|
55 |
|
|
$this->assertLink(t('Disable'));
|
56 |
|
|
|
57 |
|
|
// Panelize "Basic page" content type and the 'page_manager' display, give
|
58 |
|
|
// it a default display and allow multiple displays.
|
59 |
|
|
$edit = array();
|
60 |
|
|
$edit['panelizer[status]'] = TRUE;
|
61 |
|
|
$edit['panelizer[view modes][page_manager][status]'] = TRUE;
|
62 |
|
|
$edit['panelizer[view modes][page_manager][default]'] = TRUE;
|
63 |
|
|
$edit['panelizer[view modes][page_manager][choice]'] = TRUE;
|
64 |
|
|
$this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
|
65 |
|
|
$this->assertResponse(200);
|
66 |
|
|
|
67 |
|
|
// Add a custom class to the default display.
|
68 |
|
|
$this->drupalGet('admin/structure/types/manage/page/panelizer/page_manager/node:page:default/settings');
|
69 |
|
|
$edit = array(
|
70 |
|
|
'css_class' => $css_default_class,
|
71 |
|
|
);
|
72 |
|
|
$this->drupalPost(NULL, $edit, t('Save'));
|
73 |
|
|
|
74 |
|
|
// Clone the default display.
|
75 |
|
|
$this->drupalGet('admin/structure/types/manage/page/panelizer/page_manager/node:page:default/clone');
|
76 |
|
|
$this->assertResponse(200);
|
77 |
|
|
$this->assertText(t('Name'));
|
78 |
|
|
$this->assertFieldById('edit-title', "Clone of Default", "Administrative Title");
|
79 |
|
|
|
80 |
|
|
// Manually set the machine name here as it's normally set by
|
81 |
|
|
// machine-name.js, which doesn't work via SimpleTest.
|
82 |
|
|
$this->drupalPost(NULL, array('name' => 'clone_of_default'), t('Save'));
|
83 |
|
|
$this->assertResponse(200);
|
84 |
|
|
// Confirm the status message.
|
85 |
|
|
$this->assertText(t('!item has been created.', array('!item' => 'node:page:clone_of_default')));
|
86 |
|
|
|
87 |
|
|
// Set a custom css class to identify this cloned display.
|
88 |
|
|
$edit = array();
|
89 |
|
|
$clone_css_class = 'panelizer-test-page-node-revisions-clone';
|
90 |
|
|
$edit['css_class'] = $clone_css_class;
|
91 |
|
|
$this->drupalPost('admin/structure/types/manage/page/panelizer/page_manager/node:page:clone_of_default/settings', $edit, t('Save'));
|
92 |
|
|
$this->assertResponse(200);
|
93 |
|
|
$this->assertText(t('The settings have been updated.'));
|
94 |
|
|
|
95 |
|
|
// Clone the cloned display.
|
96 |
|
|
$this->drupalGet('admin/structure/types/manage/page/panelizer/page_manager/node:page:clone_of_default/clone');
|
97 |
|
|
$this->assertResponse(200);
|
98 |
|
|
$this->assertText(t('Name'));
|
99 |
|
|
$this->assertFieldById('edit-title', "Clone of Clone of Default", "Administrative Title");
|
100 |
|
|
|
101 |
|
|
// Manually set the machine name here as it's normally set by
|
102 |
|
|
// machine-name.js, which doesn't work via SimpleTest.
|
103 |
|
|
$this->drupalPost(NULL, array('name' => 'clone_of_clone_of_default'), t('Save'));
|
104 |
|
|
$this->assertResponse(200);
|
105 |
|
|
$this->assertText(t('!item has been created.', array('!item' => 'node:page:clone_of_clone_of_default')));
|
106 |
|
|
|
107 |
|
|
// Set a custom css class to identify this cloned-cloned display.
|
108 |
|
|
$edit = array();
|
109 |
|
|
$clone_of_clone_css_class = 'panelizer-test-page-node-revisions-cloned-clone';
|
110 |
|
|
$edit['css_class'] = $clone_of_clone_css_class;
|
111 |
|
|
$this->drupalPost('admin/structure/types/manage/page/panelizer/page_manager/node:page:clone_of_clone_of_default/settings', $edit, t('Save'));
|
112 |
|
|
$this->assertResponse(200);
|
113 |
|
|
$this->assertText(t('The settings have been updated.'));
|
114 |
|
|
|
115 |
|
|
// Assert panel choice for new pages.
|
116 |
|
|
$this->drupalGet('node/add/page');
|
117 |
|
|
$this->assertField('panelizer[page_manager][name]', 'Display can be chosen on new page form');
|
118 |
|
|
|
119 |
|
|
// Create a node with default panelizer display.
|
120 |
|
|
$edit = array();
|
121 |
|
|
$langcode = LANGUAGE_NONE;
|
122 |
|
|
$edit["title"] = $this->randomName(8);
|
123 |
|
|
$edit["body[$langcode][0][value]"] = $this->randomName(16);
|
124 |
|
|
$this->drupalPost('node/add/page', $edit, t('Save'));
|
125 |
|
|
$this->assertResponse(200);
|
126 |
|
|
|
127 |
|
|
// Check that the post can be panelized.
|
128 |
|
|
$node = $this->drupalGetNodeByTitle($edit["title"]);
|
129 |
|
|
$this->assertLink('Customize display', 0, 'The customize display link appears on the page');
|
130 |
|
|
$this->assertLinkByHref('node/' . $node->nid . '/panelizer', 0, 'A link to customize the node appears on the page');
|
131 |
|
|
|
132 |
|
|
// Assert panel choice for existing pages.
|
133 |
|
|
$this->drupalGet('node/' . $node->nid . '/edit');
|
134 |
|
|
$this->assertResponse(200);
|
135 |
|
|
$this->assertField('panelizer[page_manager][name]', 'Display can be chosen on edit page form');
|
136 |
|
|
|
137 |
|
|
// Create a new revision with a different display.
|
138 |
|
|
$langcode = LANGUAGE_NONE;
|
139 |
|
|
$edit["revision"] = 1;
|
140 |
|
|
$edit["log"] = "Changed panelizer display in a revision";
|
141 |
|
|
$edit["panelizer[page_manager][name]"] = 'node:page:clone_of_default';
|
142 |
|
|
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
|
143 |
|
|
$this->assertResponse(200);
|
144 |
|
|
$this->assertLink(t('Revisions'), 0, 'The node has multiple revisions');
|
145 |
|
|
|
146 |
|
|
// Check that the new revision is rendered using the cloned display.
|
147 |
|
|
$elements = $this->xpath('//body[contains(@class,:class)]', array(':class' => $clone_css_class));
|
148 |
|
|
$this->assertEqual(count($elements), 1, 'The node is using the cloned display.');
|
149 |
|
|
|
150 |
|
|
// Confirm that the revisions tab is now available.
|
151 |
|
|
$this->drupalGet('node/' . $node->nid . '/revisions');
|
152 |
|
|
$this->assertResponse(200);
|
153 |
|
|
|
154 |
|
|
// Check that the old revision is still using the default display.
|
155 |
|
|
$revisions = node_revision_list($node);
|
156 |
|
|
$oldest_revision = array_pop($revisions);
|
157 |
|
|
$this->assertNotNull($oldest_revision->vid);
|
158 |
|
|
$this->drupalGet('node/' . $node->nid . '/revisions/' . $oldest_revision->vid . '/view');
|
159 |
|
|
$this->assertResponse(200);
|
160 |
|
|
$elements = $this->xpath('//body[contains(@class,:class)]', array(':class' => $clone_css_class));
|
161 |
|
|
$this->assertEqual(count($elements), 0, 'The node revision is not using the cloned display.');
|
162 |
|
|
// @todo Panelizer doesn't add a body class for default displays, need to
|
163 |
|
|
// add a default class.
|
164 |
|
|
$elements = $this->xpath('//body[contains(@class,:class)]', array(':class' => $css_default_class));
|
165 |
|
|
$this->assertEqual(count($elements), 1, 'The node is using the default display.');
|
166 |
|
|
|
167 |
|
|
// Create a new revision with another different display.
|
168 |
|
|
$langcode = LANGUAGE_NONE;
|
169 |
|
|
$edit = array();
|
170 |
|
|
$edit['title'] = $node->title;
|
171 |
|
|
$edit["body[$langcode][0][value]"] = $node->body[$langcode][0]["value"];
|
172 |
|
|
$edit["revision"] = 1;
|
173 |
|
|
$edit["log"] = "Changed panelizer display in another revision";
|
174 |
|
|
$edit["panelizer[page_manager][name]"] = 'node:page:clone_of_clone_of_default';
|
175 |
|
|
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
|
176 |
|
|
$this->assertResponse(200);
|
177 |
|
|
|
178 |
|
|
// Check that the new revision is rendered using the cloned display.
|
179 |
|
|
$elements = $this->xpath('//body[contains(@class,:class)]', array(':class' => $clone_of_clone_css_class));
|
180 |
|
|
$this->assertEqual(count($elements), 1, 'The node is using the cloned display.');
|
181 |
|
|
|
182 |
|
|
// Check that the oldest revision is still using the default display.
|
183 |
|
|
$revisions = node_revision_list($node);
|
184 |
|
|
$this->assertEqual(count($revisions), 3, "The node has one published and two former revisions");
|
185 |
|
|
$oldest_revision = array_pop($revisions);
|
186 |
|
|
$this->assertNotNull($oldest_revision->vid);
|
187 |
|
|
$this->drupalGet('node/' . $node->nid . '/revisions/' . $oldest_revision->vid . '/view');
|
188 |
|
|
$this->assertResponse(200);
|
189 |
|
|
$elements = $this->xpath('//body[contains(@class,:class)]', array(':class' => $clone_of_clone_css_class));
|
190 |
|
|
$this->assertEqual(count($elements), 0, 'The node revision is NOT using the clone of cloned display.');
|
191 |
|
|
$elements = $this->xpath('//body[contains(@class,:class)]', array(':class' => $clone_css_class));
|
192 |
|
|
$this->assertEqual(count($elements), 0, 'The node revision is NOT using the cloned display.');
|
193 |
|
|
// @todo Panelizer doesn't add a body class for default displays, need to
|
194 |
|
|
// add a default class.
|
195 |
|
|
$elements = $this->xpath('//body[contains(@class,:class)]', array(':class' => $css_default_class));
|
196 |
|
|
$this->assertEqual(count($elements), 1, 'The node revision is using the default display.');
|
197 |
|
|
|
198 |
|
|
// Check that the previous revision is still using the original cloned
|
199 |
|
|
// display.
|
200 |
|
|
$node_revision = array_pop($revisions);
|
201 |
|
|
$this->assertNotNull($node_revision->vid);
|
202 |
|
|
$node_revision = node_load(NULL, $node_revision->vid);
|
203 |
|
|
$this->drupalGet('node/' . $node->nid . '/revisions/' . $node_revision->vid . '/view');
|
204 |
|
|
$this->assertResponse(200);
|
205 |
|
|
$elements = $this->xpath('//body[contains(@class,:class)]', array(':class' => $clone_of_clone_css_class));
|
206 |
|
|
$this->assertEqual(count($elements), 0, 'The node revision is NOT using the clone of cloned display.');
|
207 |
|
|
$elements = $this->xpath('//body[contains(@class,:class)]', array(':class' => $clone_css_class));
|
208 |
|
|
$this->assertEqual(count($elements), 1, 'The node revision is using the default display.');
|
209 |
|
|
|
210 |
|
|
// Get the number of {panelizer_entity} records currently recorded for this
|
211 |
|
|
// node.
|
212 |
|
|
$old_count = db_select('panelizer_entity', 'pe')
|
213 |
|
|
->fields('pe')
|
214 |
|
|
->condition('entity_type', 'node')
|
215 |
|
|
->condition('entity_id', $node->nid)
|
216 |
|
|
->countQuery()
|
217 |
|
|
->execute()
|
218 |
|
|
->fetchField();
|
219 |
|
|
|
220 |
|
|
// Delete a revision.
|
221 |
|
|
$this->drupalGet('node/' . $node->nid . '/revisions/' . $node_revision->vid . '/delete');
|
222 |
|
|
$this->assertResponse(200);
|
223 |
|
|
$t_args = array(
|
224 |
|
|
'%revision-date' => format_date($node_revision->revision_timestamp),
|
225 |
|
|
);
|
226 |
|
|
$this->assertText(strip_tags(t('Are you sure you want to delete the revision from %revision-date?', $t_args)));
|
227 |
|
|
$this->assertText(t('This action cannot be undone.'));
|
228 |
|
|
$this->drupalPost(NULL, array(), t('Delete'));
|
229 |
|
|
$this->assertResponse(200);
|
230 |
|
|
$t_args = array(
|
231 |
|
|
'%revision-date' => format_date($node_revision->revision_timestamp),
|
232 |
|
|
'@type' => node_type_get_name($node_revision),
|
233 |
|
|
'%title' => $node_revision->title,
|
234 |
|
|
);
|
235 |
|
|
$this->assertText(strip_tags(t('Revision from %revision-date of @type %title has been deleted.', $t_args)));
|
236 |
|
|
|
237 |
|
|
// Confirm only one {panelizer_entity} record was deleted.
|
238 |
|
|
$records = db_select('panelizer_entity', 'pe')
|
239 |
|
|
->fields('pe')
|
240 |
|
|
->condition('entity_type', 'node')
|
241 |
|
|
->condition('entity_id', $node->nid)
|
242 |
|
|
->orderBy('pe.revision_id')
|
243 |
|
|
->execute()
|
244 |
|
|
->fetchAll();
|
245 |
|
|
$this->assertEqual($old_count, count($records) + 1);
|
246 |
|
|
$this->verbose('<pre>' . print_r($records, TRUE) . '</pre>');
|
247 |
|
|
|
248 |
|
|
// Revert to the first revision.
|
249 |
|
|
$revisions = node_revision_list($node);
|
250 |
|
|
$node_revision = array_pop($revisions);
|
251 |
|
|
$node_revision = node_load(NULL, $node_revision->vid);
|
252 |
|
|
$this->drupalGet('node/' . $node->nid . '/revisions/' . $node_revision->vid . '/revert');
|
253 |
|
|
$this->assertResponse(200);
|
254 |
|
|
$t_args = array(
|
255 |
|
|
'%revision-date' => format_date($node_revision->revision_timestamp),
|
256 |
|
|
);
|
257 |
|
|
$this->assertText(strip_tags(t('Are you sure you want to revert to the revision from %revision-date?', $t_args)));
|
258 |
|
|
$this->drupalPost(NULL, array(), t('Revert'));
|
259 |
|
|
$this->assertResponse(200);
|
260 |
|
|
$t_args = array(
|
261 |
|
|
'@type' => node_type_get_name($node_revision),
|
262 |
|
|
'%title' => $node_revision->title,
|
263 |
|
|
'%revision-date' => format_date($node_revision->revision_timestamp),
|
264 |
|
|
);
|
265 |
|
|
$this->assertText(strip_tags(t('@type %title has been reverted back to the revision from %revision-date.', $t_args)));
|
266 |
|
|
|
267 |
|
|
// Confirm one more {panelizer_entity} record was added.
|
268 |
|
|
$records = db_select('panelizer_entity', 'pe')
|
269 |
|
|
->fields('pe')
|
270 |
|
|
->condition('entity_type', 'node')
|
271 |
|
|
->condition('entity_id', $node->nid)
|
272 |
|
|
->orderBy('pe.revision_id')
|
273 |
|
|
->execute()
|
274 |
|
|
->fetchAll();
|
275 |
|
|
// Because one of the displays is now using a default, there'll be one less
|
276 |
|
|
// record.
|
277 |
|
|
$this->assertEqual($old_count, count($records) + 1);
|
278 |
|
|
$this->verbose('<pre>' . print_r($records, TRUE) . '</pre>');
|
279 |
|
|
|
280 |
|
|
$this->drupalGet('node/' . $node->nid);
|
281 |
|
|
$this->assertResponse(200);
|
282 |
|
|
$elements = $this->xpath('//body[contains(@class,:class)]', array(':class' => $clone_css_class));
|
283 |
|
|
$this->assertEqual(count($elements), 0, 'The node revision is not using the cloned display.');
|
284 |
|
|
// @todo Panelizer doesn't add a body class for default displays, need to
|
285 |
|
|
// add a default class.
|
286 |
|
|
$elements = $this->xpath('//body[contains(@class,:class)]', array(':class' => $css_default_class));
|
287 |
|
|
$this->assertEqual(count($elements), 1, 'The node is using the default display again.');
|
288 |
|
|
|
289 |
|
|
// Confirm there is no record for this object that is now using the default.
|
290 |
|
|
$new_display = NULL;
|
291 |
|
|
foreach ($records as $record) {
|
292 |
|
|
if ($record->revision_id == $node_revision->vid) {
|
293 |
|
|
$new_display = $record->name;
|
294 |
|
|
break;
|
295 |
|
|
}
|
296 |
|
|
}
|
297 |
|
|
$this->assertNull($new_display);
|
298 |
|
|
}
|
299 |
|
|
|
300 |
|
|
} |