function FileEntityFormatterTest::testFormatterFileSize
Same name in other branches
- 8.9.x core/modules/file/tests/src/Kernel/Formatter/FileEntityFormatterTest.php \Drupal\Tests\file\Kernel\Formatter\FileEntityFormatterTest::testFormatterFileSize()
- 10 core/modules/file/tests/src/Kernel/Formatter/FileEntityFormatterTest.php \Drupal\Tests\file\Kernel\Formatter\FileEntityFormatterTest::testFormatterFileSize()
- 11.x core/modules/file/tests/src/Kernel/Formatter/FileEntityFormatterTest.php \Drupal\Tests\file\Kernel\Formatter\FileEntityFormatterTest::testFormatterFileSize()
Tests the file_size field formatter.
File
-
core/
modules/ file/ tests/ src/ Kernel/ Formatter/ FileEntityFormatterTest.php, line 160
Class
- FileEntityFormatterTest
- Tests the default file formatter.
Namespace
Drupal\Tests\file\Kernel\FormatterCode
public function testFormatterFileSize() {
$entity_display = EntityViewDisplay::create([
'targetEntityType' => 'file',
'bundle' => 'file',
]);
$entity_display->setComponent('filesize', [
'type' => 'file_size',
]);
$expected = [
'10 bytes',
'200 bytes',
'39.06 KB',
'7.63 MB',
];
foreach (array_values($this->files) as $i => $file) {
$build = $entity_display->build($file);
$this->assertEquals($expected[$i], $build['filesize'][0]['#markup']);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.