Verified Commit cb306571 authored by Jess's avatar Jess
Browse files

Issue #3323353 by Lendude, ameymudras, VitaliyB98, xjm, andypost: View combine...

Issue #3323353 by Lendude, ameymudras, VitaliyB98, xjm, andypost: View combine filter operator "Is not equal to" use the same operator as "Is equal to"

(cherry picked from commit 981d266c)
parent 2760d9ba
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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]);
  }

+58 −0
Original line number Diff line number Diff line
@@ -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.
   */