1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Base functions and tests for Display Suite.
|
6
|
*/
|
7
|
|
8
|
class dsBaseTest extends DrupalWebTestCase {
|
9
|
|
10
|
/**
|
11
|
* Implementation of setUp().
|
12
|
*/
|
13
|
function setUp() {
|
14
|
parent::setUp('ctools', 'ds', 'ds_extras', 'search', 'ds_search', 'ds_format', 'ds_forms', 'ds_ui', 'ds_test', 'panels', 'views');
|
15
|
|
16
|
variable_set('search_active_modules', array('node' => '', 'user' => 'user', 'ds_search' => 'ds_search'));
|
17
|
menu_rebuild();
|
18
|
|
19
|
$this->admin_user = $this->drupalCreateUser(array('admin_classes', 'admin_view_modes', 'admin_fields', 'admin_display_suite', 'ds_switch article', 'use text format ds_code', 'access administration pages', 'administer content types', 'administer users', 'administer comments', 'administer nodes', 'bypass node access', 'administer blocks', 'search content', 'use advanced search', 'administer search', 'access user profiles', 'administer permissions'));
|
20
|
$this->drupalLogin($this->admin_user);
|
21
|
}
|
22
|
|
23
|
/**
|
24
|
* Select a layout.
|
25
|
*/
|
26
|
function dsSelectLayout($edit = array(), $assert = array(), $url = 'admin/structure/types/manage/article/display', $options = array()) {
|
27
|
|
28
|
$edit += array(
|
29
|
'additional_settings[layout]' => 'ds_2col_stacked',
|
30
|
);
|
31
|
|
32
|
$this->drupalPost($url, $edit, t('Save'), $options);
|
33
|
|
34
|
$assert += array(
|
35
|
'regions' => array(
|
36
|
'header' => '<td colspan="8">' . t('Header') . '</td>',
|
37
|
'left' => '<td colspan="8">' . t('Left') . '</td>',
|
38
|
'right' => '<td colspan="8">' . t('Right') . '</td>',
|
39
|
'footer' => '<td colspan="8">' . t('Footer') . '</td>',
|
40
|
),
|
41
|
);
|
42
|
|
43
|
foreach ($assert['regions'] as $region => $raw) {
|
44
|
$this->assertRaw($region, t('Region !region found', array('!region' => $region)));
|
45
|
}
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* Configure classes
|
50
|
*/
|
51
|
function dsConfigureClasses($edit = array()) {
|
52
|
|
53
|
$edit += array(
|
54
|
'ds_classes_regions' => "class_name_1\nclass_name_2|Friendly name"
|
55
|
);
|
56
|
|
57
|
$this->drupalPost('admin/structure/ds/classes', $edit, t('Save configuration'));
|
58
|
$this->assertText(t('The configuration options have been saved.'), t('CSS classes configuration saved'));
|
59
|
$this->assertRaw('class_name_1', 'Class name 1 found');
|
60
|
$this->assertRaw('class_name_2', 'Class name 1 found');
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* Configure classes on a layout.
|
65
|
*/
|
66
|
function dsSelectClasses($edit = array(), $url = 'admin/structure/types/manage/article/display') {
|
67
|
|
68
|
$edit += array(
|
69
|
"additional_settings[header][]" => 'class_name_1',
|
70
|
"additional_settings[footer][]" => 'class_name_2',
|
71
|
);
|
72
|
|
73
|
$this->drupalPost($url, $edit, t('Save'));
|
74
|
}
|
75
|
|
76
|
/**
|
77
|
* Configure Field UI.
|
78
|
*/
|
79
|
function dsConfigureUI($edit, $url = 'admin/structure/types/manage/article/display') {
|
80
|
$this->drupalPost($url, $edit, t('Save'));
|
81
|
}
|
82
|
|
83
|
/**
|
84
|
* Edit field formatter settings
|
85
|
*/
|
86
|
function dsEditFormatterSettings($edit, $url = 'admin/structure/types/manage/article/display', $element_value = 'edit body') {
|
87
|
$this->drupalPost($url, array(), $element_value);
|
88
|
$this->drupalPost(NULL, $edit, t('Update'));
|
89
|
$this->drupalPost(NULL, array(), t('Save'));
|
90
|
}
|
91
|
|
92
|
/**
|
93
|
* Create a view mode.
|
94
|
*
|
95
|
* @param $edit
|
96
|
* An optional array of view mode properties.
|
97
|
*/
|
98
|
function dsCreateViewMode($edit = array()) {
|
99
|
|
100
|
$edit += array(
|
101
|
'name' => 'Testing',
|
102
|
'view_mode' => 'testing',
|
103
|
'entities[node]' => '1'
|
104
|
);
|
105
|
|
106
|
$this->drupalPost('admin/structure/ds/view_modes/manage', $edit, t('Save'));
|
107
|
$this->assertText(t('The view mode ' . $edit['name'] . ' has been saved'), t('!name view mode has been saved', array('!name' => $edit['name'])));
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Create a code field.
|
112
|
*
|
113
|
* @param $edit
|
114
|
* An optional array of field properties.
|
115
|
*/
|
116
|
function dsCreateCodeField($edit = array(), $url = 'admin/structure/ds/fields/manage_custom') {
|
117
|
|
118
|
$edit += array(
|
119
|
'name' => 'Test field',
|
120
|
'field' => 'test_field',
|
121
|
'entities[node]' => '1',
|
122
|
'code[value]' => 'Test field',
|
123
|
'use_token' => '0',
|
124
|
);
|
125
|
|
126
|
$this->drupalPost($url, $edit, t('Save'));
|
127
|
$this->assertText(t('The field ' . $edit['name'] . ' has been saved'), t('!name field has been saved', array('!name' => $edit['name'])));
|
128
|
}
|
129
|
|
130
|
/**
|
131
|
* Create a block field.
|
132
|
*
|
133
|
* @param $edit
|
134
|
* An optional array of field properties.
|
135
|
*/
|
136
|
function dsCreateBlockField($edit = array(), $url = 'admin/structure/ds/fields/manage_block', $first = TRUE) {
|
137
|
|
138
|
$edit += array(
|
139
|
'name' => 'Test block field',
|
140
|
'entities[node]' => '1',
|
141
|
'block' => 'node|recent',
|
142
|
'block_render' => DS_BLOCK_TEMPLATE,
|
143
|
);
|
144
|
|
145
|
if ($first) {
|
146
|
$edit += array('field' => 'test_block_field');
|
147
|
}
|
148
|
|
149
|
$this->drupalPost($url, $edit, t('Save'));
|
150
|
$this->assertText(t('The field ' . $edit['name'] . ' has been saved'), t('!name field has been saved', array('!name' => $edit['name'])));
|
151
|
}
|
152
|
|
153
|
/**
|
154
|
* Create a block field.
|
155
|
*
|
156
|
* @param $edit
|
157
|
* An optional array of field properties.
|
158
|
*/
|
159
|
function dsCreatePreprocessField($edit = array(), $url = 'admin/structure/ds/fields/manage_preprocess', $first = TRUE) {
|
160
|
|
161
|
$edit += array(
|
162
|
'name' => 'Submitted',
|
163
|
'entities[node]' => '1',
|
164
|
);
|
165
|
|
166
|
if ($first) {
|
167
|
$edit += array('field' => 'submitted');
|
168
|
}
|
169
|
|
170
|
$this->drupalPost($url, $edit, t('Save'));
|
171
|
$this->assertText(t('The field ' . $edit['name'] . ' has been saved'), t('!name field has been saved', array('!name' => $edit['name'])));
|
172
|
}
|
173
|
|
174
|
/**
|
175
|
* Create a dynamic field.
|
176
|
*
|
177
|
* @param $edit
|
178
|
* An optional array of field properties.
|
179
|
*/
|
180
|
function dsCreateDynamicField($edit = array(), $url = 'admin/structure/ds/fields/manage_ctools', $first = TRUE) {
|
181
|
|
182
|
$edit += array(
|
183
|
'name' => 'Dynamic',
|
184
|
'entities[node]' => '1',
|
185
|
);
|
186
|
|
187
|
if ($first) {
|
188
|
$edit += array('field' => 'dynamic');
|
189
|
}
|
190
|
|
191
|
$this->drupalPost($url, $edit, t('Save'));
|
192
|
$this->assertText(t('The field ' . $edit['name'] . ' has been saved'), t('!name field has been saved', array('!name' => $edit['name'])));
|
193
|
}
|
194
|
}
|
195
|
|
196
|
/**
|
197
|
* Test managing of custom fields.
|
198
|
*/
|
199
|
class dsFieldsTests extends dsBaseTest {
|
200
|
|
201
|
/**
|
202
|
* Implements getInfo().
|
203
|
*/
|
204
|
public static function getInfo() {
|
205
|
return array(
|
206
|
'name' => t('Fields'),
|
207
|
'description' => t('Tests for managing custom code, dynamic, preprocess and block fields.'),
|
208
|
'group' => t('Display Suite'),
|
209
|
);
|
210
|
}
|
211
|
|
212
|
/**
|
213
|
* Test Display fields.
|
214
|
*/
|
215
|
function testDSFields() {
|
216
|
|
217
|
$edit = array(
|
218
|
'name' => 'Test field',
|
219
|
'field' => 'test_field',
|
220
|
'entities[node]' => '1',
|
221
|
'code[value]' => 'Test field',
|
222
|
'use_token' => '0',
|
223
|
);
|
224
|
|
225
|
$this->dsCreateCodeField($edit);
|
226
|
|
227
|
// Create the same and assert it already exists.
|
228
|
$this->drupalPost('admin/structure/ds/fields/manage_custom', $edit, t('Save'));
|
229
|
$this->assertText(t('The machine-readable name is already in use. It must be unique.'), t('Field testing already exists.'));
|
230
|
|
231
|
$this->dsSelectLayout();
|
232
|
|
233
|
// Assert it's found on the Field UI for article.
|
234
|
$this->drupalGet('admin/structure/types/manage/article/display');
|
235
|
$this->assertRaw('fields[test_field][weight]', t('Test field found on node article.'));
|
236
|
|
237
|
// Assert it's not found on the Field UI for users.
|
238
|
$this->drupalGet('admin/config/people/accounts/display');
|
239
|
$this->assertNoRaw('fields[test_field][weight]', t('Test field not found on user.'));
|
240
|
|
241
|
// Update testing label
|
242
|
$edit = array(
|
243
|
'name' => 'Test field 2',
|
244
|
);
|
245
|
$this->drupalPost('admin/structure/ds/fields/manage_custom/test_field', $edit, t('Save'));
|
246
|
$this->assertText(t('The field Test field 2 has been saved'), t('Test field label updated'));
|
247
|
|
248
|
// Use the Field UI limit option.
|
249
|
$this->dsSelectLayout(array(), array(), 'admin/structure/types/manage/page/display');
|
250
|
$this->dsSelectLayout(array(), array(), 'admin/structure/types/manage/article/display/teaser');
|
251
|
$edit = array(
|
252
|
'ui_limit' => 'article|default',
|
253
|
);
|
254
|
$this->drupalPost('admin/structure/ds/fields/manage_custom/test_field', $edit, t('Save'));
|
255
|
|
256
|
$this->drupalGet('admin/structure/types/manage/article/display');
|
257
|
$this->assertRaw('fields[test_field][weight]', t('Test field field found on node article, default.'));
|
258
|
$this->drupalGet('admin/structure/types/manage/article/display/teaser');
|
259
|
$this->assertNoRaw('fields[test_field][weight]', t('Test field field not found on node article, teaser.'));
|
260
|
$this->drupalGet('admin/structure/types/manage/page/display');
|
261
|
$this->assertNoRaw('fields[test_field][weight]', t('Test field field not found on node page, default.'));
|
262
|
$edit = array(
|
263
|
'ui_limit' => 'article|*',
|
264
|
);
|
265
|
$this->drupalPost('admin/structure/ds/fields/manage_custom/test_field', $edit, t('Save'));
|
266
|
$this->drupalGet('admin/structure/types/manage/article/display');
|
267
|
$this->assertRaw('fields[test_field][weight]', t('Test field field found on node article, default.'));
|
268
|
$this->drupalGet('admin/structure/types/manage/article/display/teaser');
|
269
|
$this->assertRaw('fields[test_field][weight]', t('Test field field found on node article, teaser.'));
|
270
|
|
271
|
|
272
|
|
273
|
// Remove the field.
|
274
|
$this->drupalPost('admin/structure/ds/fields/delete/test_field', array(), t('Delete'));
|
275
|
$this->assertText(t('The field Test field 2 has been deleted'), t('Test field removed'));
|
276
|
|
277
|
// Assert the field is gone at the manage display screen.
|
278
|
$this->drupalGet('admin/structure/types/manage/article/display');
|
279
|
$this->assertNoRaw('fields[test_field][weight]', t('Test field field not found on node article.'));
|
280
|
|
281
|
// Block fields.
|
282
|
$edit = array(
|
283
|
'name' => 'Test block field',
|
284
|
'field' => 'test_block_field',
|
285
|
'entities[node]' => '1',
|
286
|
'block' => 'node|recent',
|
287
|
'block_render' => DS_BLOCK_TEMPLATE,
|
288
|
);
|
289
|
|
290
|
$this->dsCreateBlockField($edit);
|
291
|
|
292
|
// Create the same and assert it already exists.
|
293
|
$this->drupalPost('admin/structure/ds/fields/manage_block', $edit, t('Save'));
|
294
|
$this->assertText(t('The machine-readable name is already in use. It must be unique.'), t('Block test field already exists.'));
|
295
|
|
296
|
$this->dsSelectLayout();
|
297
|
|
298
|
// Assert it's found on the Field UI for article.
|
299
|
$this->drupalGet('admin/structure/types/manage/article/display');
|
300
|
$this->assertRaw('fields[test_block_field][weight]', t('Test block field found on node article.'));
|
301
|
|
302
|
// Assert it's not found on the Field UI for users.
|
303
|
$this->drupalGet('admin/config/people/accounts/display');
|
304
|
$this->assertNoRaw('fields[test_block_field][weight]', t('Test block field not found on user.'));
|
305
|
|
306
|
// Update testing label
|
307
|
$edit = array(
|
308
|
'name' => 'Test block field 2',
|
309
|
);
|
310
|
$this->drupalPost('admin/structure/ds/fields/manage_block/test_block_field', $edit, t('Save'));
|
311
|
$this->assertText(t('The field Test block field 2 has been saved'), t('Test field label updated'));
|
312
|
|
313
|
// Remove the block field.
|
314
|
$this->drupalPost('admin/structure/ds/fields/delete/test_block_field', array(), t('Delete'));
|
315
|
$this->assertText(t('The field Test block field 2 has been deleted'), t('Test field removed'));
|
316
|
|
317
|
// Assert the block field is gone at the manage display screen.
|
318
|
$this->drupalGet('admin/structure/types/manage/article/display');
|
319
|
$this->assertNoRaw('fields[test_block_field][weight]', t('Test block field not found on node article.'));
|
320
|
|
321
|
// Preprocess fields.
|
322
|
$edit = array(
|
323
|
'name' => 'Submitted',
|
324
|
'field' => 'submitted',
|
325
|
'entities[node]' => '1',
|
326
|
);
|
327
|
|
328
|
$this->dsCreatePreprocessField($edit);
|
329
|
|
330
|
// Create the same and assert it already exists.
|
331
|
$this->drupalPost('admin/structure/ds/fields/manage_custom', $edit, t('Save'));
|
332
|
$this->assertText(t('The machine-readable name is already in use. It must be unique.'), t('Submitted already exists.'));
|
333
|
|
334
|
$this->dsSelectLayout();
|
335
|
|
336
|
// Assert it's found on the Field UI for article.
|
337
|
$this->drupalGet('admin/structure/types/manage/article/display');
|
338
|
$this->assertRaw('fields[submitted][weight]', t('Submitted found on node article.'));
|
339
|
|
340
|
// Assert it's not found on the Field UI for users.
|
341
|
$this->drupalGet('admin/config/people/accounts/display');
|
342
|
$this->assertNoRaw('fields[submitted][weight]', t('Submitted not found on user.'));
|
343
|
|
344
|
// Update testing label
|
345
|
$edit = array(
|
346
|
'name' => 'Submitted by',
|
347
|
);
|
348
|
$this->drupalPost('admin/structure/ds/fields/manage_preprocess/submitted', $edit, t('Save'));
|
349
|
$this->assertText(t('The field Submitted by has been saved'), t('Submitted label updated'));
|
350
|
|
351
|
// Remove a field.
|
352
|
$this->drupalPost('admin/structure/ds/fields/delete/submitted', array(), t('Delete'));
|
353
|
$this->assertText(t('The field Submitted by has been deleted'), t('Submitted removed'));
|
354
|
|
355
|
// Assert the field is gone at the manage display screen.
|
356
|
$this->drupalGet('admin/structure/types/manage/article/display');
|
357
|
$this->assertNoRaw('fields[submitted][weight]', t('Submitted field not found on node article.'));
|
358
|
|
359
|
// Dynamic fields.
|
360
|
$edit = array(
|
361
|
'name' => 'Dynamic',
|
362
|
'field' => 'dynamic',
|
363
|
'entities[node]' => '1',
|
364
|
);
|
365
|
|
366
|
$this->dsCreateDynamicField($edit);
|
367
|
|
368
|
// Create the same and assert it already exists.
|
369
|
$this->drupalPost('admin/structure/ds/fields/manage_ctools', $edit, t('Save'));
|
370
|
$this->assertText(t('The machine-readable name is already in use. It must be unique.'), t('Dynamic already exists.'));
|
371
|
|
372
|
$this->dsSelectLayout();
|
373
|
|
374
|
// Assert it's found on the Field UI for article.
|
375
|
$this->drupalGet('admin/structure/types/manage/article/display');
|
376
|
$this->assertRaw('fields[dynamic][weight]', t('Dynamic found on node article.'));
|
377
|
|
378
|
// Assert it's not found on the Field UI for users.
|
379
|
$this->drupalGet('admin/config/people/accounts/display');
|
380
|
$this->assertNoRaw('fields[dynamic][weight]', t('Dynamic not found on user.'));
|
381
|
|
382
|
// Update testing label
|
383
|
$edit = array(
|
384
|
'name' => 'Uber dynamic',
|
385
|
);
|
386
|
$this->drupalPost('admin/structure/ds/fields/manage_ctools/dynamic', $edit, t('Save'));
|
387
|
$this->assertText(t('The field Uber dynamic has been saved'), t('Dynamic label updated'));
|
388
|
|
389
|
// Remove a field.
|
390
|
$this->drupalPost('admin/structure/ds/fields/delete/dynamic', array(), t('Delete'));
|
391
|
$this->assertText(t('The field Uber dynamic has been deleted'), t('Dynamic removed'));
|
392
|
|
393
|
// Assert the field is gone at the manage display screen.
|
394
|
$this->drupalGet('admin/structure/types/manage/article/display');
|
395
|
$this->assertNoRaw('fields[dynamic][weight]', t('Dynamic field not found on node article.'));
|
396
|
}
|
397
|
}
|
398
|
|
399
|
/**
|
400
|
* Test managing of view modes.
|
401
|
*/
|
402
|
class dsViewModesTests extends dsBaseTest {
|
403
|
|
404
|
/**
|
405
|
* Implements getInfo().
|
406
|
*/
|
407
|
public static function getInfo() {
|
408
|
return array(
|
409
|
'name' => t('View modes'),
|
410
|
'description' => t('Tests for managing custom view modes.'),
|
411
|
'group' => t('Display Suite'),
|
412
|
);
|
413
|
}
|
414
|
|
415
|
/**
|
416
|
* Test managing view modes.
|
417
|
*/
|
418
|
function testDSManageViewModes() {
|
419
|
|
420
|
$edit = array(
|
421
|
'name' => 'Testing',
|
422
|
'view_mode' => 'testing',
|
423
|
'entities[node]' => '1'
|
424
|
);
|
425
|
|
426
|
$this->dsCreateViewMode($edit);
|
427
|
|
428
|
// Create the same and assert it already exists.
|
429
|
$this->drupalPost('admin/structure/ds/view_modes/manage', $edit, t('Save'));
|
430
|
$this->assertText(t('The machine-readable name is already in use. It must be unique.'), t('View mode testing already exists.'));
|
431
|
|
432
|
// Assert it's found on the Field UI for article.
|
433
|
$this->drupalGet('admin/structure/types/manage/article/display');
|
434
|
$this->assertRaw('additional_settings[modes][view_modes_custom][testing]', t('Testing view mode found on node article.'));
|
435
|
|
436
|
// Assert it's not found on the Field UI for article.
|
437
|
$this->drupalGet('admin/config/people/accounts/display');
|
438
|
$this->assertNoRaw('additional_settings[modes][view_modes_custom][testing]', t('Testing view mode not found on user.'));
|
439
|
|
440
|
// Update testing label
|
441
|
$edit = array(
|
442
|
'name' => 'Testing 2',
|
443
|
);
|
444
|
$this->drupalPost('admin/structure/ds/view_modes/manage/testing', $edit, t('Save'));
|
445
|
$this->assertText(t('The view mode Testing 2 has been saved'), t('Testing label updated'));
|
446
|
|
447
|
// Remove a view mode.
|
448
|
$this->drupalPost('admin/structure/ds/view_modes/delete/testing', array(), t('Delete'));
|
449
|
$this->assertText(t('The view mode Testing 2 has been deleted'), t('Testing view mode removed'));
|
450
|
|
451
|
// Assert the view mode is gone at the manage display screen.
|
452
|
$this->drupalGet('admin/structure/types/manage/article/display');
|
453
|
$this->assertNoRaw('additional_settings[modes][view_modes_custom][testing]', t('Testing view mode found on node article.'));
|
454
|
}
|
455
|
}
|
456
|
|
457
|
/**
|
458
|
* Test managing of layouts and CSS classes
|
459
|
*/
|
460
|
class dsLayoutsClassesTests extends dsBaseTest {
|
461
|
|
462
|
/**
|
463
|
* Implements getInfo().
|
464
|
*/
|
465
|
public static function getInfo() {
|
466
|
return array(
|
467
|
'name' => t('Layouts'),
|
468
|
'description' => t('Tests for managing layouts and classes on Field UI screen.'),
|
469
|
'group' => t('Display Suite'),
|
470
|
);
|
471
|
}
|
472
|
|
473
|
/**
|
474
|
* Test selecting layouts, classes, region to block and fields.
|
475
|
*/
|
476
|
function testDStestLayouts() {
|
477
|
|
478
|
// Check that the ds_3col_equal_width layout is not available (through the alter).
|
479
|
$this->drupalGet('admin/structure/types/manage/article/display');
|
480
|
$this->assertNoRaw('ds_3col_stacked_equal_width', 'ds_3col_stacked_equal_width not available');
|
481
|
|
482
|
// Create code, dynamic, preprocess block field.
|
483
|
$this->dsCreateCodeField();
|
484
|
$this->dsCreateBlockField();
|
485
|
$this->dsCreateDynamicField();
|
486
|
$this->dsCreatePreprocessField();
|
487
|
|
488
|
$layout = array(
|
489
|
'additional_settings[layout]' => 'ds_2col_stacked',
|
490
|
);
|
491
|
|
492
|
$assert = array(
|
493
|
'regions' => array(
|
494
|
'header' => '<td colspan="8">' . t('Header') . '</td>',
|
495
|
'left' => '<td colspan="8">' . t('Left') . '</td>',
|
496
|
'right' => '<td colspan="8">' . t('Right') . '</td>',
|
497
|
'footer' => '<td colspan="8">' . t('Footer') . '</td>',
|
498
|
),
|
499
|
);
|
500
|
|
501
|
$fields = array(
|
502
|
'fields[post_date][region]' => 'header',
|
503
|
'fields[author][region]' => 'left',
|
504
|
'fields[links][region]' => 'left',
|
505
|
'fields[body][region]' => 'right',
|
506
|
'fields[comments][region]' => 'footer',
|
507
|
'fields[test_field][region]' => 'left',
|
508
|
'fields[test_block_field][region]' => 'left',
|
509
|
'fields[submitted][region]' => 'left',
|
510
|
'fields[dynamic][region]' => 'left',
|
511
|
'fields[ds_extras_extra_test_field][region]' => 'header',
|
512
|
);
|
513
|
|
514
|
// Setup first layout.
|
515
|
$this->dsSelectLayout($layout, $assert);
|
516
|
$this->dsConfigureClasses();
|
517
|
$this->dsSelectClasses();
|
518
|
$this->dsConfigureUI($fields);
|
519
|
|
520
|
// Assert the two extra fields are found.
|
521
|
$this->drupalGet('admin/structure/types/manage/article/display');
|
522
|
$this->assertRaw('ds_extras_extra_test_field');
|
523
|
$this->assertRaw('ds_extras_second_field');
|
524
|
|
525
|
// Assert we have some configuration in our database.
|
526
|
$count = db_query("SELECT COUNT(settings) FROM {ds_layout_settings} WHERE entity_type = 'node' AND bundle = 'article' AND view_mode = 'default'")->fetchField();
|
527
|
$this->assertEqual($count, 1, t('1 record found for layout serttings for node article'));
|
528
|
|
529
|
// Lookup settings and verify.
|
530
|
$data = unserialize(db_query("SELECT settings FROM {ds_layout_settings} WHERE entity_type = 'node' AND bundle = 'article' AND view_mode = 'default'")->fetchField());
|
531
|
$this->assertTrue(in_array('ds_extras_extra_test_field', $data['regions']['header']), t('Extra field is in header'));
|
532
|
$this->assertTrue(in_array('post_date', $data['regions']['header']), t('Post date is in header'));
|
533
|
$this->assertTrue(in_array('test_field', $data['regions']['left']), t('Test field is in left'));
|
534
|
$this->assertTrue(in_array('author', $data['regions']['left']), t('Author is in left'));
|
535
|
$this->assertTrue(in_array('links', $data['regions']['left']), t('Links is in left'));
|
536
|
$this->assertTrue(in_array('test_block_field', $data['regions']['left']), t('Test block field is in left'));
|
537
|
$this->assertTrue(in_array('submitted', $data['regions']['left']), t('Submitted field is in left'));
|
538
|
$this->assertTrue(in_array('dynamic', $data['regions']['left']), t('Dynamic field is in left'));
|
539
|
$this->assertTrue(in_array('body', $data['regions']['right']), t('Body is in right'));
|
540
|
$this->assertTrue(in_array('comments', $data['regions']['footer']), t('Comments is in footer'));
|
541
|
$this->assertTrue(in_array('class_name_1', $data['classes']['header']), t('Class name 1 is in header'));
|
542
|
$this->assertTrue(empty($data['classes']['left']), t('Left has no classes'));
|
543
|
$this->assertTrue(empty($data['classes']['right']), t('Right has classes'));
|
544
|
$this->assertTrue(in_array('class_name_2', $data['classes']['footer']), t('Class name 2 is in header'));
|
545
|
|
546
|
// Extra save for the dynamic field.
|
547
|
$field_settings = ds_get_field_settings('node', 'article', 'default');
|
548
|
$formatter_settings = array(
|
549
|
'show_title' => 0,
|
550
|
'title_wrapper' => '',
|
551
|
'ctools' => 'a:3:{s:4:"conf";a:3:{s:7:"context";s:25:"argument_entity_id:node_1";s:14:"override_title";i:0;s:19:"override_title_text";s:0:"";}s:4:"type";s:14:"node_type_desc";s:7:"subtype";s:14:"node_type_desc";}',
|
552
|
);
|
553
|
$field_settings['dynamic']['formatter_settings'] = $formatter_settings;
|
554
|
$record = new stdClass();
|
555
|
$record->id = 'node|article|default';
|
556
|
$record->entity_type = 'node';
|
557
|
$record->bundle = 'article';
|
558
|
$record->view_mode = 'default';
|
559
|
$record->settings = $field_settings;
|
560
|
drupal_write_record('ds_field_settings', $record, array('id'));
|
561
|
cache_clear_all('ds_fields:', 'cache', TRUE);
|
562
|
cache_clear_all('ds_field_settings', 'cache');
|
563
|
|
564
|
// Create a article node and verify settings.
|
565
|
$settings = array(
|
566
|
'type' => 'article',
|
567
|
);
|
568
|
$node = $this->drupalCreateNode($settings);
|
569
|
$this->drupalGet('node/' . $node->nid);
|
570
|
|
571
|
// Assert regions.
|
572
|
$this->assertRaw('group-header', 'Template found (region header)');
|
573
|
$this->assertRaw('group-header class_name_1', 'Class found (class_name_1)');
|
574
|
$this->assertRaw('group-left', 'Template found (region left)');
|
575
|
$this->assertRaw('group-right', 'Template found (region right)');
|
576
|
$this->assertRaw('group-footer', 'Template found (region footer)');
|
577
|
$this->assertRaw('group-footer class_name_2', 'Class found (class_name_2)');
|
578
|
|
579
|
// Assert custom fields.
|
580
|
$this->assertRaw('field-name-test-field', t('Custom field found'));
|
581
|
$this->assertRaw('Test field', t('Custom field found'));
|
582
|
$this->assertRaw('field-name-test-block-field', t('Custom block field found'));
|
583
|
$this->assertRaw('<h2>Recent content</h2>', t('Custom block field found'));
|
584
|
$this->assertRaw('Submitted by', t('Submitted field found'));
|
585
|
$this->assertText('Use articles for time-sensitive content like news, press releases or blog posts.', t('Dynamic field found'));
|
586
|
$this->assertText('This is an extra field made available through "Extra fields" functionality.');
|
587
|
|
588
|
// Test disable sidebar regions.
|
589
|
$this->drupalGet('node/' . $node->nid);
|
590
|
$this->assertRaw('sidebar-first', 'Left sidebar found.');
|
591
|
$hide = array(
|
592
|
'additional_settings[hide_sidebars]' => '1',
|
593
|
);
|
594
|
$this->dsConfigureUI($hide);
|
595
|
$this->drupalGet('node/' . $node->nid);
|
596
|
$this->assertNoRaw('sidebar-first', 'Left sidebar not found.');
|
597
|
|
598
|
// Test HTML5 wrappers
|
599
|
$this->assertNoRaw('<header', 'Header not found.');
|
600
|
$this->assertNoRaw('<footer', 'Footer not found.');
|
601
|
$this->assertNoRaw('<article', 'Article not found.');
|
602
|
$wrappers = array(
|
603
|
'additional_settings[region_wrapper][header]' => 'header',
|
604
|
'additional_settings[region_wrapper][right]' => 'footer',
|
605
|
'additional_settings[region_wrapper][layout_wrapper]' => 'article',
|
606
|
);
|
607
|
$this->dsConfigureUI($wrappers);
|
608
|
$this->drupalGet('node/' . $node->nid);
|
609
|
$this->assertRaw('<header', 'Header found.');
|
610
|
$this->assertRaw('<footer', 'Footer found.');
|
611
|
$this->assertRaw('<article', 'Article found.');
|
612
|
|
613
|
// Let's create a block field, enable the full mode first.
|
614
|
$edit = array('additional_settings[modes][view_modes_custom][full]' => '1');
|
615
|
$this->drupalPost('admin/structure/types/manage/article/display', $edit, t('Save'));
|
616
|
|
617
|
// Select layout.
|
618
|
$layout = array(
|
619
|
'additional_settings[layout]' => 'ds_2col',
|
620
|
);
|
621
|
|
622
|
$assert = array(
|
623
|
'regions' => array(
|
624
|
'left' => '<td colspan="8">' . t('Left') . '</td>',
|
625
|
'right' => '<td colspan="8">' . t('Right') . '</td>',
|
626
|
),
|
627
|
);
|
628
|
$this->dsSelectLayout($layout, $assert, 'admin/structure/types/manage/article/display/full');
|
629
|
|
630
|
// Create new block field.
|
631
|
$edit = array(
|
632
|
'additional_settings[region_to_block][new_block_region]' => 'Block region',
|
633
|
'additional_settings[region_to_block][new_block_region_key]' => 'block_region',
|
634
|
);
|
635
|
$this->drupalPost('admin/structure/types/manage/article/display/full', $edit, t('Save'));
|
636
|
$this->assertRaw('<td colspan="8">' . t('Block region') . '</td>', 'Block region found');
|
637
|
|
638
|
// Configure fields
|
639
|
$fields = array(
|
640
|
'fields[author][region]' => 'left',
|
641
|
'fields[links][region]' => 'left',
|
642
|
'fields[body][region]' => 'right',
|
643
|
'fields[ds_test_field][region]' => 'block_region',
|
644
|
);
|
645
|
$this->dsConfigureUI($fields, 'admin/structure/types/manage/article/display/full');
|
646
|
|
647
|
// Set block in sidebar
|
648
|
$edit = array(
|
649
|
'blocks[ds_extras_block_region][region]' => 'sidebar_first',
|
650
|
);
|
651
|
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
|
652
|
|
653
|
// Assert the block is on the node page.
|
654
|
$this->drupalGet('node/' . $node->nid);
|
655
|
$this->assertRaw('<h2>Block region</h2>', 'Block region found');
|
656
|
$this->assertText('Test code field on node ' . $node->nid, 'Post date in block');
|
657
|
|
658
|
// Change layout via admin/structure/ds/layout-change.
|
659
|
// First verify that header and footer are not here.
|
660
|
$this->drupalGet('admin/structure/types/manage/article/display/full');
|
661
|
$this->assertNoRaw('<td colspan="8">' . t('Header') . '</td>', 'Header region not found');
|
662
|
$this->assertNoRaw('<td colspan="8">' . t('Footer') . '</td>', 'Footer region not found');
|
663
|
|
664
|
// Remap the regions.
|
665
|
$edit = array(
|
666
|
'ds_left' => 'header',
|
667
|
'ds_right' => 'footer',
|
668
|
'ds_block_region' => 'footer',
|
669
|
);
|
670
|
$this->drupalPost('admin/structure/ds/change-layout/node/article/full/ds_2col_stacked', $edit, t('Save'), array('query' => array('destination' => 'admin/structure/types/manage/article/display/full')));
|
671
|
|
672
|
// Verify new regions.
|
673
|
$this->assertRaw('<td colspan="8">' . t('Header') . '</td>', 'Header region found');
|
674
|
$this->assertRaw('<td colspan="8">' . t('Footer') . '</td>', 'Footer region found');
|
675
|
$this->assertRaw('<td colspan="8">' . t('Block region') . '</td>', 'Block region found');
|
676
|
|
677
|
// Verify settings.
|
678
|
$data = unserialize(db_query("SELECT settings FROM {ds_layout_settings} WHERE entity_type = 'node' AND bundle = 'article' AND view_mode = 'full'")->fetchField());
|
679
|
$this->assertTrue(in_array('author', $data['regions']['header']), t('Author is in header'));
|
680
|
$this->assertTrue(in_array('links', $data['regions']['header']), t('Links field is in header'));
|
681
|
$this->assertTrue(in_array('body', $data['regions']['footer']), t('Body field is in footer'));
|
682
|
$this->assertTrue(in_array('ds_test_field', $data['regions']['footer']), t('Test field is in footer'));
|
683
|
|
684
|
// Test that a default view mode with no layout is not affected by a disabled view mode.
|
685
|
$edit = array(
|
686
|
'additional_settings[layout]' => '',
|
687
|
'additional_settings[modes][view_modes_custom][full]' => FALSE,
|
688
|
);
|
689
|
$this->drupalPost('admin/structure/types/manage/article/display', $edit, t('Save'));
|
690
|
$this->drupalGet('node/' . $node->nid);
|
691
|
$this->assertNoText('Test code field on node 1', 'No ds field from full view mode layout');
|
692
|
}
|
693
|
}
|
694
|
|
695
|
/**
|
696
|
* Tests for Display Suite field permissions.
|
697
|
*/
|
698
|
class dsFieldPermissionTests extends dsBaseTest {
|
699
|
|
700
|
/**
|
701
|
* Implements getInfo().
|
702
|
*/
|
703
|
public static function getInfo() {
|
704
|
return array(
|
705
|
'name' => t('Field permissions'),
|
706
|
'description' => t('Tests for testing field permissions.'),
|
707
|
'group' => t('Display Suite'),
|
708
|
);
|
709
|
}
|
710
|
|
711
|
function testFieldPermissions() {
|
712
|
|
713
|
$fields = array(
|
714
|
'fields[body][region]' => 'right',
|
715
|
'fields[ds_test_field][region]' => 'left',
|
716
|
);
|
717
|
|
718
|
variable_set('ds_extras_field_permissions', TRUE);
|
719
|
$this->refreshVariables();
|
720
|
module_implements(FALSE, FALSE, TRUE);
|
721
|
|
722
|
$this->dsSelectLayout();
|
723
|
$this->dsConfigureUI($fields);
|
724
|
|
725
|
// Create a node.
|
726
|
$settings = array('type' => 'article');
|
727
|
$node = $this->drupalCreateNode($settings);
|
728
|
$this->drupalGet('node/' . $node->nid);
|
729
|
$this->assertRaw('group-right', 'Template found (region right)');
|
730
|
$this->assertNoText('Test code field on node ' . $node->nid, 'Test code field not found');
|
731
|
|
732
|
// Give permissions.
|
733
|
$edit = array(
|
734
|
'2[view author on node]' => 1,
|
735
|
'2[view ds_test_field on node]' => 1,
|
736
|
);
|
737
|
$this->drupalPost('admin/people/permissions', $edit, t('Save permissions'));
|
738
|
$this->drupalGet('node/' . $node->nid);
|
739
|
$this->assertRaw('group-left', 'Template found (region left)');
|
740
|
$this->assertText('Test code field on node ' . $node->nid, 'Test code field found');
|
741
|
}
|
742
|
}
|
743
|
|
744
|
/**
|
745
|
* Tests for Display Suite hooks.
|
746
|
*/
|
747
|
class dsHooksTests extends dsBaseTest {
|
748
|
|
749
|
/**
|
750
|
* Implements getInfo().
|
751
|
*/
|
752
|
public static function getInfo() {
|
753
|
return array(
|
754
|
'name' => t('Hooks'),
|
755
|
'description' => t('Tests for hooks: ds_fields, ds_fields_alter, ds_layouts.'),
|
756
|
'group' => t('Display Suite'),
|
757
|
);
|
758
|
}
|
759
|
|
760
|
/**
|
761
|
* Test fields hooks.
|
762
|
*/
|
763
|
function testDSFields() {
|
764
|
|
765
|
$this->dsSelectLayout();
|
766
|
|
767
|
// Find the two extra fields from the test module on the node type.
|
768
|
$this->drupalGet('admin/structure/types/manage/article/display');
|
769
|
$this->assertText('Test code field from hook', 'Test field found on node.');
|
770
|
$this->assertText('Field altered', 'Test field altered found on node.');
|
771
|
|
772
|
$empty = array();
|
773
|
$edit = array('additional_settings[layout]' => 'ds_2col_stacked');
|
774
|
$this->dsSelectLayout($edit, $empty, 'admin/config/people/accounts/display');
|
775
|
|
776
|
// Fields can not be found on user.
|
777
|
$this->drupalGet('admin/config/people/accounts/display');
|
778
|
$this->assertNoText('Test code field from hook', 'Test field not found on user.');
|
779
|
$this->assertNoText('Field altered', 'Test field altered not found on user.');
|
780
|
|
781
|
// Select layout.
|
782
|
$this->dsSelectLayout();
|
783
|
|
784
|
$fields = array(
|
785
|
'fields[author][region]' => 'left',
|
786
|
'fields[links][region]' => 'left',
|
787
|
'fields[body][region]' => 'right',
|
788
|
'fields[ds_test_field][region]' => 'right',
|
789
|
'fields[ds_test_field_empty_string][region]' => 'right',
|
790
|
'fields[ds_test_field_empty_string][label]' => 'inline',
|
791
|
'fields[ds_test_field_false][region]' => 'right',
|
792
|
'fields[ds_test_field_false][label]' => 'inline',
|
793
|
'fields[ds_test_field_null][region]' => 'right',
|
794
|
'fields[ds_test_field_null][label]' => 'inline',
|
795
|
'fields[ds_test_field_nothing][region]' => 'right',
|
796
|
'fields[ds_test_field_nothing][label]' => 'inline',
|
797
|
'fields[ds_test_field_zero_int][region]' => 'right',
|
798
|
'fields[ds_test_field_zero_int][label]' => 'inline',
|
799
|
'fields[ds_test_field_zero_string][region]' => 'right',
|
800
|
'fields[ds_test_field_zero_string][label]' => 'inline',
|
801
|
'fields[ds_test_field_zero_float][region]' => 'right',
|
802
|
'fields[ds_test_field_zero_float][label]' => 'inline',
|
803
|
);
|
804
|
|
805
|
$this->dsSelectLayout();
|
806
|
$this->dsConfigureUI($fields);
|
807
|
|
808
|
// Create a node.
|
809
|
$settings = array('type' => 'article');
|
810
|
$node = $this->drupalCreateNode($settings);
|
811
|
$this->drupalGet('node/' . $node->nid);
|
812
|
|
813
|
$this->assertRaw('group-left', 'Template found (region left)');
|
814
|
$this->assertRaw('group-right', 'Template found (region right)');
|
815
|
$this->assertText('Test code field on node ' . $node->nid, 'Test code field found');
|
816
|
$this->assertNoText('Test code field that returns an empty string', 'Test code field that returns an empty string is not visible.');
|
817
|
$this->assertNoText('Test code field that returns FALSE', 'Test code field that returns FALSE is not visible.');
|
818
|
$this->assertNoText('Test code field that returns NULL', 'Test code field that returns NULL is not visible.');
|
819
|
$this->assertNoText('Test code field that returns nothing', 'Test code field that returns nothing is not visible.');
|
820
|
$this->assertNoText('Test code field that returns an empty array', 'Test code field that returns an empty array is not visible.');
|
821
|
$this->assertText('Test code field that returns zero as an integer', 'Test code field that returns zero as an integer is visible.');
|
822
|
$this->assertText('Test code field that returns zero as a string', 'Test code field that returns zero as a string is visible.');
|
823
|
$this->assertText('Test code field that returns zero as a floating point number', 'Test code field that returns zero as a floating point number is visible.');
|
824
|
}
|
825
|
|
826
|
/**
|
827
|
* Test layouts hook.
|
828
|
*/
|
829
|
function testDSLayouts() {
|
830
|
|
831
|
// Assert our 2 tests layouts are found.
|
832
|
$this->drupalGet('admin/structure/types/manage/article/display');
|
833
|
$this->assertRaw('Test One column', 'Test One column layout found');
|
834
|
$this->assertRaw('Test Two column', 'Test Two column layout found');
|
835
|
|
836
|
$layout = array(
|
837
|
'additional_settings[layout]' => 'dstest_2col',
|
838
|
);
|
839
|
|
840
|
$assert = array(
|
841
|
'regions' => array(
|
842
|
'left' => '<td colspan="8">' . t('Left') . '</td>',
|
843
|
'right' => '<td colspan="8">' . t('Right') . '</td>',
|
844
|
),
|
845
|
);
|
846
|
|
847
|
$fields = array(
|
848
|
'fields[author][region]' => 'left',
|
849
|
'fields[links][region]' => 'left',
|
850
|
'fields[body][region]' => 'right',
|
851
|
);
|
852
|
|
853
|
$this->dsSelectLayout($layout, $assert);
|
854
|
$this->dsConfigureUI($fields);
|
855
|
|
856
|
// Create a node.
|
857
|
$settings = array('type' => 'article');
|
858
|
$node = $this->drupalCreateNode($settings);
|
859
|
|
860
|
$this->drupalGet('node/' . $node->nid);
|
861
|
$this->assertRaw('group-left', 'Template found (region left)');
|
862
|
$this->assertRaw('group-right', 'Template found (region right)');
|
863
|
$this->assertRaw('dstest_2col.css', 'Css file included');
|
864
|
|
865
|
// Alter a region
|
866
|
$settings = array(
|
867
|
'type' => 'article',
|
868
|
'title' => 'Alter me!',
|
869
|
);
|
870
|
$node = $this->drupalCreateNode($settings);
|
871
|
$this->drupalGet('node/' . $node->nid);
|
872
|
$this->assertRaw('cool!', 'Region altered');
|
873
|
}
|
874
|
}
|