diff --git a/core/modules/views/src/Plugin/views/filter/Combine.php b/core/modules/views/src/Plugin/views/filter/Combine.php index d1e25f16759026f97f1507a73d0d6fca83f2e146..a39e3b0118698a5af0448169305b6bdaff5da861 100644 --- a/core/modules/views/src/Plugin/views/filter/Combine.php +++ b/core/modules/views/src/Plugin/views/filter/Combine.php @@ -133,7 +133,7 @@ public function validate() { */ public function opEqual($expression) { $placeholder = $this->placeholder(); - $operator = $this->getConditionOperator('LIKE'); + $operator = $this->getConditionOperator($this->operator()); $this->query->addWhereExpression($this->options['group'], "$expression $operator $placeholder", [$placeholder => $this->value]); } diff --git a/core/modules/views/tests/src/Kernel/Handler/FilterCombineTest.php b/core/modules/views/tests/src/Kernel/Handler/FilterCombineTest.php index d1a577fab5e513d094513a3e1716f56deaa34ff3..eb5fc520550ea6c4902d723c9108f2133c983590 100644 --- a/core/modules/views/tests/src/Kernel/Handler/FilterCombineTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/FilterCombineTest.php @@ -9,6 +9,8 @@ * Tests the combine filter handler. * * @group views + * + * @coversDefaultClass \Drupal\views\Plugin\views\filter\Combine */ class FilterCombineTest extends ViewsKernelTestBase { @@ -283,6 +285,8 @@ public function testNonFieldsRow() { /** * Tests the Combine field filter using the 'equal' operator. + * + * @covers::opEqual */ public function testFilterCombineEqual() { $view = Views::getView('test_view'); @@ -327,6 +331,60 @@ public function testFilterCombineEqual() { $this->assertIdenticalResultset($view, $resultset, $this->columnMap); } + /** + * Tests the Combine field filter using the 'not equal' operator. + * + * @covers::opEqual + */ + public function testFilterCombineNotEqual(): void { + $view = Views::getView('test_view'); + $view->setDisplay(); + + $fields = $view->displayHandlers->get('default')->getOption('fields'); + $view->displayHandlers->get('default')->overrideOption('fields', $fields + [ + 'job' => [ + 'id' => 'job', + 'table' => 'views_test_data', + 'field' => 'job', + 'relationship' => 'none', + ], + ]); + + // Change the filtering. + $view->displayHandlers->get('default')->overrideOption('filters', [ + 'age' => [ + 'id' => 'combine', + 'table' => 'views', + 'field' => 'combine', + 'relationship' => 'none', + 'operator' => '!=', + 'fields' => [ + 'job', + ], + // The 'I' in 'sInger' is capitalized deliberately because we are + // testing that search filters are case-insensitive. + 'value' => 'sInger', + ], + ]); + + $this->executeView($view); + $result_set = [ + [ + 'name' => 'Ringo', + 'job' => 'Drummer', + ], + [ + 'name' => 'Paul', + 'job' => 'Songwriter', + ], + [ + 'name' => 'Meredith', + 'job' => 'Speaker', + ], + ]; + $this->assertIdenticalResultset($view, $result_set, $this->columnMap); + } + /** * Tests the Combine field filter using the 'starts' operator. */