You are here

protected function BackendTest::regressionTest2873023 in Search API 8

Tests whether keywords with special characters work correctly.

See also

https://www.drupal.org/node/2873023

1 call to BackendTest::regressionTest2873023()
BackendTest::backendSpecificRegressionTests in modules/search_api_db/tests/src/Kernel/BackendTest.php
Runs backend specific regression tests.

File

modules/search_api_db/tests/src/Kernel/BackendTest.php, line 786

Class

BackendTest
Tests index and search capabilities using the Database search backend.

Namespace

Drupal\Tests\search_api_db\Kernel

Code

protected function regressionTest2873023() {
  $keyword = 'regression@test@2873023';
  $entity_id = count($this->entities) + 1;
  $entity = $this
    ->addTestEntity($entity_id, [
    'name' => $keyword,
    'type' => 'article',
  ]);
  $index = $this
    ->getIndex();
  $this
    ->assertFalse($index
    ->isValidProcessor('tokenizer'));
  $this
    ->indexItems($this->indexId);
  $results = $this
    ->buildSearch($keyword, [], [
    'name',
  ])
    ->execute();
  $this
    ->assertResults([
    $entity_id,
  ], $results, 'Keywords with special characters (Tokenizer disabled)');
  $processor = \Drupal::getContainer()
    ->get('search_api.plugin_helper')
    ->createProcessorPlugin($index, 'tokenizer');
  $index
    ->addProcessor($processor);
  $index
    ->save();
  $this
    ->assertTrue($index
    ->isValidProcessor('tokenizer'));
  $this
    ->indexItems($this->indexId);
  $results = $this
    ->buildSearch($keyword, [], [
    'name',
  ])
    ->execute();
  $this
    ->assertResults([
    $entity_id,
  ], $results, 'Keywords with special characters (Tokenizer enabled)');
  $index
    ->getProcessor('tokenizer')
    ->setConfiguration([
    'spaces' => '\\s',
  ]);
  $index
    ->save();
  $this
    ->indexItems($this->indexId);
  $results = $this
    ->buildSearch($keyword, [], [
    'name',
  ])
    ->execute();
  $this
    ->assertResults([
    $entity_id,
  ], $results, 'Keywords with special characters (Tokenizer with special config)');
  $index
    ->removeProcessor('tokenizer');
  $index
    ->save();
  $this
    ->assertFalse($index
    ->isValidProcessor('tokenizer'));
  $entity
    ->delete();
  unset($this->entities[$entity_id]);
}