You are here

public function FileEntityFormatterTest::testFormatterFileExtension 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::testFormatterFileExtension()
  2. 10 core/modules/file/tests/src/Kernel/Formatter/FileEntityFormatterTest.php \Drupal\Tests\file\Kernel\Formatter\FileEntityFormatterTest::testFormatterFileExtension()

Tests the file_extension field formatter.

File

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

Class

FileEntityFormatterTest
Tests the default file formatter.

Namespace

Drupal\Tests\file\Kernel\Formatter

Code

public function testFormatterFileExtension() {
  $entity_display = EntityViewDisplay::create([
    'targetEntityType' => 'file',
    'bundle' => 'file',
  ]);
  $entity_display
    ->setComponent('filename', [
    'type' => 'file_extension',
  ]);
  $expected = [
    'png',
    'tar',
    'gz',
    '',
  ];
  foreach (array_values($this->files) as $i => $file) {
    $build = $entity_display
      ->build($file);
    $this
      ->assertEqual($expected[$i], $build['filename'][0]['#markup']);
  }
  $entity_display
    ->setComponent('filename', [
    'type' => 'file_extension',
    'settings' => [
      'extension_detect_tar' => TRUE,
    ],
  ]);
  $expected = [
    'png',
    'tar',
    'tar.gz',
    '',
  ];
  foreach (array_values($this->files) as $i => $file) {
    $build = $entity_display
      ->build($file);
    $this
      ->assertEqual($expected[$i], $build['filename'][0]['#markup']);
  }
}