1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Test integration for the panelizer module.
|
5
|
*/
|
6
|
|
7
|
/**
|
8
|
* This will be extended by other tests to simplify them and make the code more
|
9
|
* reusable.
|
10
|
*/
|
11
|
class PanelizerTestHelper extends DrupalWebTestCase {
|
12
|
|
13
|
/**
|
14
|
* {@inheritdoc}
|
15
|
*/
|
16
|
function setUp(array $modules = array()) {
|
17
|
$modules[] = 'ctools';
|
18
|
$modules[] = 'panels';
|
19
|
$modules[] = 'panelizer';
|
20
|
parent::setUp($modules);
|
21
|
}
|
22
|
|
23
|
/**
|
24
|
* Helper function to quickly enable or disable Panelizer for an entity type.
|
25
|
*
|
26
|
* @param string $entity_type
|
27
|
* The entity type to configure, defaults to 'node'.
|
28
|
* @param string $bundle
|
29
|
* The entity bundle to enable, defaults to 'page'.
|
30
|
* @param string $view_mode
|
31
|
* The entity view mode to be panelized; defaults to 'page_manager'.
|
32
|
* @param boolean $status
|
33
|
* Indicate whther the view mode is enabled or disabled; defaults to TRUE.
|
34
|
* @param boolean $use_default
|
35
|
* Whether to enable a default display; defaults to TRUE.
|
36
|
* @param boolean $choice
|
37
|
* Whether to enable a display choice may be made; defaults to TRUE.
|
38
|
*/
|
39
|
protected function togglePanelizer($entity_type = 'node', $bundle = 'page', $view_mode = 'page_manager', $status = 1, $use_default = 1, $choice = 1) {
|
40
|
variable_set('panelizer_defaults_' . $entity_type . '_' . $bundle, array(
|
41
|
'status' => 1,
|
42
|
'help' => '',
|
43
|
'view modes' => array(
|
44
|
$view_mode => array(
|
45
|
'status' => $status,
|
46
|
'substitute' => FALSE,
|
47
|
'default' => $use_default,
|
48
|
'choice' => $choice,
|
49
|
),
|
50
|
),
|
51
|
));
|
52
|
|
53
|
// Update the handler's plugin definition. Because of the way Panelizer is
|
54
|
// caching the handler objects, the entity node handler has already been
|
55
|
// loaded and has already identified what bundles are configured for this
|
56
|
// page execution. In order to work around that, so that
|
57
|
// hook_entity_update() can be called, need to reload the handler and rejig
|
58
|
// the plugin defintion.
|
59
|
ctools_include('plugins');
|
60
|
ctools_plugin_get_plugin_type_info(TRUE);
|
61
|
$handler = panelizer_entity_plugin_get_handler($entity_type);
|
62
|
$plugin = panelizer_get_entity_plugin($entity_type);
|
63
|
$info = ctools_plugin_get_info('panelizer', 'entity');
|
64
|
panelizer_entity_plugin_process($plugin, $info);
|
65
|
$handler->plugin = $plugin;
|
66
|
$this->verbose(print_r($handler, TRUE));
|
67
|
$this->assertTrue($handler->is_panelized($bundle), 'Entity bundle is panelized.');
|
68
|
return $handler;
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Enable a Page Manager page handler.
|
73
|
*
|
74
|
* @param string $page_name
|
75
|
* The Page Manager page handler that needs to be enabled.
|
76
|
*/
|
77
|
function simpleEnablePage($page_name) {
|
78
|
$page = page_manager_get_page_cache($page_name);
|
79
|
$function = ctools_plugin_get_function($page->subtask, 'enable callback');
|
80
|
$function($page, FALSE);
|
81
|
menu_rebuild();
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* Get the default Panelizer display for a specific entity bundle.
|
86
|
*
|
87
|
* @param string $entity_type
|
88
|
* @param string $bundle
|
89
|
* @param string $view_mode
|
90
|
*/
|
91
|
function getDefaultPanelizerDisplay($entity_type, $bundle, $view_mode) {
|
92
|
$handler = panelizer_entity_plugin_get_handler($entity_type);
|
93
|
$this->verbose(print_r($handler, TRUE));
|
94
|
$this->assertTrue($handler->is_panelized($bundle), 'Entity bundle is panelized.');
|
95
|
return $handler->get_default_display($bundle, $view_mode);
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* Add a custom text pane to a display.
|
100
|
*/
|
101
|
function addTestPane(&$display, $text = 'Hello world') {
|
102
|
$custom = ctools_get_content_type('custom');
|
103
|
|
104
|
// Create a basic 'custom' pane.
|
105
|
$pane = panels_new_pane('custom', 'custom');
|
106
|
$pane->configuration = ctools_content_get_defaults($custom, 'custom');
|
107
|
$pane->configuration['title'] = 'test';
|
108
|
$pane->configuration['body'] = $text;
|
109
|
|
110
|
// Add the pane to the display.
|
111
|
$display->add_pane($pane, 'center');
|
112
|
}
|
113
|
|
114
|
/**
|
115
|
* Enable some extra languages.
|
116
|
*/
|
117
|
function setupLocales() {
|
118
|
// Add French.
|
119
|
$this->addSiteLanguage('fr');
|
120
|
|
121
|
// Add Spanish.
|
122
|
$this->addSiteLanguage('es');
|
123
|
|
124
|
// Enable URL language detection and selection.
|
125
|
$edit = array('language[enabled][locale-url]' => '1');
|
126
|
$this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
|
127
|
$this->assertResponse(200);
|
128
|
}
|
129
|
|
130
|
/**
|
131
|
* Add a locale to the site.
|
132
|
*
|
133
|
* This assumes the Locale module is enabled.
|
134
|
*/
|
135
|
public function addSiteLanguage($langcode) {
|
136
|
// Load the language-add page.
|
137
|
$this->drupalGet('admin/config/regional/language/add');
|
138
|
$this->assertResponse(200, 'Loaded the language-add admin page.');
|
139
|
|
140
|
// Submit the language-add form.
|
141
|
$args = array(
|
142
|
'langcode' => $langcode,
|
143
|
);
|
144
|
$this->drupalPost(NULL, $args, t('Add language'));
|
145
|
$this->assertResponse(200);
|
146
|
|
147
|
// Verify that the browser was returned to the main languages admin page.
|
148
|
$this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Redirected back to the main languages admin page.');
|
149
|
|
150
|
// Clear the language list cache so it can be reloaded.
|
151
|
drupal_static_reset('language_list');
|
152
|
|
153
|
// Get all language definitions.
|
154
|
$languages = language_list();
|
155
|
$language = $languages[$langcode]->name;
|
156
|
$this->assertText(strip_tags(t('The language %language has been created and can now be used. More information is available on the <a href="@locale-help">help screen</a>.', array('%language' => t($language), '@locale-help' => url('admin/help/locale')))), 'A new language has been added.');
|
157
|
}
|
158
|
|
159
|
/**
|
160
|
* Create a node for testing.
|
161
|
*
|
162
|
* @params array $options
|
163
|
* A list of additional arguments to be passed to the node/add/page form.
|
164
|
*
|
165
|
* @return object
|
166
|
* A node object.
|
167
|
*/
|
168
|
function createNode(array $options = array()) {
|
169
|
// Create a node.
|
170
|
$this->drupalGet('node/add/page');
|
171
|
$this->assertResponse(200);
|
172
|
$langcode = LANGUAGE_NONE;
|
173
|
$edit = array(
|
174
|
'title' => $this->randomName(8),
|
175
|
"body[$langcode][0][value]" => $this->randomName(16),
|
176
|
) + $options;
|
177
|
$this->drupalPost(NULL, $edit, t('Save'));
|
178
|
|
179
|
return $this->drupalGetNodeByTitle($edit['title']);
|
180
|
}
|
181
|
|
182
|
/**
|
183
|
* Compare panes from two different displays to make sure they're the same.
|
184
|
*
|
185
|
* @param object $panelizer1
|
186
|
* The first display object.
|
187
|
* @param object $panelizer2
|
188
|
* The second display object.
|
189
|
*/
|
190
|
function compareDisplayPanes($panelizer1, $panelizer2) {
|
191
|
$this->verbose('<pre>' . print_r(func_get_args(), TRUE) . '</pre>');
|
192
|
|
193
|
// Confirm the UUID values are different.
|
194
|
// @todo Dependent upon https://www.drupal.org/node/2750545.
|
195
|
// $this->assertNotEqual($panelizer1->display->uuid, $panelizer2->display->uuid);
|
196
|
|
197
|
// Make simpler structure of the two display's panes, to make them easier to
|
198
|
// examine later.
|
199
|
$panes1 = array();
|
200
|
$panes2 = array();
|
201
|
foreach ($panelizer1->display->content as $key => $pane) {
|
202
|
$panes1[] = $pane;
|
203
|
}
|
204
|
foreach ($panelizer2->display->content as $key => $pane) {
|
205
|
$panes2[] = $pane;
|
206
|
}
|
207
|
|
208
|
// Compare the two sets of panes.
|
209
|
foreach ($panes1 as $key => $pane) {
|
210
|
// Verify that the pane exists in the second display.
|
211
|
$this->assertTrue(isset($panes2[$key]));
|
212
|
|
213
|
// Confirm the two panes are of the same type.
|
214
|
$this->assertEqual($pane->type, $panes2[$key]->type);
|
215
|
$this->assertEqual($pane->subtype, $panes2[$key]->subtype);
|
216
|
|
217
|
// Confirm the pid values are different.
|
218
|
$this->assertNotEqual($pane->pid, $panes2[$key]->pid);
|
219
|
|
220
|
// Confirm the UUID values are different.
|
221
|
// @todo Dependent upon https://www.drupal.org/node/2750545.
|
222
|
// $this->assertNotEqual($pane->uuid, $panes2[$key]->uuid);
|
223
|
}
|
224
|
}
|
225
|
|
226
|
/**
|
227
|
* Get the {panelizer_entity} records exist for an entity.
|
228
|
*
|
229
|
* @param string $entity_type
|
230
|
* The entity type to check.
|
231
|
* @param int $entity_id
|
232
|
* The entity's primary ID.
|
233
|
* @param int $revision_id
|
234
|
* The entity's revision ID.
|
235
|
*
|
236
|
* @return array
|
237
|
* The records that were found.
|
238
|
*/
|
239
|
function getPanelizerEntityRecords($entity_type, $entity_id, $revision_id = NULL) {
|
240
|
$query = db_select('panelizer_entity', 'pe')
|
241
|
->fields('pe')
|
242
|
->condition('entity_type', $entity_type);
|
243
|
|
244
|
// If the revision ID was passed in, use it, otherwise use the entity ID.
|
245
|
if (!empty($revision_id)) {
|
246
|
$query->condition('revision_id', $revision_id);
|
247
|
}
|
248
|
else {
|
249
|
$query->condition('entity_id', $entity_id);
|
250
|
}
|
251
|
|
252
|
$records = $query->orderBy('pe.revision_id')
|
253
|
->execute()
|
254
|
->fetchAll();
|
255
|
|
256
|
// Debug output, for local testing.
|
257
|
$this->verbose('<pre>' . print_r($records, TRUE) . '</pre>');
|
258
|
|
259
|
return $records;
|
260
|
}
|
261
|
|
262
|
}
|