public function FileDownloadLinkTest::testFormatterFileDefault in File Download Link 8
Test the formatter using default settings for a file.
File
- tests/
src/ Kernel/ FileDownloadLinkTest.php, line 51
Class
- FileDownloadLinkTest
- Class for testing file_download_link formatter.
Namespace
Drupal\Tests\file_download_link\KernelCode
public function testFormatterFileDefault() {
$render = $this->entity->field_file
->view([
'type' => 'file_download_link',
'label' => 'hidden',
]);
$file = $this->entity->field_file
->referencedEntities()[0];
$expected_render = [
'#type' => 'link',
'#title' => 'Download',
'#url' => Url::fromUri(file_create_url('public://file.txt')),
'#options' => [
'attributes' => [
'class' => [
'file-download',
'file-download-text',
'file-download-plain',
],
'target' => '_blank',
'download' => TRUE,
],
],
'#cache' => [
'tags' => $file
->getCacheTags(),
'contexts' => [],
'max-age' => -1,
],
];
Assert::assertEquals($expected_render, $render[0]);
}