1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Test file for fieldgroup display.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Group display tests
|
10
|
*/
|
11
|
class GroupDisplayTestCase extends DrupalWebTestCase {
|
12
|
|
13
|
protected $node;
|
14
|
|
15
|
public static function getInfo() {
|
16
|
return array(
|
17
|
'name' => 'Display tests',
|
18
|
'description' => 'Test the field group display.',
|
19
|
'group' => 'Field group',
|
20
|
);
|
21
|
}
|
22
|
|
23
|
function setUp() {
|
24
|
|
25
|
parent::setUp('field_test', 'field_group', 'field_group_test');
|
26
|
|
27
|
$node = new stdClass();
|
28
|
$node->type = 'article';
|
29
|
$node->title = $this->randomName();
|
30
|
$node->status = 1;
|
31
|
|
32
|
// Create test fields.
|
33
|
$test_fields = array('field_test', 'field_test_2', 'field_no_access');
|
34
|
foreach ($test_fields as $field_name) {
|
35
|
|
36
|
$field = array(
|
37
|
'field_name' => $field_name,
|
38
|
'type' => 'test_field',
|
39
|
'cardinality' => 1,
|
40
|
);
|
41
|
$instance = array(
|
42
|
'field_name' => $field_name,
|
43
|
'entity_type' => 'node',
|
44
|
'bundle' => 'article',
|
45
|
'label' => $this->randomName(),
|
46
|
'display' => array(
|
47
|
'default' => array(
|
48
|
'type' => 'field_test_default',
|
49
|
'settings' => array(
|
50
|
'test_formatter_setting' => $this->randomName(),
|
51
|
),
|
52
|
),
|
53
|
'teaser' => array(
|
54
|
'type' => 'field_test_default',
|
55
|
'settings' => array(
|
56
|
'test_formatter_setting' => $this->randomName(),
|
57
|
),
|
58
|
),
|
59
|
),
|
60
|
);
|
61
|
field_create_field($field);
|
62
|
field_create_instance($instance);
|
63
|
|
64
|
$node->{$field_name}[LANGUAGE_NONE][0]['value'] = mt_rand(1, 127);
|
65
|
}
|
66
|
|
67
|
node_save($node);
|
68
|
$this->node = $node;
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Create a new group.
|
73
|
* @param array $data
|
74
|
* Data for the field group.
|
75
|
*/
|
76
|
function createGroup($mode, array $data) {
|
77
|
|
78
|
$group_name = 'group_' . drupal_strtolower($this->randomName(8));
|
79
|
$identifier = $group_name . '|node|article|' . $mode;
|
80
|
|
81
|
$field_group = new stdClass;
|
82
|
$field_group->disabled = FALSE;
|
83
|
$field_group->api_version = 1;
|
84
|
$field_group->identifier = $identifier;
|
85
|
$field_group->group_name = $group_name;
|
86
|
$field_group->entity_type = 'node';
|
87
|
$field_group->bundle = 'article';
|
88
|
$field_group->mode = $mode;
|
89
|
$field_group->parent_name = '';
|
90
|
$field_group->children = $data['children'];
|
91
|
$field_group->data = $data;
|
92
|
drupal_write_record('field_group', $field_group);
|
93
|
ctools_export_crud_enable('field_group', $field_group->identifier);
|
94
|
|
95
|
return $field_group;
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* Test if an empty formatter.
|
100
|
*/
|
101
|
function testFieldAccess() {
|
102
|
|
103
|
$data = array(
|
104
|
'label' => 'Wrapper',
|
105
|
'weight' => '1',
|
106
|
'children' => array(
|
107
|
0 => 'field_no_access',
|
108
|
),
|
109
|
'format_type' => 'div',
|
110
|
'format_settings' => array(
|
111
|
'label' => 'Link',
|
112
|
'instance_settings' => array(
|
113
|
'required_fields' => 0,
|
114
|
'id' => 'wrapper-id',
|
115
|
'classes' => 'test-class',
|
116
|
'description' => '',
|
117
|
'show_label' => FALSE,
|
118
|
'label_element' => 'h3',
|
119
|
'effect' => 'blink',
|
120
|
'speed' => 'fast',
|
121
|
),
|
122
|
'formatter' => 'open',
|
123
|
),
|
124
|
);
|
125
|
$group = $this->createGroup('default', $data);
|
126
|
|
127
|
$groups = field_group_info_groups('node', 'article', 'default', TRUE);
|
128
|
$this->drupalGet('node/' . $this->node->nid);
|
129
|
|
130
|
// Test if group is not shown.
|
131
|
$this->assertNoFieldByXPath("//div[contains(@id, 'wrapper-id')]", NULL, t('Div that contains fields with no access is not shown.'));
|
132
|
}
|
133
|
|
134
|
/**
|
135
|
* Test the div formatter.
|
136
|
*/
|
137
|
function testDiv() {
|
138
|
|
139
|
$data = array(
|
140
|
'label' => 'Wrapper',
|
141
|
'weight' => '1',
|
142
|
'children' => array(
|
143
|
0 => 'field_test',
|
144
|
),
|
145
|
'format_type' => 'div',
|
146
|
'format_settings' => array(
|
147
|
'label' => 'Link',
|
148
|
'instance_settings' => array(
|
149
|
'required_fields' => 0,
|
150
|
'id' => 'wrapper-id',
|
151
|
'classes' => 'test-class',
|
152
|
'description' => '',
|
153
|
'show_label' => FALSE,
|
154
|
'label_element' => 'h3',
|
155
|
'effect' => 'blink',
|
156
|
'speed' => 'fast',
|
157
|
),
|
158
|
'formatter' => 'open',
|
159
|
),
|
160
|
);
|
161
|
$group = $this->createGroup('default', $data);
|
162
|
|
163
|
$groups = field_group_info_groups('node', 'article', 'default', TRUE);
|
164
|
$this->drupalGet('node/' . $this->node->nid);
|
165
|
|
166
|
// Test group ids and classes.
|
167
|
$this->assertFieldByXPath("//div[contains(@id, 'wrapper-id')]", NULL, t('Wrapper id set on wrapper div'));
|
168
|
$this->assertFieldByXPath("//div[contains(@class, 'test-class')]", NULL, t('Test class set on wrapper div') . 'class="' . $group->group_name . ' test-class');
|
169
|
|
170
|
// Test group label.
|
171
|
$this->assertNoRaw('<h3><span>' . $data['label'] . '</span></h3>', t('Label is not shown'));
|
172
|
|
173
|
// Set show label to true.
|
174
|
$group->data['format_settings']['instance_settings']['show_label'] = TRUE;
|
175
|
|
176
|
drupal_write_record('field_group', $group, array('identifier'));
|
177
|
$groups = field_group_info_groups('node', 'article', 'default', TRUE);
|
178
|
$this->drupalGet('node/' . $this->node->nid);
|
179
|
$this->assertRaw('<h3><span>' . $data['label'] . '</span></h3>', t('Label is shown'));
|
180
|
|
181
|
// Change to collapsible
|
182
|
$group->data['format_settings']['formatter'] = 'collapsible';
|
183
|
drupal_write_record('field_group', $group, array('identifier'));
|
184
|
$groups = field_group_info_groups('node', 'article', 'default', TRUE);
|
185
|
$this->drupalGet('node/' . $this->node->nid);
|
186
|
$this->assertFieldByXPath("//div[contains(@class, 'speed-fast')]", NULL, t('Speed class is set'));
|
187
|
$this->assertFieldByXPath("//div[contains(@class, 'effect-blink')]", NULL, t('Effect class is set'));
|
188
|
}
|
189
|
|
190
|
/**
|
191
|
* Test the horizontal tabs formatter.
|
192
|
*/
|
193
|
function testHorizontalTabs() {
|
194
|
|
195
|
$data = array(
|
196
|
'label' => 'Tab 1',
|
197
|
'weight' => '1',
|
198
|
'children' => array(
|
199
|
0 => 'field_test',
|
200
|
),
|
201
|
'format_type' => 'htab',
|
202
|
'format_settings' => array(
|
203
|
'label' => 'Tab 1',
|
204
|
'instance_settings' => array(
|
205
|
'classes' => 'test-class',
|
206
|
'description' => '',
|
207
|
),
|
208
|
'formatter' => 'open',
|
209
|
),
|
210
|
);
|
211
|
$first_tab = $this->createGroup('default', $data);
|
212
|
$first_tab_id = 'node_article_full_' . $first_tab->group_name;
|
213
|
|
214
|
$data = array(
|
215
|
'label' => 'Tab 2',
|
216
|
'weight' => '1',
|
217
|
'children' => array(
|
218
|
0 => 'field_test_2',
|
219
|
),
|
220
|
'format_type' => 'htab',
|
221
|
'format_settings' => array(
|
222
|
'label' => 'Tab 1',
|
223
|
'instance_settings' => array(
|
224
|
'classes' => 'test-class-2',
|
225
|
'description' => 'description of second tab',
|
226
|
),
|
227
|
'formatter' => 'closed',
|
228
|
),
|
229
|
);
|
230
|
$second_tab = $this->createGroup('default', $data);
|
231
|
$second_tab_id = 'node_article_full_' . $first_tab->group_name;
|
232
|
|
233
|
$data = array(
|
234
|
'label' => 'Tabs',
|
235
|
'weight' => '1',
|
236
|
'children' => array(
|
237
|
0 => $first_tab->group_name,
|
238
|
1 => $second_tab->group_name,
|
239
|
),
|
240
|
'format_type' => 'htabs',
|
241
|
'format_settings' => array(
|
242
|
'label' => 'Tab 1',
|
243
|
'instance_settings' => array(
|
244
|
'classes' => 'test-class-wrapper',
|
245
|
),
|
246
|
),
|
247
|
);
|
248
|
$tabs = $this->createGroup('default', $data);
|
249
|
|
250
|
$groups = field_group_info_groups('node', 'article', 'default', TRUE);
|
251
|
|
252
|
$this->drupalGet('node/' . $this->node->nid);
|
253
|
|
254
|
// Test properties.
|
255
|
$this->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]", NULL, t('Test class set on tabs wrapper'));
|
256
|
$this->assertFieldByXPath("//fieldset[contains(@class, 'test-class-2')]", NULL, t('Test class set on second tab'));
|
257
|
$this->assertRaw('<div class="fieldset-description">description of second tab</div>', t('Description of tab is shown'));
|
258
|
$this->assertRaw('class="collapsible collapsed test-class-2', t('Second tab is default collapsed'));
|
259
|
|
260
|
// Test if correctly nested
|
261
|
$this->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]//fieldset[contains(@id, '$first_tab_id')]", NULL, 'First tab is displayed as child of the wrapper.');
|
262
|
$this->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]//fieldset[contains(@id, '$second_tab_id')]", NULL, 'Second tab is displayed as child of the wrapper.');
|
263
|
|
264
|
}
|
265
|
|
266
|
/**
|
267
|
* Test the vertical tabs formatter.
|
268
|
*/
|
269
|
function testVerticalTabs() {
|
270
|
|
271
|
$data = array(
|
272
|
'label' => 'Tab 1',
|
273
|
'weight' => '1',
|
274
|
'children' => array(
|
275
|
0 => 'field_test',
|
276
|
),
|
277
|
'format_type' => 'tab',
|
278
|
'format_settings' => array(
|
279
|
'label' => 'Tab 1',
|
280
|
'instance_settings' => array(
|
281
|
'classes' => 'test-class',
|
282
|
'description' => '',
|
283
|
),
|
284
|
'formatter' => 'open',
|
285
|
),
|
286
|
);
|
287
|
$first_tab = $this->createGroup('default', $data);
|
288
|
$first_tab_id = 'node_article_full_' . $first_tab->group_name;
|
289
|
|
290
|
$data = array(
|
291
|
'label' => 'Tab 2',
|
292
|
'weight' => '1',
|
293
|
'children' => array(
|
294
|
0 => 'field_test_2',
|
295
|
),
|
296
|
'format_type' => 'tab',
|
297
|
'format_settings' => array(
|
298
|
'label' => 'Tab 1',
|
299
|
'instance_settings' => array(
|
300
|
'classes' => 'test-class-2',
|
301
|
'description' => 'description of second tab',
|
302
|
),
|
303
|
'formatter' => 'closed',
|
304
|
),
|
305
|
);
|
306
|
$second_tab = $this->createGroup('default', $data);
|
307
|
$second_tab_id = 'node_article_full_' . $first_tab->group_name;
|
308
|
|
309
|
$data = array(
|
310
|
'label' => 'Tabs',
|
311
|
'weight' => '1',
|
312
|
'children' => array(
|
313
|
0 => $first_tab->group_name,
|
314
|
1 => $second_tab->group_name,
|
315
|
),
|
316
|
'format_type' => 'tabs',
|
317
|
'format_settings' => array(
|
318
|
'label' => 'Tab 1',
|
319
|
'instance_settings' => array(
|
320
|
'classes' => 'test-class-wrapper',
|
321
|
),
|
322
|
),
|
323
|
);
|
324
|
$tabs = $this->createGroup('default', $data);
|
325
|
|
326
|
$groups = field_group_info_groups('node', 'article', 'default', TRUE);
|
327
|
|
328
|
$this->drupalGet('node/' . $this->node->nid);
|
329
|
|
330
|
// Test properties.
|
331
|
$this->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]", NULL, t('Test class set on tabs wrapper'));
|
332
|
$this->assertFieldByXPath("//fieldset[contains(@class, 'test-class-2')]", NULL, t('Test class set on second tab'));
|
333
|
$this->assertRaw('<div class="fieldset-description">description of second tab</div>', t('Description of tab is shown'));
|
334
|
$this->assertRaw('class="collapsible collapsed test-class-2', t('Second tab is default collapsed'));
|
335
|
|
336
|
// Test if correctly nested
|
337
|
$this->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]//fieldset[contains(@id, '$first_tab_id')]", NULL, 'First tab is displayed as child of the wrapper.');
|
338
|
$this->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]//fieldset[contains(@id, '$second_tab_id')]", NULL, 'Second tab is displayed as child of the wrapper.');
|
339
|
}
|
340
|
|
341
|
/**
|
342
|
* Test the accordion formatter.
|
343
|
*/
|
344
|
function testAccordion() {
|
345
|
|
346
|
$data = array(
|
347
|
'label' => 'Accordion item 1',
|
348
|
'weight' => '1',
|
349
|
'children' => array(
|
350
|
0 => 'field_test',
|
351
|
),
|
352
|
'format_type' => 'accordion-item',
|
353
|
'format_settings' => array(
|
354
|
'label' => 'Accordion item 1',
|
355
|
'instance_settings' => array(
|
356
|
'classes' => 'test-class',
|
357
|
),
|
358
|
'formatter' => 'closed',
|
359
|
),
|
360
|
);
|
361
|
$first_item = $this->createGroup('default', $data);
|
362
|
$first_item_id = 'node_article_full_' . $first_item->group_name;
|
363
|
|
364
|
$data = array(
|
365
|
'label' => 'Accordion item 2',
|
366
|
'weight' => '1',
|
367
|
'children' => array(
|
368
|
0 => 'field_test_2',
|
369
|
),
|
370
|
'format_type' => 'accordion-item',
|
371
|
'format_settings' => array(
|
372
|
'label' => 'Tab 2',
|
373
|
'instance_settings' => array(
|
374
|
'classes' => 'test-class-2',
|
375
|
),
|
376
|
'formatter' => 'open',
|
377
|
),
|
378
|
);
|
379
|
$second_item = $this->createGroup('default', $data);
|
380
|
$second_item_id = 'node_article_full_' . $second_item->group_name;
|
381
|
|
382
|
$data = array(
|
383
|
'label' => 'Accordion',
|
384
|
'weight' => '1',
|
385
|
'children' => array(
|
386
|
0 => $first_item->group_name,
|
387
|
1 => $second_item->group_name,
|
388
|
),
|
389
|
'format_type' => 'accordion',
|
390
|
'format_settings' => array(
|
391
|
'label' => 'Tab 1',
|
392
|
'instance_settings' => array(
|
393
|
'classes' => 'test-class-wrapper',
|
394
|
'effect' => 'bounceslide'
|
395
|
),
|
396
|
),
|
397
|
);
|
398
|
$accordion = $this->createGroup('default', $data);
|
399
|
|
400
|
$groups = field_group_info_groups('node', 'article', 'default', TRUE);
|
401
|
|
402
|
$this->drupalGet('node/' . $this->node->nid);
|
403
|
|
404
|
// Test properties.
|
405
|
$this->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]", NULL, t('Test class set on tabs wrapper'));
|
406
|
$this->assertFieldByXPath("//div[contains(@class, 'effect-bounceslide')]", NULL, t('Correct effect is set on the accordion'));
|
407
|
$this->assertFieldByXPath("//div[contains(@class, 'test-class')]", NULL, t('Accordion item with test-class is shown'));
|
408
|
$this->assertFieldByXPath("//div[contains(@class, 'test-class-2')]", NULL, t('Accordion item with test-class-2 is shown'));
|
409
|
$this->assertFieldByXPath("//h3[contains(@class, 'field-group-accordion-active')]", NULL, t('Accordion item 2 was set active'));
|
410
|
|
411
|
// Test if correctly nested
|
412
|
$this->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]//div[contains(@class, 'test-class')]", NULL, 'First item is displayed as child of the wrapper.');
|
413
|
$this->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]//div[contains(@class, 'test-class-2')]", NULL, 'Second item is displayed as child of the wrapper.');
|
414
|
}
|
415
|
|
416
|
}
|