Commit 3da27e53 authored by alexpott's avatar alexpott

Issue #2821112 by vaplas, jibran, esolitos, nicholas.alipaz, gambry, Lendude,...

Issue #2821112 by vaplas, jibran, esolitos, nicholas.alipaz, gambry, Lendude, SylvainM: Views NumericFilter 'regular_expression' operator is broken
parent a6a513df
......@@ -82,7 +82,7 @@ function operators() {
'regular_expression' => array(
'title' => $this->t('Regular expression'),
'short' => $this->t('regex'),
'method' => 'op_regex',
'method' => 'opRegex',
'values' => 1,
),
);
......@@ -274,7 +274,7 @@ protected function opEmpty($field) {
* The expression pointing to the queries field, for example "foo.bar".
*/
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() {
......
......@@ -212,6 +212,66 @@ public function testFilterNumericExposedGroupedNotBetween() {
$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() {
$view = Views::getView('test_view');
$view->setDisplay();
......@@ -407,6 +467,13 @@ protected function getGroupedExposedFilters() {
'title' => 'Age is not empty',
'operator' => 'not empty',
),
6 => array(
'title' => 'Age is regexp 2[7-8]',
'operator' => 'regular_expression',
'value' => array(
'value' => '2[7-8]',
),
),
),
),
),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment