You are here

protected function BackendTestBase::regressionTest1658964 in Search API 8

Regression tests for facets with counts of 0.

See also

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

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

File

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

Class

BackendTestBase
Provides a base class for backend tests.

Namespace

Drupal\Tests\search_api\Kernel

Code

protected function regressionTest1658964() {
  $query = $this
    ->buildSearch();
  $facets['type'] = [
    'field' => 'type',
    'limit' => 0,
    'min_count' => 0,
    'missing' => TRUE,
  ];
  $query
    ->setOption('search_api_facets', $facets);
  $query
    ->addCondition('type', 'article');
  $query
    ->range(0, 0);
  $results = $query
    ->execute();
  $expected = [
    [
      'count' => 2,
      'filter' => '"article"',
    ],
    [
      'count' => 0,
      'filter' => '!',
    ],
    [
      'count' => 0,
      'filter' => '"item"',
    ],
  ];
  $facets = $results
    ->getExtraData('search_api_facets', [])['type'];
  usort($facets, [
    $this,
    'facetCompare',
  ]);
  $this
    ->assertEquals($expected, $facets, 'Correct facets were returned');
}