You are here

public function GridStackManagerTest::testBuild in GridStack 8

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

Tests for GridStack build.

@covers ::build @covers ::preRenderGridStack @dataProvider providerTestGridStackBuild

Parameters

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

array $settings: The settings being tested.

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

File

tests/src/Kernel/GridStackManagerTest.php, line 147

Class

GridStackManagerTest
Tests the GridStack manager methods.

Namespace

Drupal\Tests\gridstack\Kernel

Code

public function testBuild($items, array $settings, $expected) {
  $manager = $this->gridstackManager;
  $defaults = $this
    ->getFormatterSettings() + GridStack::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,
    'optionset' => GridStack::load($settings['optionset']),
  ];
  $gridstack = $manager
    ->build($build);
  $this
    ->assertEquals($expected, !empty($gridstack));
  $gridstack['#build']['items'] = $items;
  $gridstack['#build']['settings'] = $settings;
  $elements = $manager
    ->preRenderGridStack($gridstack);
  $this
    ->assertEquals($expected, !empty($elements));
}