You are here

protected function BackendTestBase::regressionTest2616804 in Search API 8

Regression tests for multibyte characters exceeding 50 byte.

See also

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

1 call to BackendTestBase::regressionTest2616804()
BackendTestBase::regressionTests2 in tests/src/Kernel/BackendTestBase.php
Executes regression tests which are unpractical to run in between.

File

tests/src/Kernel/BackendTestBase.php, line 1023

Class

BackendTestBase
Provides a base class for backend tests.

Namespace

Drupal\Tests\search_api\Kernel

Code

protected function regressionTest2616804() {

  // The word has 28 Unicode characters but 56 bytes. Verify that it is still
  // indexed correctly.
  $mb_word = 'äöüßáŧæøðđŋħĸµäöüßáŧæøðđŋħĸµ';

  // We put the word 8 times into the body so we can also verify that the 255
  // character limit for strings counts characters, not bytes.
  $mb_body = implode(' ', array_fill(0, 8, $mb_word));
  $this
    ->addTestEntity(9, [
    'name' => 'Test item 9',
    'type' => 'item',
    'body' => $mb_body,
  ]);
  $count = $this
    ->indexItems($this->indexId);
  $this
    ->assertEquals(1, $count, 'Indexing an item with a word with 28 multi-byte characters worked.');
  $query = $this
    ->buildSearch($mb_word);
  $results = $query
    ->execute();
  $this
    ->assertResults([
    9,
  ], $results, 'Search for word with 28 multi-byte characters');
  $query = $this
    ->buildSearch($mb_word . 'ä');
  $results = $query
    ->execute();
  $this
    ->assertResults([], $results, 'Search for unknown word with 29 multi-byte characters');

  // Test the same body when indexed as a string (255 characters limit should
  // not be reached).
  $index = $this
    ->getIndex();
  $index
    ->getField('body')
    ->setType('string');
  $index
    ->save();
  $entity_count = count($this->entities);
  $count = $this
    ->indexItems($this->indexId);
  $this
    ->assertEquals($entity_count, $count, 'Switching type from text to string worked.');
  $query = $this
    ->buildSearch(NULL, [
    "body,{$mb_body}",
  ]);
  $results = $query
    ->execute();
  $this
    ->assertResults([
    9,
  ], $results, 'Search for body with 231 multi-byte characters');
  $query = $this
    ->buildSearch(NULL, [
    "body,{$mb_body}ä",
  ]);
  $results = $query
    ->execute();
  $this
    ->assertResults([], $results, 'Search for unknown body with 232 multi-byte characters');
  $index
    ->getField('body')
    ->setType('text');
  $index
    ->save();
}