You are here

public function FacetFacetSourceTest::testFacetSource in Facets 8

Tests facet source behavior for the facet entity.

@covers ::getFacetSourceId @covers ::setFacetSourceId @covers ::getFacetSources @covers ::getFacetSource @covers ::getFacetSourceConfig

File

tests/src/Kernel/Entity/FacetFacetSourceTest.php, line 75

Class

FacetFacetSourceTest
Class FacetFacetSourceTest.

Namespace

Drupal\Tests\facets\Kernel\Entity

Code

public function testFacetSource() {
  $entity = new Facet([], 'facets_facet');
  $this
    ->assertNull($entity
    ->getFacetSourceId());

  // Check that the facet source is in the list of search api displays.
  $displays = $this->container
    ->get('plugin.manager.search_api.display')
    ->getDefinitions();
  $this
    ->assertArrayHasKey('views_page:search_api_test_view__page_1', $displays);

  // Check that has transformed into a facet source as expected.
  $facet_sources = $this->container
    ->get('plugin.manager.facets.facet_source')
    ->getDefinitions();
  $this
    ->assertArrayHasKey('search_api:views_page__search_api_test_view__page_1', $facet_sources);

  // Check the behavior of the facet sources.
  $display_name = 'search_api:views_page__search_api_test_view__page_1';
  $entity
    ->setFacetSourceId($display_name);
  $this
    ->assertEquals($display_name, $entity
    ->getFacetSourceId());
  $this
    ->assertInstanceOf(SearchApiDisplay::class, $entity
    ->getFacetSources()[$display_name]);
  $this
    ->assertInstanceOf(SearchApiDisplay::class, $entity
    ->getFacetSource());
  $this
    ->assertInstanceOf(FacetSourceInterface::class, $entity
    ->getFacetSourceConfig());
  $this
    ->assertEquals($display_name, $entity
    ->getFacetSourceConfig()
    ->getName());
  $this
    ->assertEquals('f', $entity
    ->getFacetSourceConfig()
    ->getFilterKey());
}