1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Test file for fieldgroup UI.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Group UI tests.
|
10
|
*/
|
11
|
class GroupUITestCase extends DrupalWebTestCase {
|
12
|
|
13
|
public static function getInfo() {
|
14
|
return array(
|
15
|
'name' => 'UI tests',
|
16
|
'description' => 'Test the field group UI.',
|
17
|
'group' => 'Field group',
|
18
|
);
|
19
|
}
|
20
|
|
21
|
function setUp() {
|
22
|
parent::setUp('field_test', 'field_group', 'field_group_test');
|
23
|
|
24
|
// Create test user.
|
25
|
$admin_user = $this->drupalCreateUser(array('administer content types', 'administer nodes', 'access administration pages', 'bypass node access'));
|
26
|
$this->drupalLogin($admin_user);
|
27
|
}
|
28
|
|
29
|
/**
|
30
|
* Test the creation a group on the article content type.
|
31
|
*/
|
32
|
function createGroup() {
|
33
|
|
34
|
// Create random group name.
|
35
|
$this->group_label = $this->randomName(8);
|
36
|
$this->group_name_input = drupal_strtolower($this->randomName(8));
|
37
|
$this->group_name = 'group_' . $this->group_name_input;
|
38
|
|
39
|
// Setup new group.
|
40
|
$group = array(
|
41
|
'fields[_add_new_group][label]' => $this->group_label,
|
42
|
'fields[_add_new_group][group_name]' => $this->group_name_input,
|
43
|
);
|
44
|
|
45
|
// Add new group on the 'Manage fields' page.
|
46
|
$this->drupalPost('admin/structure/types/manage/article/fields', $group, t('Save'));
|
47
|
|
48
|
$this->assertRaw(t('New group %label successfully created.', array('%label' => $this->group_label)), t('Group message displayed on screen.'));
|
49
|
|
50
|
// Test if group is in the $groups array.
|
51
|
$groups = field_group_info_groups('node', 'article', 'form', TRUE);
|
52
|
$this->assertTrue(array_key_exists($this->group_name, $groups), t('Group found in groups array'));
|
53
|
|
54
|
// Add new group on the 'Manage display' page.
|
55
|
$this->drupalPost('admin/structure/types/manage/article/display', $group, t('Save'));
|
56
|
$this->assertRaw(t('New group %label successfully created.', array('%label' => $this->group_label)), t('Group message displayed on screen.'));
|
57
|
|
58
|
// Test if group is in the $groups array.
|
59
|
$groups = field_group_info_groups('node', 'article', 'default', TRUE);
|
60
|
$this->assertTrue(array_key_exists($this->group_name, $groups), t('Group found in groups array'));
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* Delete a group.
|
65
|
*/
|
66
|
function deleteGroup() {
|
67
|
|
68
|
$this->drupalPost('admin/structure/types/manage/article/groups/' . $this->group_name . '/delete/form', array(), t('Delete'));
|
69
|
$this->assertRaw(t('The group %label has been deleted from the %article content type.', array('%label' => $this->group_label, '%article' => 'Article')), t('Group removal message displayed on screen.'));
|
70
|
|
71
|
// Test that group is not in the $groups array.
|
72
|
$groups = field_group_info_groups('node', 'article', 'form', TRUE);
|
73
|
$this->assertFalse(array_key_exists($this->group_name, $groups), t('Group not found in groups array while deleting'));
|
74
|
|
75
|
$this->drupalPost('admin/structure/types/manage/article/groups/' . $this->group_name . '/delete/default', array(), t('Delete'));
|
76
|
$this->assertRaw(t('The group %label has been deleted from the %article content type.', array('%label' => $this->group_label, '%article' => 'Article')), t('Group removal message displayed on screen.'));
|
77
|
|
78
|
// Test that group is not in the $groups array.
|
79
|
$groups = field_group_info_groups('node', 'article', 'default', TRUE);
|
80
|
$this->assertFalse(array_key_exists($this->group_name, $groups), t('Group not found in groups array while deleting'));
|
81
|
}
|
82
|
|
83
|
/**
|
84
|
* General CRUD.
|
85
|
*/
|
86
|
function testCRUDGroup() {
|
87
|
$this->createGroup();
|
88
|
$this->deleteGroup();
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* Nest a field underneath a group.
|
93
|
*/
|
94
|
function testNestField() {
|
95
|
|
96
|
$this->createGroup();
|
97
|
|
98
|
$edit = array(
|
99
|
'fields[field_image][parent]' => $this->group_name,
|
100
|
);
|
101
|
$this->drupalPost('admin/structure/types/manage/article/fields', $edit, t('Save'));
|
102
|
$this->assertRaw(t('Your settings have been saved.'), t('Settings saved'));
|
103
|
|
104
|
$groups = field_group_info_groups('node', 'article', 'form', TRUE);
|
105
|
$this->assertTrue(in_array('field_image', $groups[$this->group_name]->children), t('Image is a child of %group', array('%group' => $this->group_name)));
|
106
|
}
|
107
|
|
108
|
}
|
109
|
|