From 8c30ce931a50c22831ad0192bc4613bbdf33e351 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 14 Jan 2015 08:18:35 +0000 Subject: [PATCH] Issue #2405907 by MrHaroldA: Views combined filters add redundant separators in CONCAT_WS() --- .../views/src/Plugin/views/filter/Combine.php | 10 +---- .../src/Tests/Handler/FilterCombineTest.php | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/core/modules/views/src/Plugin/views/filter/Combine.php b/core/modules/views/src/Plugin/views/filter/Combine.php index cad7eb9137..31863c358c 100644 --- a/core/modules/views/src/Plugin/views/filter/Combine.php +++ b/core/modules/views/src/Plugin/views/filter/Combine.php @@ -77,15 +77,7 @@ public function query() { } } if ($fields) { - $count = count($fields); - $separated_fields = array(); - foreach ($fields as $key => $field) { - $separated_fields[] = $field; - if ($key < $count-1) { - $separated_fields[] = "' '"; - } - } - $expression = implode(', ', $separated_fields); + $expression = implode(', ', $fields); $expression = "CONCAT_WS(' ', $expression)"; $info = $this->operators(); diff --git a/core/modules/views/src/Tests/Handler/FilterCombineTest.php b/core/modules/views/src/Tests/Handler/FilterCombineTest.php index 516c773a25..4decd83d2e 100644 --- a/core/modules/views/src/Tests/Handler/FilterCombineTest.php +++ b/core/modules/views/src/Tests/Handler/FilterCombineTest.php @@ -81,6 +81,49 @@ public function testFilterCombineContains() { $this->assertIdenticalResultset($view, $resultset, $this->column_map); } + /** + * Tests filtering result using a phrase that matches combined fields. + */ + public function testFilterCombineContainsPhrase() { + $view = Views::getView('test_view'); + $view->setDisplay(); + + $fields = $view->displayHandlers->get('default')->getOption('fields'); + $view->displayHandlers->get('default')->overrideOption('fields', $fields + array( + 'job' => array( + 'id' => 'job', + 'table' => 'views_test_data', + 'field' => 'job', + 'relationship' => 'none', + ), + )); + + // Change the filtering. + $view->displayHandlers->get('default')->overrideOption('filters', array( + 'age' => array( + 'id' => 'combine', + 'table' => 'views', + 'field' => 'combine', + 'relationship' => 'none', + 'operator' => 'contains', + 'fields' => array( + 'name', + 'job', + ), + 'value' => 'ohn Si', + ), + )); + + $this->executeView($view); + $resultset = array( + array( + 'name' => 'John', + 'job' => 'Singer', + ), + ); + $this->assertIdenticalResultset($view, $resultset, $this->column_map); + } + /** * Tests if the filter can handle removed fields. * -- GitLab