You are here

public function FileDownloadLinkTest::testFormatterImageDefault in File Download Link 8

Test the formatter using default settings for an image.

File

tests/src/Kernel/FileDownloadLinkTest.php, line 128

Class

FileDownloadLinkTest
Class for testing file_download_link formatter.

Namespace

Drupal\Tests\file_download_link\Kernel

Code

public function testFormatterImageDefault() {
  $render = $this->entity->field_image
    ->view([
    'type' => 'file_download_link',
    'label' => 'hidden',
  ]);
  $file = $this->entity->field_image
    ->referencedEntities()[0];
  $expected_render = [
    '#type' => 'link',
    '#title' => 'Download',
    '#url' => Url::fromUri(file_create_url('public://file.png')),
    '#options' => [
      'attributes' => [
        'class' => [
          'file-download',
          'file-download-image',
          'file-download-png',
        ],
        'target' => '_blank',
        'download' => TRUE,
      ],
    ],
    '#cache' => [
      'tags' => $file
        ->getCacheTags(),
      'contexts' => [],
      'max-age' => -1,
    ],
  ];
  Assert::assertEquals($expected_render, $render[0]);
}