public function FileEntityFormatterTest::testFormatterFileExtension in Drupal 9
Same name and namespace in other branches
- 8 core/modules/file/tests/src/Kernel/Formatter/FileEntityFormatterTest.php \Drupal\Tests\file\Kernel\Formatter\FileEntityFormatterTest::testFormatterFileExtension()
- 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 118
Class
- FileEntityFormatterTest
- Tests the default file formatter.
Namespace
Drupal\Tests\file\Kernel\FormatterCode
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
->assertEquals($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
->assertEquals($expected[$i], $build['filename'][0]['#markup']);
}
}