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