1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of ViewsExposedFormTest.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Tests exposed forms.
|
10
|
*/
|
11
|
class ViewsExposedFormTest extends ViewsSqlTest {
|
12
|
|
13
|
/**
|
14
|
*
|
15
|
*/
|
16
|
public static function getInfo() {
|
17
|
return array(
|
18
|
'name' => 'Exposed forms',
|
19
|
'description' => 'Test exposed forms functionality.',
|
20
|
'group' => 'Views Plugins',
|
21
|
);
|
22
|
}
|
23
|
|
24
|
/**
|
25
|
*
|
26
|
*/
|
27
|
public function setUp() {
|
28
|
parent::setUp('views_ui');
|
29
|
module_enable(array('views_ui'));
|
30
|
// @todo Figure out why it's required to clear the cache here.
|
31
|
views_module_include('views_default', TRUE);
|
32
|
views_get_all_views(TRUE);
|
33
|
menu_rebuild();
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* Tests, whether and how the reset button can be renamed.
|
38
|
*/
|
39
|
public function testRenameResetButton() {
|
40
|
$account = $this->drupalCreateUser();
|
41
|
$this->drupalLogin($account);
|
42
|
// Create some random nodes.
|
43
|
for ($i = 0; $i < 5; $i++) {
|
44
|
$this->drupalCreateNode();
|
45
|
}
|
46
|
// Look at the page and check the label "reset".
|
47
|
$this->drupalGet('test_rename_reset_button');
|
48
|
// Rename the label of the reset button.
|
49
|
$view = views_get_view('test_rename_reset_button');
|
50
|
$view->set_display('default');
|
51
|
|
52
|
$exposed_form = $view->display_handler->get_option('exposed_form');
|
53
|
$exposed_form['options']['reset_button_label'] = $expected_label = $this->randomName();
|
54
|
$exposed_form['options']['reset_button'] = TRUE;
|
55
|
$view->display_handler->set_option('exposed_form', $exposed_form);
|
56
|
$view->save();
|
57
|
|
58
|
views_invalidate_cache();
|
59
|
|
60
|
// Look whether ther reset button label changed.
|
61
|
$this->drupalGet('test_rename_reset_button');
|
62
|
|
63
|
$this->helperButtonHasLabel('edit-reset', $expected_label);
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* Tests that exposed values are correctly stored.
|
68
|
*/
|
69
|
public function testRemember() {
|
70
|
$account = $this->drupalCreateUser();
|
71
|
$this->drupalLogin($account);
|
72
|
// Create some random nodes.
|
73
|
for ($i = 0; $i < 5; $i++) {
|
74
|
$this->drupalCreateNode();
|
75
|
}
|
76
|
|
77
|
// Set the exposed filter.
|
78
|
$this->drupalGet('test_exposed_remember', array('query' => array('type' => 'page')));
|
79
|
$this->assertFieldByName('type', 'page');
|
80
|
|
81
|
// Request the page again, should still be set.
|
82
|
$this->drupalGet('test_exposed_remember');
|
83
|
$this->assertFieldByName('type', 'page');
|
84
|
|
85
|
// Request the page with an unrelated GET argument, filter should still be
|
86
|
// set.
|
87
|
$this->drupalGet('test_exposed_remember', array('query' => array('argument' => 'value')));
|
88
|
$this->assertFieldByName('type', 'page');
|
89
|
|
90
|
// Change the remembered exposed value.
|
91
|
$this->drupalGet('test_exposed_remember', array('query' => array('type' => 'article')));
|
92
|
$this->assertFieldByName('type', 'article');
|
93
|
|
94
|
// Request the page again, should have remembered the new value.
|
95
|
$this->drupalGet('test_exposed_remember');
|
96
|
$this->assertFieldByName('type', 'article');
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* Tests the admin interface of exposed filter and sort items.
|
101
|
*/
|
102
|
function testExposedAdminUi() {
|
103
|
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
|
104
|
$this->drupalLogin($admin_user);
|
105
|
menu_rebuild();
|
106
|
$edit = array();
|
107
|
|
108
|
$this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
|
109
|
// Be sure that the button is called exposed.
|
110
|
$this->helperButtonHasLabel('edit-options-expose-button-button', t('Expose filter'));
|
111
|
|
112
|
// The first time the filter UI is displayed, the operator and the value
|
113
|
// forms should be shown.
|
114
|
$this->assertFieldById('edit-options-operator-in', '', 'Operator In exists');
|
115
|
$this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists');
|
116
|
$this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists');
|
117
|
$this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists');
|
118
|
|
119
|
// Click the Expose filter button.
|
120
|
$this->drupalPost('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type', $edit, t('Expose filter'));
|
121
|
// Check the label of the expose button.
|
122
|
$this->helperButtonHasLabel('edit-options-expose-button-button', t('Hide filter'));
|
123
|
// Check the label of the grouped exposed button.
|
124
|
$this->helperButtonHasLabel('edit-options-group-button-button', t('Grouped filters'));
|
125
|
|
126
|
// After Expose the filter, Operator and Value should be still here.
|
127
|
$this->assertFieldById('edit-options-operator-in', '', 'Operator In exists');
|
128
|
$this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists');
|
129
|
$this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists');
|
130
|
$this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists');
|
131
|
|
132
|
// Check the validations of the filter handler.
|
133
|
$edit = array();
|
134
|
$edit['options[expose][identifier]'] = '';
|
135
|
$this->drupalPost(NULL, $edit, t('Apply'));
|
136
|
$this->assertText(t('The identifier is required if the filter is exposed.'));
|
137
|
|
138
|
$edit = array();
|
139
|
$edit['options[expose][identifier]'] = 'value';
|
140
|
$this->drupalPost(NULL, $edit, t('Apply'));
|
141
|
$this->assertText(t('This identifier is not allowed.'));
|
142
|
|
143
|
// Now check the sort criteria.
|
144
|
$this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/sort/created');
|
145
|
$this->helperButtonHasLabel('edit-options-expose-button-button', t('Expose sort'));
|
146
|
$this->assertNoFieldById('edit-options-expose-label', '', t('Make sure no label field is shown'));
|
147
|
|
148
|
// Click the Grouped Filters button.
|
149
|
$this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
|
150
|
$this->drupalPost(NULL, array(), t('Grouped filters'));
|
151
|
|
152
|
// After click on 'Grouped Filters' standard operator and value should not
|
153
|
// be displayed.
|
154
|
$this->assertNoFieldById('edit-options-operator-in', '', 'Operator In not exists');
|
155
|
$this->assertNoFieldById('edit-options-operator-not-in', '', 'Operator Not In not exists');
|
156
|
$this->assertNoFieldById('edit-options-value-page', '', 'Checkbox for Page not exists');
|
157
|
$this->assertNoFieldById('edit-options-value-article', '', 'Checkbox for Article not exists');
|
158
|
|
159
|
// Check that after click on 'Grouped Filters', a new button is shown to
|
160
|
// add more items to the list.
|
161
|
$this->helperButtonHasLabel('edit-options-group-info-add-group', t('Add another item'));
|
162
|
|
163
|
// Create a grouped filter.
|
164
|
$this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
|
165
|
$edit = array();
|
166
|
$edit["options[group_info][group_items][1][title]"] = 'Is Article';
|
167
|
$edit["options[group_info][group_items][1][value][article]"] = 'article';
|
168
|
|
169
|
$edit["options[group_info][group_items][2][title]"] = 'Is Page';
|
170
|
$edit["options[group_info][group_items][2][value][page]"] = TRUE;
|
171
|
|
172
|
$edit["options[group_info][group_items][3][title]"] = 'Is Page and Article';
|
173
|
$edit["options[group_info][group_items][3][value][article]"] = TRUE;
|
174
|
$edit["options[group_info][group_items][3][value][page]"] = TRUE;
|
175
|
$this->drupalPost(NULL, $edit, t('Apply'));
|
176
|
|
177
|
// Validate that all the titles are defined for each group.
|
178
|
$this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
|
179
|
$edit = array();
|
180
|
$edit["options[group_info][group_items][1][title]"] = 'Is Article';
|
181
|
$edit["options[group_info][group_items][1][value][article]"] = TRUE;
|
182
|
|
183
|
// This should trigger an error.
|
184
|
$edit["options[group_info][group_items][2][title]"] = '';
|
185
|
$edit["options[group_info][group_items][2][value][page]"] = TRUE;
|
186
|
|
187
|
$edit["options[group_info][group_items][3][title]"] = 'Is Page and Article';
|
188
|
$edit["options[group_info][group_items][3][value][article]"] = TRUE;
|
189
|
$edit["options[group_info][group_items][3][value][page]"] = TRUE;
|
190
|
$this->drupalPost(NULL, $edit, t('Apply'));
|
191
|
$this->assertRaw(t('The title is required if value for this item is defined.'), t('Group items should have a title'));
|
192
|
|
193
|
// Un-Expose the filter.
|
194
|
$this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
|
195
|
$this->drupalPost(NULL, array(), t('Hide filter'));
|
196
|
|
197
|
// After Un-Expose the filter, Operator and Value should be shown again.
|
198
|
$this->assertFieldById('edit-options-operator-in', '', 'Operator In exists after hide filter');
|
199
|
$this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists after hide filter');
|
200
|
$this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists after hide filter');
|
201
|
$this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists after hide filter');
|
202
|
|
203
|
// Click the Expose sort button.
|
204
|
$edit = array();
|
205
|
$this->drupalPost('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/sort/created', $edit, t('Expose sort'));
|
206
|
// Check the label of the expose button.
|
207
|
$this->helperButtonHasLabel('edit-options-expose-button-button', t('Hide sort'));
|
208
|
$this->assertFieldById('edit-options-expose-label', '', t('Make sure a label field is shown'));
|
209
|
}
|
210
|
|
211
|
}
|