Issue #2821112 by vaplas, jibran, esolitos, nicholas.alipaz, gambry, Lendude, SylvainM: Views NumericFilter 'regular_expression' operator is broken
parent
a6a513dff9
commit
3da27e5324
|
@ -82,7 +82,7 @@ class NumericFilter extends FilterPluginBase {
|
||||||
'regular_expression' => array(
|
'regular_expression' => array(
|
||||||
'title' => $this->t('Regular expression'),
|
'title' => $this->t('Regular expression'),
|
||||||
'short' => $this->t('regex'),
|
'short' => $this->t('regex'),
|
||||||
'method' => 'op_regex',
|
'method' => 'opRegex',
|
||||||
'values' => 1,
|
'values' => 1,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -274,7 +274,7 @@ class NumericFilter extends FilterPluginBase {
|
||||||
* The expression pointing to the queries field, for example "foo.bar".
|
* The expression pointing to the queries field, for example "foo.bar".
|
||||||
*/
|
*/
|
||||||
protected function opRegex($field) {
|
protected function opRegex($field) {
|
||||||
$this->query->addWhere($this->options['group'], $field, $this->value, 'REGEXP');
|
$this->query->addWhere($this->options['group'], $field, $this->value['value'], 'REGEXP');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function adminSummary() {
|
public function adminSummary() {
|
||||||
|
|
|
@ -212,6 +212,66 @@ class FilterNumericTest extends ViewsKernelTestBase {
|
||||||
$this->assertIdenticalResultset($view, $resultset, $this->columnMap);
|
$this->assertIdenticalResultset($view, $resultset, $this->columnMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the numeric filter handler with the 'regular_expression' operator.
|
||||||
|
*/
|
||||||
|
public function testFilterNumericRegularExpression() {
|
||||||
|
$view = Views::getView('test_view');
|
||||||
|
$view->setDisplay();
|
||||||
|
|
||||||
|
// Filtering by regular expression pattern.
|
||||||
|
$view->displayHandlers->get('default')->overrideOption('filters', array(
|
||||||
|
'age' => array(
|
||||||
|
'id' => 'age',
|
||||||
|
'table' => 'views_test_data',
|
||||||
|
'field' => 'age',
|
||||||
|
'relationship' => 'none',
|
||||||
|
'operator' => 'regular_expression',
|
||||||
|
'value' => array(
|
||||||
|
'value' => '2[8]',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->executeView($view);
|
||||||
|
$resultset = array(
|
||||||
|
array(
|
||||||
|
'name' => 'Ringo',
|
||||||
|
'age' => 28,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$this->assertIdenticalResultset($view, $resultset, $this->columnMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the numeric filter handler with the 'regular_expression' operator
|
||||||
|
* to grouped exposed filters.
|
||||||
|
*/
|
||||||
|
public function testFilterNumericExposedGroupedRegularExpression() {
|
||||||
|
$filters = $this->getGroupedExposedFilters();
|
||||||
|
$view = Views::getView('test_view');
|
||||||
|
$view->newDisplay('page', 'Page', 'page_1');
|
||||||
|
|
||||||
|
// Filter: Age, Operator: regular_expression, Value: 2[7-8]
|
||||||
|
$filters['age']['group_info']['default_group'] = 6;
|
||||||
|
$view->setDisplay('page_1');
|
||||||
|
$view->displayHandlers->get('page_1')->overrideOption('filters', $filters);
|
||||||
|
$view->save();
|
||||||
|
|
||||||
|
$this->executeView($view);
|
||||||
|
$resultset = array(
|
||||||
|
array(
|
||||||
|
'name' => 'George',
|
||||||
|
'age' => 27,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'Ringo',
|
||||||
|
'age' => 28,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$this->assertIdenticalResultset($view, $resultset, $this->columnMap);
|
||||||
|
}
|
||||||
|
|
||||||
public function testFilterNumericEmpty() {
|
public function testFilterNumericEmpty() {
|
||||||
$view = Views::getView('test_view');
|
$view = Views::getView('test_view');
|
||||||
$view->setDisplay();
|
$view->setDisplay();
|
||||||
|
@ -407,6 +467,13 @@ class FilterNumericTest extends ViewsKernelTestBase {
|
||||||
'title' => 'Age is not empty',
|
'title' => 'Age is not empty',
|
||||||
'operator' => 'not empty',
|
'operator' => 'not empty',
|
||||||
),
|
),
|
||||||
|
6 => array(
|
||||||
|
'title' => 'Age is regexp 2[7-8]',
|
||||||
|
'operator' => 'regular_expression',
|
||||||
|
'value' => array(
|
||||||
|
'value' => '2[7-8]',
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue