You are here

public function FileDownloadLinkTest::testFormatterImageCustom in File Download Link 8

Test the formatter using custom settings for an image.

File

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

Class

FileDownloadLinkTest
Class for testing file_download_link formatter.

Namespace

Drupal\Tests\file_download_link\Kernel

Code

public function testFormatterImageCustom() {
  $settings = [
    'link_text' => '',
    'link_title' => 'Click for image',
    'new_tab' => FALSE,
    'force_download' => FALSE,
    'custom_classes' => 'Howdy! p@rtner',
  ];
  $render = $this->entity->field_image
    ->view([
    'type' => 'file_download_link',
    'label' => 'hidden',
    'settings' => $settings,
  ]);
  $file = $this->entity->field_image
    ->referencedEntities()[0];
  $expected_render = [
    '#type' => 'link',
    '#title' => 'file.png',
    '#url' => Url::fromUri(file_create_url('public://file.png')),
    '#options' => [
      'attributes' => [
        'class' => [
          'file-download',
          'file-download-image',
          'file-download-png',
          'Howdy',
          'prtner',
        ],
        'title' => 'Click for image',
      ],
    ],
    '#cache' => [
      'tags' => $file
        ->getCacheTags(),
      'contexts' => [],
      'max-age' => -1,
    ],
  ];
  Assert::assertEquals($expected_render, $render[0]);
}