You are here

public function SlickFormatterTest::testSlickFormatter in Slick Carousel 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/SlickFormatterTest.php \Drupal\Tests\slick\Kernel\SlickFormatterTest::testSlickFormatter()

Tests the Slick formatters.

File

tests/src/Kernel/SlickFormatterTest.php, line 87

Class

SlickFormatterTest
Tests the Slick field rendering using the image field type.

Namespace

Drupal\Tests\slick\Kernel

Code

public function testSlickFormatter() {
  $entity = $this->entity;

  // Generate the render array to verify if the cache tags are as expected.
  $build = $this->display
    ->build($entity);
  $build_empty = $this->displayEmpty
    ->build($entity);
  $render = $this->slickManager
    ->getRenderer()
    ->renderRoot($build);
  $this
    ->assertNotEmpty($render);
  $render_empty = $this->slickManager
    ->getRenderer()
    ->renderRoot($build_empty[$this->testEmptyName]);
  $this
    ->assertEmpty($render_empty);
  $this
    ->assertInstanceOf('\\Drupal\\Core\\Field\\FieldItemListInterface', $this->testItems);
  $this
    ->assertInstanceOf('\\Drupal\\slick\\Form\\SlickAdminInterface', $this->formatterInstance
    ->admin());
  $this
    ->assertInstanceOf('\\Drupal\\slick\\SlickFormatterInterface', $this->formatterInstance
    ->formatter());
  $this
    ->assertInstanceOf('\\Drupal\\slick\\SlickManagerInterface', $this->formatterInstance
    ->manager());
  $component = $this->display
    ->getComponent($this->testFieldName);
  $this
    ->assertEquals($this->testPluginId, $component['type']);
  $this
    ->assertEquals($this->testPluginId, $build[$this->testFieldName]['#formatter']);
  $scopes = $this->formatterInstance
    ->getScopedFormElements();
  $this
    ->assertEquals('slick', $scopes['namespace']);
  $this
    ->assertArrayHasKey('optionset', $scopes['settings']);
  $summary = $this->formatterInstance
    ->settingsSummary();
  $this
    ->assertNotEmpty($summary);
}