function FileEntityFormatterTest::testFormatterFileUri

Same name in other branches
  1. 9 core/modules/file/tests/src/Kernel/Formatter/FileEntityFormatterTest.php \Drupal\Tests\file\Kernel\Formatter\FileEntityFormatterTest::testFormatterFileUri()
  2. 10 core/modules/file/tests/src/Kernel/Formatter/FileEntityFormatterTest.php \Drupal\Tests\file\Kernel\Formatter\FileEntityFormatterTest::testFormatterFileUri()
  3. 11.x 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 89

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->assertEqual('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->assertEqual(file_create_url('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->assertEqual(file_create_url('public://file.png'), $build['#title']);
    $this->assertEqual(Url::fromUri(file_create_url('public://file.png')), $build['#url']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.