You are here

public function FacetTest::testWidget in Facets 8

Tests widget behavior.

@covers ::setWidget @covers ::getWidget @covers ::getWidgetManager @covers ::getWidgetInstance

File

tests/src/Kernel/Entity/FacetTest.php, line 66

Class

FacetTest
Class FacetTest.

Namespace

Drupal\Tests\facets\Kernel\Entity

Code

public function testWidget() {
  $entity = new Facet([], 'facets_facet');
  $entity
    ->setWidget('links');
  $manager = $entity
    ->getWidgetManager();
  $this
    ->assertInstanceOf(WidgetPluginManager::class, $manager);
  $config = [
    'soft_limit' => 0,
    'show_numbers' => FALSE,
    'soft_limit_settings' => [
      'show_less_label' => 'Show less',
      'show_more_label' => 'Show more',
    ],
    'show_reset_link' => FALSE,
    'hide_reset_when_no_selection' => FALSE,
    'reset_text' => 'Show all',
  ];
  $this
    ->assertEquals([
    'type' => 'links',
    'config' => $config,
  ], $entity
    ->getWidget());
  $this
    ->assertInstanceOf(LinksWidget::class, $entity
    ->getWidgetInstance());
  $this
    ->assertFalse($entity
    ->getWidgetInstance()
    ->getConfiguration()['show_numbers']);
  $config['show_numbers'] = TRUE;
  $entity
    ->setWidget('links', $config);
  $this
    ->assertEquals([
    'type' => 'links',
    'config' => $config,
  ], $entity
    ->getWidget());
  $this
    ->assertInstanceOf(LinksWidget::class, $entity
    ->getWidgetInstance());
  $this
    ->assertTrue($entity
    ->getWidgetInstance()
    ->getConfiguration()['show_numbers']);
}