You are here

protected function BackendTestBase::regressionTest2469547 in Search API 8

Regression tests for facets on fulltext fields.

See also

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

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

File

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

Class

BackendTestBase
Provides a base class for backend tests.

Namespace

Drupal\Tests\search_api\Kernel

Code

protected function regressionTest2469547() {
  $query = $this
    ->buildSearch();
  $facets = [];
  $facets['body'] = [
    'field' => 'body',
    'limit' => 0,
    'min_count' => 1,
    'missing' => FALSE,
  ];
  $query
    ->setOption('search_api_facets', $facets);
  $query
    ->addCondition('id', 5, '<>');
  $query
    ->range(0, 0);
  $results = $query
    ->execute();
  $expected = [
    [
      'count' => 4,
      'filter' => '"test"',
    ],
    [
      'count' => 2,
      'filter' => '"Case"',
    ],
    [
      'count' => 2,
      'filter' => '"casE"',
    ],
    [
      'count' => 1,
      'filter' => '"bar"',
    ],
    [
      'count' => 1,
      'filter' => '"case"',
    ],
    [
      'count' => 1,
      'filter' => '"foobar"',
    ],
  ];

  // We can't guarantee the order of returned facets, since "bar" and "foobar"
  // both occur once, so we have to manually sort the returned facets first.
  $facets = $results
    ->getExtraData('search_api_facets', [])['body'];
  usort($facets, [
    $this,
    'facetCompare',
  ]);
  $this
    ->assertEquals($expected, $facets, 'Correct facets were returned for a fulltext field.');
}