You are here

public function BlazyEntityReferenceFormatterTest::testBuildPreview in Blazy 8

Tests Blazy preview.

@dataProvider providerTestBuildPreview @depends testFormatterDisplay

Parameters

array $settings: The settings being tested.

bool $is_entity: Tests againts entity or image.

bool $is_item: Tests againts empty image.

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

File

tests/src/Kernel/BlazyEntityReferenceFormatterTest.php, line 192

Class

BlazyEntityReferenceFormatterTest
Tests the Blazy entity reference file formatter.

Namespace

Drupal\Tests\blazy\Kernel

Code

public function testBuildPreview(array $settings, $is_entity, $is_item, $expected) {

  // @todo remove once corrected, likely broken since Drupal 8.4+.
  if (!$this->formatterInstance) {
    $this
      ->assertEquals(NULL, $this->formatterInstance);
    return;
  }
  $this
    ->buildContents();
  $formatter = $this->formatterInstance;
  $definition = array_merge($formatter
    ->getScopedFormElements(), $this
    ->getFormatterDefinition());
  $settings = array_merge($definition['settings'], $settings) + $this
    ->getDefaultFields(TRUE);
  $settings['delta'] = 0;
  $item = $is_item ? $this->referencedEntity
    ->get($this->testFieldName) : NULL;
  $entity = $is_entity ? $this->referencedEntity : $this->testItem;
  $data = [
    'item' => $item,
    'settings' => $settings,
  ];
  $preview = $formatter
    ->buildPreview($data, $entity, '');
  $result = $is_entity ? !empty($preview) : $preview;
  $this
    ->assertEquals($expected, $result);
}