Projet

Général

Profil

Paste
Télécharger (7,75 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / tests / views_exposed_form.test @ 7547bb19

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 the admin interface of exposed filter and sort items.
61
   */
62
  function testExposedAdminUi() {
63
    $admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
64
    $this->drupalLogin($admin_user);
65
    menu_rebuild();
66
    $edit = array();
67

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

    
72
    // The first time the filter UI is displayed, the operator and the
73
    // value forms should be shown.
74
    $this->assertFieldById('edit-options-operator-in', '', 'Operator In exists');
75
    $this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists');
76
    $this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists');
77
    $this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists');
78

    
79
    // Click the Expose filter button.
80
    $this->drupalPost('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type', $edit, t('Expose filter'));
81
    // Check the label of the expose button.
82
    $this->helperButtonHasLabel('edit-options-expose-button-button', t('Hide filter'));
83
    // Check the label of the grouped exposed button
84
    $this->helperButtonHasLabel('edit-options-group-button-button', t('Grouped filters'));
85

    
86
    // After Expose the filter, Operator and Value should be still here
87
    $this->assertFieldById('edit-options-operator-in', '', 'Operator In exists');
88
    $this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists');
89
    $this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists');
90
    $this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists');
91

    
92
    // Check the validations of the filter handler.
93
    $edit = array();
94
    $edit['options[expose][identifier]'] = '';
95
    $this->drupalPost(NULL, $edit, t('Apply'));
96
    $this->assertText(t('The identifier is required if the filter is exposed.'));
97

    
98
    $edit = array();
99
    $edit['options[expose][identifier]'] = 'value';
100
    $this->drupalPost(NULL, $edit, t('Apply'));
101
    $this->assertText(t('This identifier is not allowed.'));
102

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

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

    
112
    // After click on 'Grouped Filters' standard operator and value should not be displayed
113
    $this->assertNoFieldById('edit-options-operator-in', '', 'Operator In not exists');
114
    $this->assertNoFieldById('edit-options-operator-not-in', '', 'Operator Not In not exists');
115
    $this->assertNoFieldById('edit-options-value-page', '', 'Checkbox for Page not exists');
116
    $this->assertNoFieldById('edit-options-value-article', '', 'Checkbox for Article not exists');
117

    
118

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

    
123
    // Create a grouped filter
124
    $this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
125
    $edit = array();
126
    $edit["options[group_info][group_items][1][title]"] = 'Is Article';
127
    $edit["options[group_info][group_items][1][value][article]"] = 'article';
128

    
129
    $edit["options[group_info][group_items][2][title]"] = 'Is Page';
130
    $edit["options[group_info][group_items][2][value][page]"] = TRUE;
131

    
132
    $edit["options[group_info][group_items][3][title]"] = 'Is Page and Article';
133
    $edit["options[group_info][group_items][3][value][article]"] = TRUE;
134
    $edit["options[group_info][group_items][3][value][page]"] = TRUE;
135
    $this->drupalPost(NULL, $edit, t('Apply'));
136

    
137
    // Validate that all the titles are defined for each group
138
    $this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
139
    $edit = array();
140
    $edit["options[group_info][group_items][1][title]"] = 'Is Article';
141
    $edit["options[group_info][group_items][1][value][article]"] = TRUE;
142

    
143
    // This should trigger an error
144
    $edit["options[group_info][group_items][2][title]"] = '';
145
    $edit["options[group_info][group_items][2][value][page]"] = TRUE;
146

    
147
    $edit["options[group_info][group_items][3][title]"] = 'Is Page and Article';
148
    $edit["options[group_info][group_items][3][value][article]"] = TRUE;
149
    $edit["options[group_info][group_items][3][value][page]"] = TRUE;
150
    $this->drupalPost(NULL, $edit, t('Apply'));
151
    $this->assertRaw(t('The title is required if value for this item is defined.'), t('Group items should have a title'));
152

    
153
    // Un-Expose the filter
154
    $this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
155
    $this->drupalPost(NULL, array(), t('Hide filter'));
156

    
157
    // After Un-Expose the filter, Operator and Value should be shown again
158
    $this->assertFieldById('edit-options-operator-in', '', 'Operator In exists after hide filter');
159
    $this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists after hide filter');
160
    $this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists after hide filter');
161
    $this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists after hide filter');
162

    
163
    // Click the Expose sort button.
164
    $edit = array();
165
    $this->drupalPost('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/sort/created', $edit, t('Expose sort'));
166
    // Check the label of the expose button.
167
    $this->helperButtonHasLabel('edit-options-expose-button-button', t('Hide sort'));
168
    $this->assertFieldById('edit-options-expose-label', '', t('Make sure a label field is shown'));
169
  }
170
}