You are here

private function IndexFacetsTest::createFacet in JSON:API Search API 8

Creates a facet.

Parameters

string $field_name: The index field name.

string $name: The facet name.

string $url_alias: The facet URL alias.

string $query_operator: The query operator, 'or' or 'and'.

bool $show_numbers: Whether to show numbers.

Throws

\Drupal\Core\Entity\EntityStorageException

3 calls to IndexFacetsTest::createFacet()
IndexFacetsTest::testEmptyFacets in modules/jsonapi_search_api_facets/tests/src/Functional/IndexFacetsTest.php
Tests facets are rendeted properly when empty.
IndexFacetsTest::testWithExistingFilter in modules/jsonapi_search_api_facets/tests/src/Functional/IndexFacetsTest.php
Tests that existing filters are preserved in facet term URLs.
IndexFacetsTest::testWithFacets in modules/jsonapi_search_api_facets/tests/src/Functional/IndexFacetsTest.php
Test facet data.

File

modules/jsonapi_search_api_facets/tests/src/Functional/IndexFacetsTest.php, line 91

Class

IndexFacetsTest
Tests searching with facets.

Namespace

Drupal\Tests\jsonapi_search_api_facets\Functional

Code

private function createFacet(string $field_name, string $name, string $url_alias, string $query_operator, bool $show_numbers) : void {
  assert($query_operator === 'and' || $query_operator === 'or', '$query_operator must be `or` or `and`');
  Facet::create([
    'id' => $field_name,
    'name' => $name,
    'url_alias' => $url_alias,
    'query_operator' => $query_operator,
    'field_identifier' => $field_name,
    'facet_source_id' => 'jsonapi_search_api_facets:database_search_index',
    'widget' => [
      'type' => 'jsonapi_search_api',
      'config' => [
        'show_numbers' => $show_numbers,
      ],
    ],
    'empty_behavior' => [
      'behavior' => 'none',
    ],
    'processor_configs' => [
      'url_processor_handler' => [
        'processor_id' => 'url_processor_handler',
        'weights' => [
          'pre_query' => -10,
          'build' => -10,
        ],
        'settings' => [],
      ],
    ],
  ])
    ->save();
}