function FileItemTest::testGenerateSampleValue
Tests sample value generation with actual allowed file extensions.
1 method overrides FileItemTest::testGenerateSampleValue()
- WorkspacesFileItemTest::testGenerateSampleValue in core/
modules/ workspaces/ tests/ src/ Kernel/ WorkspacesFileItemTest.php - Tests sample value generation with actual allowed file extensions.
File
-
core/
modules/ file/ tests/ src/ Kernel/ FileItemTest.php, line 209
Class
- FileItemTest
- Tests using entity fields of the file field type.
Namespace
Drupal\Tests\file\KernelCode
public function testGenerateSampleValue() : void {
/** @var \Drupal\field\Entity\FieldConfig $field_definition */
$field_definition = FieldConfig::loadByName('entity_test', 'entity_test', 'file_test');
$field_definition->setSetting('file_extensions', 'pdf');
$field_definition->save();
$class = $field_definition->getItemDefinition()
->getClass();
$value = call_user_func("{$class}::generateSampleValue", $field_definition);
/** @var \Drupal\file\FileInterface $file */
$file = File::load($value['target_id']);
$this->assertStringEndsWith('.pdf', $file->getFileUri());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.