You are here

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

Tests the file_extension field formatter.

File

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

Class

FileEntityFormatterTest
Tests the default file formatter.

Namespace

Drupal\Tests\file\Kernel\Formatter

Code

public function testFormatterFileMime() {
  $entity_display = EntityViewDisplay::create([
    'targetEntityType' => 'file',
    'bundle' => 'file',
  ]);
  $entity_display
    ->setComponent('filemime', [
    'type' => 'file_filemime',
    'settings' => [
      'filemime_image' => TRUE,
    ],
  ]);
  foreach (array_values($this->files) as $i => $file) {
    $build = $entity_display
      ->build($file);
    $this
      ->assertEqual('image__file_icon', $build['filemime'][0]['#theme']);
    $this
      ->assertEqual(spl_object_hash($file), spl_object_hash($build['filemime'][0]['#file']));
  }
}