public function FileDownloadLinkTokenTest::testFormatterImageTokens in File Download Link 8
Test the formatter using a token from the image.
File
- tests/src/ Kernel/ FileDownloadLinkTokenTest.php, line 134 
Class
- FileDownloadLinkTokenTest
- Class for testing file_download_link formatter with tokens.
Namespace
Drupal\Tests\file_download_link\KernelCode
public function testFormatterImageTokens() {
  $settings = [
    'link_text' => 'The extension is [file:extension]',
    'new_tab' => FALSE,
    'force_download' => FALSE,
  ];
  $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' => 'The extension is png',
    '#url' => Url::fromUri(file_create_url('public://file.png')),
    '#options' => [
      'attributes' => [
        'class' => [
          'file-download',
          'file-download-image',
          'file-download-png',
        ],
      ],
    ],
    '#cache' => [
      'tags' => array_merge($file
        ->getCacheTags(), $this->entity
        ->getCacheTags()),
      'contexts' => [],
      'max-age' => -1,
    ],
    '#attached' => [],
  ];
  Assert::assertEquals($expected_render, $render[0]);
}