You are here

protected function BackendTest::regressionTest2926733 in Search API 8

Tests indexing of text tokens with leading/trailing whitespace.

See also

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

1 call to BackendTest::regressionTest2926733()
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 627

Class

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

Namespace

Drupal\Tests\search_api_db\Kernel

Code

protected function regressionTest2926733() {
  $index = $this
    ->getIndex();
  $item_id = $this
    ->getItemIds([
    1,
  ])[0];
  $fields_helper = \Drupal::getContainer()
    ->get('search_api.fields_helper');
  $item = $fields_helper
    ->createItem($index, $item_id);
  $field = clone $index
    ->getField('body');
  $value = new TextValue('test');
  $tokens = [];
  foreach ([
    'test',
    ' test',
    '  test',
    'test  ',
    ' test ',
  ] as $token) {
    $tokens[] = new TextToken($token);
  }
  $value
    ->setTokens($tokens);
  $field
    ->setValues([
    $value,
  ]);
  $item
    ->setFields([
    'body' => $field,
  ]);
  $item
    ->setFieldsExtracted(TRUE);
  $index
    ->getServerInstance()
    ->indexItems($index, [
    $item_id => $item,
  ]);

  // Make sure to re-index the proper version of the item to avoid confusing
  // the other tests.
  list($datasource_id, $raw_id) = Utility::splitCombinedId($item_id);
  $index
    ->trackItemsUpdated($datasource_id, [
    $raw_id,
  ]);
  $this
    ->indexItems($index
    ->id());
}