You are here

public function FileEntityFormatterTest::testFormatterFileMime 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::testFormatterFileMime()
  2. 9 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 143

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
      ->assertEquals('image__file_icon', $build['filemime'][0]['#theme']);
    $this
      ->assertEquals(spl_object_hash($file), spl_object_hash($build['filemime'][0]['#file']));
  }
}