function FilterCombineTest::testNonFieldsRow

Same name and namespace in other branches
  1. 11.x core/modules/views/tests/src/Kernel/Handler/FilterCombineTest.php \Drupal\Tests\views\Kernel\Handler\FilterCombineTest::testNonFieldsRow()
  2. 10 core/modules/views/tests/src/Kernel/Handler/FilterCombineTest.php \Drupal\Tests\views\Kernel\Handler\FilterCombineTest::testNonFieldsRow()
  3. 8.9.x core/modules/views/tests/src/Kernel/Handler/FilterCombineTest.php \Drupal\Tests\views\Kernel\Handler\FilterCombineTest::testNonFieldsRow()
  4. main core/modules/views/tests/src/Kernel/Handler/FilterCombineTest.php \Drupal\Tests\views\Kernel\Handler\FilterCombineTest::testNonFieldsRow()

Tests that the "combine" filter is only valid on displays that use fields.

File

core/modules/views/tests/src/Kernel/Handler/FilterCombineTest.php, line 250

Class

FilterCombineTest
Tests the combine filter handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testNonFieldsRow() {
  $view = Views::getView('entity_test_fields');
  $view->setDisplay();
  // Set the rows to a plugin type that doesn't support fields.
  $view->displayHandlers
    ->get('default')
    ->overrideOption('row', [
    'type' => 'entity:entity_test',
    'options' => [
      'view_mode' => 'teaser',
    ],
  ]);
  // Change the filtering.
  $view->displayHandlers
    ->get('default')
    ->overrideOption('filters', [
    'name' => [
      'id' => 'combine',
      'table' => 'views',
      'field' => 'combine',
      'relationship' => 'none',
      'operator' => 'contains',
      'fields' => [
        'name',
      ],
      'value' => 'ing',
    ],
  ]);
  $this->executeView($view);
  $errors = $view->validate();
  // Check that the right error is shown.
  $this->assertEquals(t('%display: %filter can only be used on displays that use fields. Set the style or row format for that display to one using fields to use the combine field filter.', [
    '%filter' => 'Global: Combine fields filter',
    '%display' => 'Default',
  ]), reset($errors['default']));
  // Confirm that the query with single filter does not use the "CONCAT_WS"
  // operator.
  $this->assertStringNotContainsString('CONCAT_WS(', $view->query
    ->query());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.