From 3da27e532456dc665d4236caafdeeadb928f646f Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Mon, 13 Feb 2017 20:00:56 +0000 Subject: [PATCH] Issue #2821112 by vaplas, jibran, esolitos, nicholas.alipaz, gambry, Lendude, SylvainM: Views NumericFilter 'regular_expression' operator is broken --- .../src/Plugin/views/filter/NumericFilter.php | 4 +- .../src/Kernel/Handler/FilterNumericTest.php | 67 +++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/core/modules/views/src/Plugin/views/filter/NumericFilter.php b/core/modules/views/src/Plugin/views/filter/NumericFilter.php index e7720dfa04f..d1b5257a644 100644 --- a/core/modules/views/src/Plugin/views/filter/NumericFilter.php +++ b/core/modules/views/src/Plugin/views/filter/NumericFilter.php @@ -82,7 +82,7 @@ class NumericFilter extends FilterPluginBase { 'regular_expression' => array( 'title' => $this->t('Regular expression'), 'short' => $this->t('regex'), - 'method' => 'op_regex', + 'method' => 'opRegex', 'values' => 1, ), ); @@ -274,7 +274,7 @@ class NumericFilter extends FilterPluginBase { * 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() { diff --git a/core/modules/views/tests/src/Kernel/Handler/FilterNumericTest.php b/core/modules/views/tests/src/Kernel/Handler/FilterNumericTest.php index c4c978a115b..ca1587913d0 100644 --- a/core/modules/views/tests/src/Kernel/Handler/FilterNumericTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/FilterNumericTest.php @@ -212,6 +212,66 @@ class FilterNumericTest extends ViewsKernelTestBase { $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 @@ class FilterNumericTest extends ViewsKernelTestBase { '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]', + ), + ), ), ), ),