You are here

protected function BackendTestBase::regressionTest2111753 in Search API 8

Regression tests for searching for multiple words using "OR" condition.

See also

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

1 call to BackendTestBase::regressionTest2111753()
BackendTestBase::regressionTests in tests/src/Kernel/BackendTestBase.php
Executes regression tests for issues that were already fixed.

File

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

Class

BackendTestBase
Provides a base class for backend tests.

Namespace

Drupal\Tests\search_api\Kernel

Code

protected function regressionTest2111753() {
  $keys = [
    '#conjunction' => 'OR',
    'foo',
    'test',
  ];
  $query = $this
    ->buildSearch($keys, [], [
    'name',
  ]);
  $results = $query
    ->execute();
  $this
    ->assertResults([
    1,
    2,
    4,
  ], $results, 'OR keywords');
  $query = $this
    ->buildSearch($keys, [], [
    'name',
    'body',
  ]);
  $query
    ->range(0, 0);
  $results = $query
    ->execute();
  $this
    ->assertEquals(5, $results
    ->getResultCount(), 'Multi-field OR keywords returned correct number of results.');
  $this
    ->assertEmpty($results
    ->getResultItems(), 'Multi-field OR keywords returned correct result.');
  $this
    ->assertEmpty($results
    ->getIgnoredSearchKeys());
  $this
    ->assertEmpty($results
    ->getWarnings());
  $keys = [
    '#conjunction' => 'OR',
    'foo',
    'test',
    [
      '#conjunction' => 'AND',
      'bar',
      'baz',
    ],
  ];
  $query = $this
    ->buildSearch($keys, [], [
    'name',
  ]);
  $results = $query
    ->execute();
  $this
    ->assertResults([
    1,
    2,
    4,
    5,
  ], $results, 'Nested OR keywords');
  $keys = [
    '#conjunction' => 'OR',
    [
      '#conjunction' => 'AND',
      'foo',
      'test',
    ],
    [
      '#conjunction' => 'AND',
      'bar',
      'baz',
    ],
  ];
  $query = $this
    ->buildSearch($keys, [], [
    'name',
    'body',
  ]);
  $results = $query
    ->execute();
  $this
    ->assertResults([
    1,
    2,
    4,
    5,
  ], $results, 'Nested multi-field OR keywords');
}