You are here

public function FileEntityFormatterTest::testFormatterFileExtension in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Tests/Formatter/FileEntityFormatterTest.php \Drupal\file\Tests\Formatter\FileEntityFormatterTest::testFormatterFileExtension()

Tests the file_extension field formatter.

File

core/modules/file/src/Tests/Formatter/FileEntityFormatterTest.php, line 117
Contains \Drupal\file\Tests\Formatter\FileEntityFormatterTest.

Class

FileEntityFormatterTest
Tests the default file formatter.

Namespace

Drupal\file\Tests\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']);
  }
}