1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Definition of ViewsHandlerFilterNumericTest.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Tests the numeric filter handler.
|
10 |
|
|
*/
|
11 |
|
|
class ViewsHandlerFilterNumericTest extends ViewsSqlTest {
|
12 |
|
|
var $column_map = array();
|
13 |
|
|
|
14 |
|
|
public static function getInfo() {
|
15 |
|
|
return array(
|
16 |
|
|
'name' => 'Filter: Numeric',
|
17 |
|
|
'description' => 'Tests the numeric filter handler',
|
18 |
|
|
'group' => 'Views Handlers',
|
19 |
|
|
);
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
function setUp() {
|
23 |
|
|
parent::setUp();
|
24 |
|
|
$this->column_map = array(
|
25 |
|
|
'views_test_name' => 'name',
|
26 |
|
|
'views_test_age' => 'age',
|
27 |
|
|
);
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
function viewsData() {
|
31 |
|
|
$data = parent::viewsData();
|
32 |
|
|
$data['views_test']['age']['filter']['allow empty'] = TRUE;
|
33 |
|
|
$data['views_test']['id']['filter']['allow empty'] = FALSE;
|
34 |
|
|
|
35 |
|
|
return $data;
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
public function testFilterNumericSimple() {
|
39 |
|
|
$view = $this->getBasicView();
|
40 |
|
|
|
41 |
|
|
// Change the filtering
|
42 |
|
|
$view->display['default']->handler->override_option('filters', array(
|
43 |
|
|
'age' => array(
|
44 |
|
|
'id' => 'age',
|
45 |
|
|
'table' => 'views_test',
|
46 |
|
|
'field' => 'age',
|
47 |
|
|
'relationship' => 'none',
|
48 |
|
|
'operator' => '=',
|
49 |
|
|
'value' => array('value' => 28),
|
50 |
|
|
),
|
51 |
|
|
));
|
52 |
|
|
|
53 |
|
|
$this->executeView($view);
|
54 |
|
|
$resultset = array(
|
55 |
|
|
array(
|
56 |
|
|
'name' => 'Ringo',
|
57 |
|
|
'age' => 28,
|
58 |
|
|
),
|
59 |
|
|
);
|
60 |
|
|
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
public function testFilterNumericExposedGroupedSimple() {
|
64 |
|
|
$filters = $this->getGroupedExposedFilters();
|
65 |
|
|
$view = $this->getBasicPageView();
|
66 |
|
|
|
67 |
|
|
// Filter: Age, Operator: =, Value: 28
|
68 |
|
|
$filters['age']['group_info']['default_group'] = 1;
|
69 |
|
|
$view->set_display('page_1');
|
70 |
|
|
$view->display['page_1']->handler->override_option('filters', $filters);
|
71 |
|
|
|
72 |
|
|
$this->executeView($view);
|
73 |
|
|
$resultset = array(
|
74 |
|
|
array(
|
75 |
|
|
'name' => 'Ringo',
|
76 |
|
|
'age' => 28,
|
77 |
|
|
),
|
78 |
|
|
);
|
79 |
|
|
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
public function testFilterNumericBetween() {
|
83 |
|
|
$view = $this->getBasicView();
|
84 |
|
|
|
85 |
|
|
// Change the filtering
|
86 |
|
|
$view->display['default']->handler->override_option('filters', array(
|
87 |
|
|
'age' => array(
|
88 |
|
|
'id' => 'age',
|
89 |
|
|
'table' => 'views_test',
|
90 |
|
|
'field' => 'age',
|
91 |
|
|
'relationship' => 'none',
|
92 |
|
|
'operator' => 'between',
|
93 |
|
|
'value' => array(
|
94 |
|
|
'min' => 26,
|
95 |
|
|
'max' => 29,
|
96 |
|
|
),
|
97 |
|
|
),
|
98 |
|
|
));
|
99 |
|
|
|
100 |
|
|
$this->executeView($view);
|
101 |
|
|
$resultset = array(
|
102 |
|
|
array(
|
103 |
|
|
'name' => 'George',
|
104 |
|
|
'age' => 27,
|
105 |
|
|
),
|
106 |
|
|
array(
|
107 |
|
|
'name' => 'Ringo',
|
108 |
|
|
'age' => 28,
|
109 |
|
|
),
|
110 |
|
|
array(
|
111 |
|
|
'name' => 'Paul',
|
112 |
|
|
'age' => 26,
|
113 |
|
|
),
|
114 |
|
|
);
|
115 |
|
|
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
116 |
|
|
|
117 |
|
|
// test not between
|
118 |
|
|
$view->delete();
|
119 |
|
|
$view = $this->getBasicView();
|
120 |
|
|
|
121 |
|
|
// Change the filtering
|
122 |
|
|
$view->display['default']->handler->override_option('filters', array(
|
123 |
|
|
'age' => array(
|
124 |
|
|
'id' => 'age',
|
125 |
|
|
'table' => 'views_test',
|
126 |
|
|
'field' => 'age',
|
127 |
|
|
'relationship' => 'none',
|
128 |
|
|
'operator' => 'not between',
|
129 |
|
|
'value' => array(
|
130 |
|
|
'min' => 26,
|
131 |
|
|
'max' => 29,
|
132 |
|
|
),
|
133 |
|
|
),
|
134 |
|
|
));
|
135 |
|
|
|
136 |
|
|
$this->executeView($view);
|
137 |
|
|
$resultset = array(
|
138 |
|
|
array(
|
139 |
|
|
'name' => 'John',
|
140 |
|
|
'age' => 25,
|
141 |
|
|
),
|
142 |
|
|
array(
|
143 |
|
|
'name' => 'Paul',
|
144 |
|
|
'age' => 26,
|
145 |
|
|
),
|
146 |
|
|
array(
|
147 |
|
|
'name' => 'Meredith',
|
148 |
|
|
'age' => 30,
|
149 |
|
|
),
|
150 |
|
|
);
|
151 |
|
|
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
public function testFilterNumericExposedGroupedBetween() {
|
155 |
|
|
$filters = $this->getGroupedExposedFilters();
|
156 |
|
|
$view = $this->getBasicPageView();
|
157 |
|
|
|
158 |
|
|
// Filter: Age, Operator: between, Value: 26 and 29
|
159 |
|
|
$filters['age']['group_info']['default_group'] = 2;
|
160 |
|
|
$view->set_display('page_1');
|
161 |
|
|
$view->display['page_1']->handler->override_option('filters', $filters);
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
$this->executeView($view);
|
165 |
|
|
$resultset = array(
|
166 |
|
|
array(
|
167 |
|
|
'name' => 'George',
|
168 |
|
|
'age' => 27,
|
169 |
|
|
),
|
170 |
|
|
array(
|
171 |
|
|
'name' => 'Ringo',
|
172 |
|
|
'age' => 28,
|
173 |
|
|
),
|
174 |
|
|
array(
|
175 |
|
|
'name' => 'Paul',
|
176 |
|
|
'age' => 26,
|
177 |
|
|
),
|
178 |
|
|
);
|
179 |
|
|
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
public function testFilterNumericExposedGroupedNotBetween() {
|
183 |
|
|
$filters = $this->getGroupedExposedFilters();
|
184 |
|
|
$view = $this->getBasicPageView();
|
185 |
|
|
|
186 |
|
|
// Filter: Age, Operator: between, Value: 26 and 29
|
187 |
|
|
$filters['age']['group_info']['default_group'] = 3;
|
188 |
|
|
$view->set_display('page_1');
|
189 |
|
|
$view->display['page_1']->handler->override_option('filters', $filters);
|
190 |
|
|
|
191 |
|
|
|
192 |
|
|
$this->executeView($view);
|
193 |
|
|
$resultset = array(
|
194 |
|
|
array(
|
195 |
|
|
'name' => 'John',
|
196 |
|
|
'age' => 25,
|
197 |
|
|
),
|
198 |
|
|
array(
|
199 |
|
|
'name' => 'Paul',
|
200 |
|
|
'age' => 26,
|
201 |
|
|
),
|
202 |
|
|
array(
|
203 |
|
|
'name' => 'Meredith',
|
204 |
|
|
'age' => 30,
|
205 |
|
|
),
|
206 |
|
|
);
|
207 |
|
|
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
public function testFilterNumericEmpty() {
|
212 |
|
|
$view = $this->getBasicView();
|
213 |
|
|
|
214 |
|
|
// Change the filtering
|
215 |
|
|
$view->display['default']->handler->override_option('filters', array(
|
216 |
|
|
'age' => array(
|
217 |
|
|
'id' => 'age',
|
218 |
|
|
'table' => 'views_test',
|
219 |
|
|
'field' => 'age',
|
220 |
|
|
'relationship' => 'none',
|
221 |
|
|
'operator' => 'empty',
|
222 |
|
|
),
|
223 |
|
|
));
|
224 |
|
|
|
225 |
|
|
$this->executeView($view);
|
226 |
|
|
$resultset = array(
|
227 |
|
|
);
|
228 |
|
|
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
229 |
|
|
|
230 |
|
|
$view->delete();
|
231 |
|
|
$view = $this->getBasicView();
|
232 |
|
|
|
233 |
|
|
// Change the filtering
|
234 |
|
|
$view->display['default']->handler->override_option('filters', array(
|
235 |
|
|
'age' => array(
|
236 |
|
|
'id' => 'age',
|
237 |
|
|
'table' => 'views_test',
|
238 |
|
|
'field' => 'age',
|
239 |
|
|
'relationship' => 'none',
|
240 |
|
|
'operator' => 'not empty',
|
241 |
|
|
),
|
242 |
|
|
));
|
243 |
|
|
|
244 |
|
|
$this->executeView($view);
|
245 |
|
|
$resultset = array(
|
246 |
|
|
array(
|
247 |
|
|
'name' => 'John',
|
248 |
|
|
'age' => 25,
|
249 |
|
|
),
|
250 |
|
|
array(
|
251 |
|
|
'name' => 'George',
|
252 |
|
|
'age' => 27,
|
253 |
|
|
),
|
254 |
|
|
array(
|
255 |
|
|
'name' => 'Ringo',
|
256 |
|
|
'age' => 28,
|
257 |
|
|
),
|
258 |
|
|
array(
|
259 |
|
|
'name' => 'Paul',
|
260 |
|
|
'age' => 26,
|
261 |
|
|
),
|
262 |
|
|
array(
|
263 |
|
|
'name' => 'Meredith',
|
264 |
|
|
'age' => 30,
|
265 |
|
|
),
|
266 |
|
|
);
|
267 |
|
|
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
268 |
|
|
}
|
269 |
|
|
|
270 |
|
|
|
271 |
|
|
public function testFilterNumericExposedGroupedEmpty() {
|
272 |
|
|
$filters = $this->getGroupedExposedFilters();
|
273 |
|
|
$view = $this->getBasicPageView();
|
274 |
|
|
|
275 |
|
|
// Filter: Age, Operator: empty, Value:
|
276 |
|
|
$filters['age']['group_info']['default_group'] = 4;
|
277 |
|
|
$view->set_display('page_1');
|
278 |
|
|
$view->display['page_1']->handler->override_option('filters', $filters);
|
279 |
|
|
|
280 |
|
|
|
281 |
|
|
$this->executeView($view);
|
282 |
|
|
$resultset = array(
|
283 |
|
|
);
|
284 |
|
|
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
285 |
|
|
}
|
286 |
|
|
|
287 |
|
|
public function testFilterNumericExposedGroupedNotEmpty() {
|
288 |
|
|
$filters = $this->getGroupedExposedFilters();
|
289 |
|
|
$view = $this->getBasicPageView();
|
290 |
|
|
|
291 |
|
|
// Filter: Age, Operator: empty, Value:
|
292 |
|
|
$filters['age']['group_info']['default_group'] = 5;
|
293 |
|
|
$view->set_display('page_1');
|
294 |
|
|
$view->display['page_1']->handler->override_option('filters', $filters);
|
295 |
|
|
|
296 |
|
|
|
297 |
|
|
$this->executeView($view);
|
298 |
|
|
$resultset = array(
|
299 |
|
|
array(
|
300 |
|
|
'name' => 'John',
|
301 |
|
|
'age' => 25,
|
302 |
|
|
),
|
303 |
|
|
array(
|
304 |
|
|
'name' => 'George',
|
305 |
|
|
'age' => 27,
|
306 |
|
|
),
|
307 |
|
|
array(
|
308 |
|
|
'name' => 'Ringo',
|
309 |
|
|
'age' => 28,
|
310 |
|
|
),
|
311 |
|
|
array(
|
312 |
|
|
'name' => 'Paul',
|
313 |
|
|
'age' => 26,
|
314 |
|
|
),
|
315 |
|
|
array(
|
316 |
|
|
'name' => 'Meredith',
|
317 |
|
|
'age' => 30,
|
318 |
|
|
),
|
319 |
|
|
);
|
320 |
|
|
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
321 |
|
|
}
|
322 |
|
|
|
323 |
|
|
|
324 |
|
|
public function testAllowEmpty() {
|
325 |
|
|
$view = $this->getBasicView();
|
326 |
|
|
|
327 |
|
|
$view->display['default']->handler->override_option('filters', array(
|
328 |
|
|
'id' => array(
|
329 |
|
|
'id' => 'id',
|
330 |
|
|
'table' => 'views_test',
|
331 |
|
|
'field' => 'id',
|
332 |
|
|
'relationship' => 'none',
|
333 |
|
|
),
|
334 |
|
|
'age' => array(
|
335 |
|
|
'id' => 'age',
|
336 |
|
|
'table' => 'views_test',
|
337 |
|
|
'field' => 'age',
|
338 |
|
|
'relationship' => 'none',
|
339 |
|
|
),
|
340 |
|
|
));
|
341 |
|
|
|
342 |
|
|
$view->set_display('default');
|
343 |
|
|
$view->init_handlers();
|
344 |
|
|
|
345 |
|
|
$id_operators = $view->filter['id']->operators();
|
346 |
|
|
$age_operators = $view->filter['age']->operators();
|
347 |
|
|
|
348 |
|
|
$this->assertFalse(isset($id_operators['empty']));
|
349 |
|
|
$this->assertFalse(isset($id_operators['not empty']));
|
350 |
|
|
$this->assertTrue(isset($age_operators['empty']));
|
351 |
|
|
$this->assertTrue(isset($age_operators['not empty']));
|
352 |
|
|
}
|
353 |
|
|
|
354 |
|
|
protected function getGroupedExposedFilters() {
|
355 |
|
|
$filters = array(
|
356 |
|
|
'age' => array(
|
357 |
|
|
'id' => 'age',
|
358 |
|
|
'table' => 'views_test',
|
359 |
|
|
'field' => 'age',
|
360 |
|
|
'relationship' => 'none',
|
361 |
|
|
'exposed' => TRUE,
|
362 |
|
|
'expose' => array(
|
363 |
|
|
'operator' => 'age_op',
|
364 |
|
|
'label' => 'age',
|
365 |
|
|
'identifier' => 'age',
|
366 |
|
|
),
|
367 |
|
|
'is_grouped' => TRUE,
|
368 |
|
|
'group_info' => array(
|
369 |
|
|
'label' => 'age',
|
370 |
|
|
'identifier' => 'age',
|
371 |
|
|
'default_group' => 'All',
|
372 |
|
|
'group_items' => array(
|
373 |
|
|
1 => array(
|
374 |
|
|
'title' => 'Age is 28',
|
375 |
|
|
'operator' => '=',
|
376 |
|
|
'value' => array('value' => 28),
|
377 |
|
|
),
|
378 |
|
|
2 => array(
|
379 |
|
|
'title' => 'Age is between 26 and 29',
|
380 |
|
|
'operator' => 'between',
|
381 |
|
|
'value' => array(
|
382 |
|
|
'min' => 26,
|
383 |
|
|
'max' => 29,
|
384 |
|
|
),
|
385 |
|
|
),
|
386 |
|
|
3 => array(
|
387 |
|
|
'title' => 'Age is not between 26 and 29',
|
388 |
|
|
'operator' => 'not between',
|
389 |
|
|
'value' => array(
|
390 |
|
|
'min' => 26,
|
391 |
|
|
'max' => 29,
|
392 |
|
|
),
|
393 |
|
|
),
|
394 |
|
|
4 => array(
|
395 |
|
|
'title' => 'Age is empty',
|
396 |
|
|
'operator' => 'empty',
|
397 |
|
|
),
|
398 |
|
|
5 => array(
|
399 |
|
|
'title' => 'Age is not empty',
|
400 |
|
|
'operator' => 'not empty',
|
401 |
|
|
),
|
402 |
|
|
),
|
403 |
|
|
),
|
404 |
|
|
),
|
405 |
|
|
);
|
406 |
|
|
return $filters;
|
407 |
|
|
}
|
408 |
|
|
|
409 |
|
|
} |