public function FileDownloadLinkTokenTest::testClearTokens in File Download Link 8
Tests that tokes are cleared correctly.
File
- tests/
src/ Kernel/ FileDownloadLinkTokenTest.php, line 316
Class
- FileDownloadLinkTokenTest
- Class for testing file_download_link formatter with tokens.
Namespace
Drupal\Tests\file_download_link\KernelCode
public function testClearTokens() {
// Text should end up as file name.
// Title should end up unset.
$settings = [
'link_text' => '[fake:token]',
'link_title' => '[fake:token]',
'custom_classes' => '[fake:token]',
'new_tab' => FALSE,
'force_download' => FALSE,
];
$render = $this->entity->field_file
->view([
'type' => 'file_download_link',
'label' => 'hidden',
'settings' => $settings,
]);
$file = $this->entity->field_file
->referencedEntities()[0];
$expected_render = [
'#type' => 'link',
'#title' => 'file.txt',
'#url' => Url::fromUri(file_create_url('public://file.txt')),
'#options' => [
'attributes' => [
'class' => [
'file-download',
'file-download-text',
'file-download-plain',
],
],
],
'#cache' => [
'tags' => array_merge($file
->getCacheTags(), $this->entity
->getCacheTags()),
'contexts' => [],
'max-age' => -1,
],
'#attached' => [],
];
Assert::assertEquals($expected_render, $render[0]);
}