function FileEntityFormatterTest::testFormatterFileExtension
Same name in other branches
- 9 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()
- 11.x 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\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->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']);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.