You are here

public function SlickManagerTest::testBuild in Slick Carousel 8

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

Tests for Slick build.

@covers ::slick @covers ::preRenderSlick @covers ::buildGrid @covers ::build @covers ::preRenderSlickWrapper @dataProvider providerTestSlickBuild

Parameters

bool $items: Whether to provide items, or not.

array $settings: The settings being tested.

array $options: The options being tested.

mixed|bool|string $expected: The expected output.

File

tests/src/Kernel/SlickManagerTest.php, line 140

Class

SlickManagerTest
Tests the Slick manager methods.

Namespace

Drupal\Tests\slick\Kernel

Code

public function testBuild($items, array $settings, array $options, $expected) {
  $manager = $this->slickManager;
  $defaults = $this
    ->getFormatterSettings() + Slick::htmlSettings();
  $settings = array_merge($defaults, $settings);
  $settings['optionset'] = 'test';
  $build = $this->display
    ->build($this->entity);
  $items = !$items ? [] : $build[$this->testFieldName]['#build']['items'];
  $build = [
    'items' => $items,
    'settings' => $settings,
    'options' => $options,
    'optionset' => Slick::load($settings['optionset']),
  ];
  $slick = $manager::slick($build);
  $this
    ->assertEquals($expected, !empty($slick));
  $slick['#build']['settings'] = $settings;
  $slick['#build']['items'] = $items;
  $element = $manager::preRenderSlick($slick);
  $this
    ->assertEquals($expected, !empty($element));
  if (!empty($settings['optionset_thumbnail'])) {
    $build['thumb'] = [
      'items' => $items,
      'settings' => $settings,
      'options' => $options,
    ];
  }
  $slicks = $manager
    ->build($build);
  $this
    ->assertEquals($expected, !empty($slicks));
  $slicks['#build']['items'] = $items;
  $slicks['#build']['settings'] = $settings;
  if (!empty($settings['optionset_thumbnail'])) {
    $slicks['#build']['thumb']['items'] = $build['thumb']['items'];
    $slicks['#build']['thumb']['settings'] = $build['thumb']['settings'];
  }
  $elements = $manager
    ->preRenderSlickWrapper($slicks);
  $this
    ->assertEquals($expected, !empty($elements));
}