public function IndexFacetsTest::testEmptyFacets in JSON:API Search API 8
Tests facets are rendeted properly when empty.
File
- modules/
jsonapi_search_api_facets/ tests/ src/ Functional/ IndexFacetsTest.php, line 234
Class
- IndexFacetsTest
- Tests searching with facets.
Namespace
Drupal\Tests\jsonapi_search_api_facets\FunctionalCode
public function testEmptyFacets() {
$this
->createFacet('keywords', 'Keywords', 'keywords', 'or', FALSE);
$this
->createFacet('category', 'Category', 'category', 'or', FALSE);
$url = Url::fromRoute('jsonapi_search_api.index_database_search_index', [], [
'query' => [
'filter' => [
'name' => 'does not exist',
],
],
]);
$data = $this
->doRequest($url);
$this
->assertCount(0, $data['data']);
$this
->assertArrayHasKey('facets', $data['meta'], var_export($data, TRUE));
$facet_ids = array_map(static function (array $facet) {
return $facet['id'];
}, $data['meta']['facets']);
$this
->assertEquals([
'category',
'keywords',
], $facet_ids);
foreach ($data['meta']['facets'] as $facet) {
$this
->assertEquals([
'id',
'label',
'path',
'terms',
], array_keys($facet));
$this
->assertCount(0, $facet['terms'], var_export($facet, TRUE));
}
}