You are here

public function FilterStringTest::testFilterStringWord in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Handler/FilterStringTest.php \Drupal\Tests\views\Kernel\Handler\FilterStringTest::testFilterStringWord()
  2. 10 core/modules/views/tests/src/Kernel/Handler/FilterStringTest.php \Drupal\Tests\views\Kernel\Handler\FilterStringTest::testFilterStringWord()

File

core/modules/views/tests/src/Kernel/Handler/FilterStringTest.php, line 244

Class

FilterStringTest
Tests the core Drupal\views\Plugin\views\filter\StringFilter handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testFilterStringWord() {
  $view = Views::getView('test_view');
  $view
    ->setDisplay();

  // Change the filtering
  $view->displayHandlers
    ->get('default')
    ->overrideOption('filters', [
    'description' => [
      'id' => 'description',
      'table' => 'views_test_data',
      'field' => 'description',
      'relationship' => 'none',
      'operator' => 'word',
      'value' => 'aCtor',
    ],
  ]);
  $this
    ->executeView($view);
  $resultset = [
    [
      'name' => 'George',
    ],
    [
      'name' => 'Ringo',
    ],
  ];
  $this
    ->assertIdenticalResultset($view, $resultset, $this->columnMap);
  $view
    ->destroy();
  $view = Views::getView('test_view');
  $view
    ->setDisplay();

  // Change the filtering
  $view->displayHandlers
    ->get('default')
    ->overrideOption('filters', [
    'description' => [
      'id' => 'description',
      'table' => 'views_test_data',
      'field' => 'description',
      'relationship' => 'none',
      'operator' => 'allwords',
      'value' => 'Richard Starkey',
    ],
  ]);
  $this
    ->executeView($view);
  $resultset = [
    [
      'name' => 'Ringo',
    ],
  ];
  $this
    ->assertIdenticalResultset($view, $resultset, $this->columnMap);
  $view
    ->destroy();
  $view = Views::getView('test_view');
  $view
    ->setDisplay();

  // Change the filtering to a sting containing only illegal characters.
  $view->displayHandlers
    ->get('default')
    ->overrideOption('filters', [
    'description' => [
      'id' => 'description',
      'table' => 'views_test_data',
      'field' => 'description',
      'relationship' => 'none',
      'operator' => 'allwords',
      'value' => ':-)',
    ],
  ]);
  $this
    ->executeView($view);
  $resultset = [
    [
      'name' => 'Ringo',
    ],
    [
      'name' => 'John',
    ],
    [
      'name' => 'George',
    ],
    [
      'name' => 'Paul',
    ],
    [
      'name' => 'Meredith',
    ],
  ];
  $this
    ->assertIdenticalResultset($view, $resultset);
}