Newer
Older
/**
* @file
* Definition of ViewsHandlerFilterNumericTest.
*/
/**
* Tests the numeric filter handler.
class ViewsHandlerFilterNumericTest extends ViewsSqlTest {
var $column_map = array();
public static function getInfo() {
return array(
Mariano D'Agostino
committed
'name' => 'Filter: Numeric',
'description' => 'Tests the numeric filter handler',
'group' => 'Views Handlers',
);
}
function setUp() {
parent::setUp();
$this->column_map = array(
'views_test_name' => 'name',
'views_test_age' => 'age',
);
}
function viewsData() {
$data = parent::viewsData();
$data['views_test']['age']['filter']['allow empty'] = TRUE;
$data['views_test']['id']['filter']['allow empty'] = FALSE;
return $data;
}
public function testFilterNumericSimple() {
$view = $this->getBasicView();
Damien McKenna
committed
// Change the filtering.
$view->display['default']->handler->override_option('filters', array(
'age' => array(
'id' => 'age',
'table' => 'views_test',
'field' => 'age',
'relationship' => 'none',
'operator' => '=',
'value' => array('value' => 28),
),
));
$this->executeView($view);
$resultset = array(
array(
'name' => 'Ringo',
'age' => 28,
),
);
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
}
Mariano D'Agostino
committed
public function testFilterNumericExposedGroupedSimple() {
$filters = $this->getGroupedExposedFilters();
$view = $this->getBasicPageView();
// Filter: Age, Operator: =, Value: 28
$filters['age']['group_info']['default_group'] = 1;
$view->set_display('page_1');
$view->display['page_1']->handler->override_option('filters', $filters);
$this->executeView($view);
$resultset = array(
array(
'name' => 'Ringo',
'age' => 28,
),
);
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
}
public function testFilterNumericBetween() {
$view = $this->getBasicView();
Damien McKenna
committed
// Change the filtering.
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
$view->display['default']->handler->override_option('filters', array(
'age' => array(
'id' => 'age',
'table' => 'views_test',
'field' => 'age',
'relationship' => 'none',
'operator' => 'between',
'value' => array(
'min' => 26,
'max' => 29,
),
),
));
$this->executeView($view);
$resultset = array(
array(
'name' => 'George',
'age' => 27,
),
array(
'name' => 'Ringo',
'age' => 28,
),
array(
'name' => 'Paul',
'age' => 26,
),
);
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
Damien McKenna
committed
// test not between.
$view->delete();
$view = $this->getBasicView();
Damien McKenna
committed
// Change the filtering.
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
$view->display['default']->handler->override_option('filters', array(
'age' => array(
'id' => 'age',
'table' => 'views_test',
'field' => 'age',
'relationship' => 'none',
'operator' => 'not between',
'value' => array(
'min' => 26,
'max' => 29,
),
),
));
$this->executeView($view);
$resultset = array(
array(
'name' => 'John',
'age' => 25,
),
array(
'name' => 'Paul',
'age' => 26,
),
array(
'name' => 'Meredith',
'age' => 30,
),
);
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
}
Mariano D'Agostino
committed
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
public function testFilterNumericExposedGroupedBetween() {
$filters = $this->getGroupedExposedFilters();
$view = $this->getBasicPageView();
// Filter: Age, Operator: between, Value: 26 and 29
$filters['age']['group_info']['default_group'] = 2;
$view->set_display('page_1');
$view->display['page_1']->handler->override_option('filters', $filters);
$this->executeView($view);
$resultset = array(
array(
'name' => 'George',
'age' => 27,
),
array(
'name' => 'Ringo',
'age' => 28,
),
array(
'name' => 'Paul',
'age' => 26,
),
);
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
}
public function testFilterNumericExposedGroupedNotBetween() {
$filters = $this->getGroupedExposedFilters();
$view = $this->getBasicPageView();
// Filter: Age, Operator: between, Value: 26 and 29
$filters['age']['group_info']['default_group'] = 3;
$view->set_display('page_1');
$view->display['page_1']->handler->override_option('filters', $filters);
$this->executeView($view);
$resultset = array(
array(
'name' => 'John',
'age' => 25,
),
array(
'name' => 'Paul',
'age' => 26,
),
array(
'name' => 'Meredith',
'age' => 30,
),
);
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
}
public function testFilterNumericEmpty() {
$view = $this->getBasicView();
Damien McKenna
committed
// Change the filtering.
$view->display['default']->handler->override_option('filters', array(
'age' => array(
'id' => 'age',
'table' => 'views_test',
'field' => 'age',
'relationship' => 'none',
'operator' => 'empty',
),
));
$this->executeView($view);
Damien McKenna
committed
$resultset = array();
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
$view->delete();
$view = $this->getBasicView();
Damien McKenna
committed
// Change the filtering.
$view->display['default']->handler->override_option('filters', array(
'age' => array(
'id' => 'age',
'table' => 'views_test',
'field' => 'age',
'relationship' => 'none',
'operator' => 'not empty',
),
));
$this->executeView($view);
$resultset = array(
Damien McKenna
committed
array(
'name' => 'John',
'age' => 25,
),
array(
'name' => 'George',
'age' => 27,
),
array(
'name' => 'Ringo',
'age' => 28,
),
array(
'name' => 'Paul',
'age' => 26,
),
array(
'name' => 'Meredith',
'age' => 30,
),
);
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
}
Mariano D'Agostino
committed
public function testFilterNumericExposedGroupedEmpty() {
$filters = $this->getGroupedExposedFilters();
$view = $this->getBasicPageView();
Damien McKenna
committed
// Filter: Age, Operator: empty, Value.
Mariano D'Agostino
committed
$filters['age']['group_info']['default_group'] = 4;
$view->set_display('page_1');
$view->display['page_1']->handler->override_option('filters', $filters);
$this->executeView($view);
Damien McKenna
committed
$resultset = array();
Mariano D'Agostino
committed
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
}
public function testFilterNumericExposedGroupedNotEmpty() {
$filters = $this->getGroupedExposedFilters();
$view = $this->getBasicPageView();
Damien McKenna
committed
// Filter: Age, Operator: empty, Value.
Mariano D'Agostino
committed
$filters['age']['group_info']['default_group'] = 5;
$view->set_display('page_1');
$view->display['page_1']->handler->override_option('filters', $filters);
$this->executeView($view);
$resultset = array(
Damien McKenna
committed
array(
Mariano D'Agostino
committed
'name' => 'John',
'age' => 25,
),
array(
'name' => 'George',
'age' => 27,
),
array(
'name' => 'Ringo',
'age' => 28,
),
array(
'name' => 'Paul',
'age' => 26,
),
array(
'name' => 'Meredith',
'age' => 30,
),
);
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
}
Mariano D'Agostino
committed
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/**
* Tests the limit operators functionality.
*/
public function testFilterNumericExposedLimitOperators() {
$filters = $this->getGroupedExposedFilters();
$view = $this->getBasicView();
$available_operators = array('<', '>', 'between');
$filters['age']['expose'] += array(
'limit_operators' => TRUE,
'available_operators' => drupal_map_assoc($available_operators),
);
$view->display['default']->handler->override_option('filters', $filters);
$this->executeView($view);
$form = array();
$form_state = array();
$view->filter['age']->operator_form($form, $form_state);
$operator = $form['operator'];
$this->assertTrue(in_array($operator['#default_value'], $available_operators), 'Default value operator found in list of available operators.');
foreach ($available_operators as $available_operator) {
$this->assertTrue($operator['#options'][$available_operator], format_string('@operator found in options', array('@operator' => $available_operator)));
}
}
Mariano D'Agostino
committed
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
public function testAllowEmpty() {
$view = $this->getBasicView();
$view->display['default']->handler->override_option('filters', array(
'id' => array(
'id' => 'id',
'table' => 'views_test',
'field' => 'id',
'relationship' => 'none',
),
'age' => array(
'id' => 'age',
'table' => 'views_test',
'field' => 'age',
'relationship' => 'none',
),
));
$view->set_display('default');
$view->init_handlers();
$id_operators = $view->filter['id']->operators();
$age_operators = $view->filter['age']->operators();
$this->assertFalse(isset($id_operators['empty']));
$this->assertFalse(isset($id_operators['not empty']));
$this->assertTrue(isset($age_operators['empty']));
$this->assertTrue(isset($age_operators['not empty']));
}
Mariano D'Agostino
committed
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
protected function getGroupedExposedFilters() {
$filters = array(
'age' => array(
'id' => 'age',
'table' => 'views_test',
'field' => 'age',
'relationship' => 'none',
'exposed' => TRUE,
'expose' => array(
'operator' => 'age_op',
'label' => 'age',
'identifier' => 'age',
),
'is_grouped' => TRUE,
'group_info' => array(
'label' => 'age',
'identifier' => 'age',
'default_group' => 'All',
'group_items' => array(
1 => array(
'title' => 'Age is 28',
'operator' => '=',
'value' => array('value' => 28),
),
2 => array(
'title' => 'Age is between 26 and 29',
'operator' => 'between',
'value' => array(
'min' => 26,
'max' => 29,
),
),
3 => array(
'title' => 'Age is not between 26 and 29',
'operator' => 'not between',
'value' => array(
'min' => 26,
'max' => 29,
),
),
4 => array(
'title' => 'Age is empty',
'operator' => 'empty',
),
5 => array(
'title' => 'Age is not empty',
'operator' => 'not empty',
),
),
),
),
);
return $filters;
}