You are here

public function FileEntityFormatterTest::testFormatterFileUri in Drupal 10

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

Tests the file_link field formatter.

File

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

Class

FileEntityFormatterTest
Tests the default file formatter.

Namespace

Drupal\Tests\file\Kernel\Formatter

Code

public function testFormatterFileUri() {
  $entity_display = EntityViewDisplay::create([
    'targetEntityType' => 'file',
    'bundle' => 'file',
  ]);
  $entity_display
    ->setComponent('uri', [
    'type' => 'file_uri',
  ]);
  $build = $entity_display
    ->buildMultiple($this->files)[0]['uri'][0];
  $this
    ->assertEquals('public://file.png', $build['#markup']);
  $entity_display
    ->setComponent('uri', [
    'type' => 'file_uri',
    'settings' => [
      'file_download_path' => TRUE,
    ],
  ]);
  $build = $entity_display
    ->buildMultiple($this->files)[0]['uri'][0];
  $this
    ->assertEquals($this->fileUrlGenerator
    ->generateString('public://file.png'), $build['#markup']);
  $entity_display
    ->setComponent('uri', [
    'type' => 'file_uri',
    'settings' => [
      'file_download_path' => TRUE,
      'link_to_file' => TRUE,
    ],
  ]);
  $build = $entity_display
    ->buildMultiple($this->files)[0]['uri'][0];
  $this
    ->assertEquals($this->fileUrlGenerator
    ->generateString('public://file.png'), $build['#title']);
  $this
    ->assertEquals($this->fileUrlGenerator
    ->generate('public://file.png'), $build['#url']);
}