Project

General

Profile

Paste
Download (4.69 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / views / tests / handlers / views_handler_filter_in_operator.test @ 4003efde

1
<?php
2

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

    
8
/**
9
 * Tests the core views_handler_filter_in_operator handler.
10
 */
11
class ViewsHandlerFilterInOperator extends ViewsSqlTest {
12
  public static function getInfo() {
13
    return array(
14
      'name' => 'Filter: in_operator',
15
      'description' => 'Test the core views_handler_filter_in_operator handler.',
16
      'group' => 'Views Handlers',
17
    );
18
  }
19

    
20
  function viewsData() {
21
    $data = parent::viewsData();
22
    $data['views_test']['age']['filter']['handler'] = 'views_handler_filter_in_operator';
23

    
24
    return $data;
25
  }
26

    
27
  public function testFilterInOperatorSimple() {
28
    $view = $this->getBasicView();
29

    
30
    // Add a in_operator ordering.
31
    $view->display['default']->handler->override_option('filters', array(
32
      'age' => array(
33
        'id' => 'age',
34
        'field' => 'age',
35
        'table' => 'views_test',
36
        'value' => array(26, 30),
37
        'operator' => 'in',
38
      ),
39
    ));
40

    
41
    $this->executeView($view);
42

    
43
    $expected_result = array(
44
      array(
45
        'name' => 'Paul',
46
        'age' => 26,
47
      ),
48
      array(
49
        'name' => 'Meredith',
50
        'age' => 30,
51
      ),
52
    );
53

    
54
    $this->assertEqual(2, count($view->result));
55
    $this->assertIdenticalResultset($view, $expected_result, array(
56
      'views_test_name' => 'name',
57
      'views_test_age' => 'age',
58
    ));
59

    
60
    $view->delete();
61
    $view = $this->getBasicView();
62

    
63
    // Add a in_operator ordering.
64
    $view->display['default']->handler->override_option('filters', array(
65
      'age' => array(
66
        'id' => 'age',
67
        'field' => 'age',
68
        'table' => 'views_test',
69
        'value' => array(26, 30),
70
        'operator' => 'not in',
71
      ),
72
    ));
73

    
74
    $this->executeView($view);
75

    
76
    $expected_result = array(
77
      array(
78
        'name' => 'John',
79
        'age' => 25,
80
      ),
81
      array(
82
        'name' => 'George',
83
        'age' => 27,
84
      ),
85
      array(
86
        'name' => 'Ringo',
87
        'age' => 28,
88
      ),
89
    );
90

    
91
    $this->assertEqual(3, count($view->result));
92
    $this->assertIdenticalResultset($view, $expected_result, array(
93
      'views_test_name' => 'name',
94
      'views_test_age' => 'age',
95
    ));
96
  }
97

    
98
  public function testFilterInOperatorGroupedExposedSimple() {
99
    $filters = $this->getGroupedExposedFilters();
100
    $view = $this->getBasicPageView();
101

    
102
    // Filter: Age, Operator: in, Value: 26, 30
103
    $filters['age']['group_info']['default_group'] = 1;
104
    $view->set_display('page_1');
105
    $view->display['page_1']->handler->override_option('filters', $filters);
106

    
107
    $this->executeView($view);
108

    
109
    $expected_result = array(
110
      array(
111
        'name' => 'Paul',
112
        'age' => 26,
113
      ),
114
      array(
115
        'name' => 'Meredith',
116
        'age' => 30,
117
      ),
118
    );
119

    
120
    $this->assertEqual(2, count($view->result));
121
    $this->assertIdenticalResultset($view, $expected_result, array(
122
      'views_test_name' => 'name',
123
      'views_test_age' => 'age',
124
    ));
125
  }
126

    
127
  public function testFilterNotInOperatorGroupedExposedSimple() {
128
    $filters = $this->getGroupedExposedFilters();
129
    $view = $this->getBasicPageView();
130

    
131
    // Filter: Age, Operator: in, Value: 26, 30
132
    $filters['age']['group_info']['default_group'] = 2;
133
    $view->set_display('page_1');
134
    $view->display['page_1']->handler->override_option('filters', $filters);
135

    
136
    $this->executeView($view);
137

    
138
    $expected_result = array(
139
      array(
140
        'name' => 'John',
141
        'age' => 25,
142
      ),
143
      array(
144
        'name' => 'George',
145
        'age' => 27,
146
      ),
147
      array(
148
        'name' => 'Ringo',
149
        'age' => 28,
150
      ),
151
    );
152

    
153
    $this->assertEqual(3, count($view->result));
154
    $this->assertIdenticalResultset($view, $expected_result, array(
155
      'views_test_name' => 'name',
156
      'views_test_age' => 'age',
157
    ));
158
  }
159

    
160
  protected function getGroupedExposedFilters() {
161
    $filters = array(
162
      'age' => array(
163
        'id' => 'age',
164
        'table' => 'views_test',
165
        'field' => 'age',
166
        'relationship' => 'none',
167
        'exposed' => TRUE,
168
        'expose' => array(
169
          'operator' => 'age_op',
170
          'label' => 'age',
171
          'identifier' => 'age',
172
        ),
173
        'is_grouped' => TRUE,
174
        'group_info' => array(
175
          'label' => 'age',
176
          'identifier' => 'age',
177
          'default_group' => 'All',
178
          'group_items' => array(
179
            1 => array(
180
              'title' => 'Age is one of 26, 30',
181
              'operator' => 'in',
182
              'value' => array(26, 30),
183
            ),
184
            2 => array(
185
              'title' => 'Age is not one of 26, 30',
186
              'operator' => 'not in',
187
              'value' => array(26, 30),
188
            ),
189
          ),
190
        ),
191
      ),
192
    );
193
    return $filters;
194
  }
195

    
196
}