You are here

protected function BackendTest::regressionTest2994022 in Search API 8

Tests facets functionality for empty result sets.

See also

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

1 call to BackendTest::regressionTest2994022()
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 715

Class

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

Namespace

Drupal\Tests\search_api_db\Kernel

Code

protected function regressionTest2994022() {
  $query = $this
    ->buildSearch('nonexistent_search_term');
  $facets['category'] = [
    'field' => 'category',
    'limit' => 0,
    'min_count' => 0,
    'missing' => FALSE,
    'operator' => 'and',
  ];
  $query
    ->setOption('search_api_facets', $facets);
  $results = $query
    ->execute();
  $this
    ->assertResults([], $results, 'Non-existent keyword');
  $expected = [
    [
      'count' => 0,
      'filter' => '"article_category"',
    ],
    [
      'count' => 0,
      'filter' => '"item_category"',
    ],
  ];
  $category_facets = $results
    ->getExtraData('search_api_facets')['category'];
  usort($category_facets, [
    $this,
    'facetCompare',
  ]);
  $this
    ->assertEquals($expected, $category_facets, 'Correct facets were returned for minimum count 0');
  $query = $this
    ->buildSearch('nonexistent_search_term');
  $conditions = $query
    ->createConditionGroup('AND', [
    'facet:category',
  ]);
  $conditions
    ->addCondition('category', 'article_category');
  $query
    ->addConditionGroup($conditions);
  $facets['category'] = [
    'field' => 'category',
    'limit' => 0,
    'min_count' => 0,
    'missing' => FALSE,
    'operator' => 'and',
  ];
  $query
    ->setOption('search_api_facets', $facets);
  $results = $query
    ->execute();
  $this
    ->assertResults([], $results, 'Non-existent keyword with filter');
  $expected = [
    [
      'count' => 0,
      'filter' => '"article_category"',
    ],
    [
      'count' => 0,
      'filter' => '"item_category"',
    ],
  ];
  $category_facets = $results
    ->getExtraData('search_api_facets')['category'];
  usort($category_facets, [
    $this,
    'facetCompare',
  ]);
  $this
    ->assertEquals($expected, $category_facets, 'Correct facets were returned for minimum count 0');
}