Projet

Général

Profil

Paste
Télécharger (8,9 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / tests / views_exposed_form.test @ 31a5a6d6

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of ViewsExposedFormTest.
6
 */
7

    
8
/**
9
 * Tests exposed forms.
10
 */
11
class ViewsExposedFormTest extends ViewsSqlTest {
12
  public static function getInfo() {
13
    return array(
14
      'name' => 'Exposed forms',
15
      'description' => 'Test exposed forms functionality.',
16
      'group' => 'Views Plugins',
17
    );
18
  }
19

    
20
  public function setUp() {
21
    parent::setUp('views_ui');
22
    module_enable(array('views_ui'));
23
    // @TODO Figure out why it's required to clear the cache here.
24
    views_module_include('views_default', TRUE);
25
    views_get_all_views(TRUE);
26
    menu_rebuild();
27
  }
28

    
29
  /**
30
   * Tests, whether and how the reset button can be renamed.
31
   */
32
  public function testRenameResetButton() {
33
    $account = $this->drupalCreateUser();
34
    $this->drupalLogin($account);
35
    // Create some random nodes.
36
    for ($i = 0; $i < 5; $i++) {
37
      $this->drupalCreateNode();
38
    }
39
    // Look at the page and check the label "reset".
40
    $this->drupalGet('test_rename_reset_button');
41
    // Rename the label of the reset button.
42
    $view = views_get_view('test_rename_reset_button');
43
    $view->set_display('default');
44

    
45
    $exposed_form = $view->display_handler->get_option('exposed_form');
46
    $exposed_form['options']['reset_button_label'] = $expected_label = $this->randomName();
47
    $exposed_form['options']['reset_button'] = TRUE;
48
    $view->display_handler->set_option('exposed_form', $exposed_form);
49
    $view->save();
50

    
51
    views_invalidate_cache();
52

    
53
    // Look whether ther reset button label changed.
54
    $this->drupalGet('test_rename_reset_button');
55

    
56
    $this->helperButtonHasLabel('edit-reset', $expected_label);
57
  }
58

    
59
  /**
60
   * Tests that exposed values are correctly stored.
61
   */
62
  public function testRemember() {
63
    $account = $this->drupalCreateUser();
64
    $this->drupalLogin($account);
65
    // Create some random nodes.
66
    for ($i = 0; $i < 5; $i++) {
67
      $this->drupalCreateNode();
68
    }
69

    
70
    // Set the exposed filter.
71
    $this->drupalGet('test_exposed_remember', array('query' => array('type' => 'page')));
72
    $this->assertFieldByName('type', 'page');
73

    
74
    // Request the page again, should still be set.
75
    $this->drupalGet('test_exposed_remember');
76
    $this->assertFieldByName('type', 'page');
77

    
78
    // Request the page with an unrelated GET argument, filter should still be set.
79
    $this->drupalGet('test_exposed_remember', array('query' => array('argument' => 'value')));
80
    $this->assertFieldByName('type', 'page');
81

    
82
    // Change the remembered exposed value.
83
    $this->drupalGet('test_exposed_remember', array('query' => array('type' => 'article')));
84
    $this->assertFieldByName('type', 'article');
85

    
86
    // Request the page again, should have remembered the new value.
87
    $this->drupalGet('test_exposed_remember');
88
    $this->assertFieldByName('type', 'article');
89
  }
90

    
91
  /**
92
   * Tests the admin interface of exposed filter and sort items.
93
   */
94
  function testExposedAdminUi() {
95
    $admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
96
    $this->drupalLogin($admin_user);
97
    menu_rebuild();
98
    $edit = array();
99

    
100
    $this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
101
    // Be sure that the button is called exposed.
102
    $this->helperButtonHasLabel('edit-options-expose-button-button', t('Expose filter'));
103

    
104
    // The first time the filter UI is displayed, the operator and the
105
    // value forms should be shown.
106
    $this->assertFieldById('edit-options-operator-in', '', 'Operator In exists');
107
    $this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists');
108
    $this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists');
109
    $this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists');
110

    
111
    // Click the Expose filter button.
112
    $this->drupalPost('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type', $edit, t('Expose filter'));
113
    // Check the label of the expose button.
114
    $this->helperButtonHasLabel('edit-options-expose-button-button', t('Hide filter'));
115
    // Check the label of the grouped exposed button
116
    $this->helperButtonHasLabel('edit-options-group-button-button', t('Grouped filters'));
117

    
118
    // After Expose the filter, Operator and Value should be still here
119
    $this->assertFieldById('edit-options-operator-in', '', 'Operator In exists');
120
    $this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists');
121
    $this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists');
122
    $this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists');
123

    
124
    // Check the validations of the filter handler.
125
    $edit = array();
126
    $edit['options[expose][identifier]'] = '';
127
    $this->drupalPost(NULL, $edit, t('Apply'));
128
    $this->assertText(t('The identifier is required if the filter is exposed.'));
129

    
130
    $edit = array();
131
    $edit['options[expose][identifier]'] = 'value';
132
    $this->drupalPost(NULL, $edit, t('Apply'));
133
    $this->assertText(t('This identifier is not allowed.'));
134

    
135
    // Now check the sort criteria.
136
    $this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/sort/created');
137
    $this->helperButtonHasLabel('edit-options-expose-button-button', t('Expose sort'));
138
    $this->assertNoFieldById('edit-options-expose-label', '', t('Make sure no label field is shown'));
139

    
140
    // Click the Grouped Filters button.
141
    $this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
142
    $this->drupalPost(NULL, array(), t('Grouped filters'));
143

    
144
    // After click on 'Grouped Filters' standard operator and value should not be displayed
145
    $this->assertNoFieldById('edit-options-operator-in', '', 'Operator In not exists');
146
    $this->assertNoFieldById('edit-options-operator-not-in', '', 'Operator Not In not exists');
147
    $this->assertNoFieldById('edit-options-value-page', '', 'Checkbox for Page not exists');
148
    $this->assertNoFieldById('edit-options-value-article', '', 'Checkbox for Article not exists');
149

    
150

    
151
    // Check that after click on 'Grouped Filters', a new button is shown to
152
    // add more items to the list.
153
    $this->helperButtonHasLabel('edit-options-group-info-add-group', t('Add another item'));
154

    
155
    // Create a grouped filter
156
    $this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
157
    $edit = array();
158
    $edit["options[group_info][group_items][1][title]"] = 'Is Article';
159
    $edit["options[group_info][group_items][1][value][article]"] = 'article';
160

    
161
    $edit["options[group_info][group_items][2][title]"] = 'Is Page';
162
    $edit["options[group_info][group_items][2][value][page]"] = TRUE;
163

    
164
    $edit["options[group_info][group_items][3][title]"] = 'Is Page and Article';
165
    $edit["options[group_info][group_items][3][value][article]"] = TRUE;
166
    $edit["options[group_info][group_items][3][value][page]"] = TRUE;
167
    $this->drupalPost(NULL, $edit, t('Apply'));
168

    
169
    // Validate that all the titles are defined for each group
170
    $this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
171
    $edit = array();
172
    $edit["options[group_info][group_items][1][title]"] = 'Is Article';
173
    $edit["options[group_info][group_items][1][value][article]"] = TRUE;
174

    
175
    // This should trigger an error
176
    $edit["options[group_info][group_items][2][title]"] = '';
177
    $edit["options[group_info][group_items][2][value][page]"] = TRUE;
178

    
179
    $edit["options[group_info][group_items][3][title]"] = 'Is Page and Article';
180
    $edit["options[group_info][group_items][3][value][article]"] = TRUE;
181
    $edit["options[group_info][group_items][3][value][page]"] = TRUE;
182
    $this->drupalPost(NULL, $edit, t('Apply'));
183
    $this->assertRaw(t('The title is required if value for this item is defined.'), t('Group items should have a title'));
184

    
185
    // Un-Expose the filter
186
    $this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
187
    $this->drupalPost(NULL, array(), t('Hide filter'));
188

    
189
    // After Un-Expose the filter, Operator and Value should be shown again
190
    $this->assertFieldById('edit-options-operator-in', '', 'Operator In exists after hide filter');
191
    $this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists after hide filter');
192
    $this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists after hide filter');
193
    $this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists after hide filter');
194

    
195
    // Click the Expose sort button.
196
    $edit = array();
197
    $this->drupalPost('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/sort/created', $edit, t('Expose sort'));
198
    // Check the label of the expose button.
199
    $this->helperButtonHasLabel('edit-options-expose-button-button', t('Hide sort'));
200
    $this->assertFieldById('edit-options-expose-label', '', t('Make sure a label field is shown'));
201
  }
202
}