You are here

public function FileEntityFormatterTest::testFormatterFileLink in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/file/tests/src/Kernel/Formatter/FileEntityFormatterTest.php \Drupal\Tests\file\Kernel\Formatter\FileEntityFormatterTest::testFormatterFileLink()
  2. 10 core/modules/file/tests/src/Kernel/Formatter/FileEntityFormatterTest.php \Drupal\Tests\file\Kernel\Formatter\FileEntityFormatterTest::testFormatterFileLink()

Tests the file_link field formatter.

File

core/modules/file/tests/src/Kernel/Formatter/FileEntityFormatterTest.php, line 74

Class

FileEntityFormatterTest
Tests the default file formatter.

Namespace

Drupal\Tests\file\Kernel\Formatter

Code

public function testFormatterFileLink() {
  $entity_display = EntityViewDisplay::create([
    'targetEntityType' => 'file',
    'bundle' => 'file',
  ]);
  $entity_display
    ->setComponent('filename', [
    'type' => 'file_link',
  ]);
  $build = $entity_display
    ->buildMultiple($this->files)[0]['filename'][0];
  $this
    ->assertEqual('file.png', $build['#title']);
  $this
    ->assertEqual(Url::fromUri(file_create_url('public://file.png')), $build['#url']);
}