// Test the generateSampleValue() method.
$entity = EntityTest::
create();
$entity->file_test->
generateSampleItems();
$this->
entityValidateAndSave($entity);
// Verify that the sample file was stored in the correct directory.
$uri =
$entity->file_test->entity->
getFileUri();
/** @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager */
$stream_wrapper_manager = \Drupal::
service('stream_wrapper_manager'
);
$this->
assertEquals($this->directory,
dirname($stream_wrapper_manager::
getTarget($uri)));
// Make sure the computed files reflects updates to the file.
file_put_contents('public://example-3.txt',
$this->
randomMachineName());
// Test unsaved file entity.
$file3 = File::
create([ 'uri' => 'public://example-3.txt',
]);
$display = \Drupal::
service('entity_display.repository'
) ->
getViewDisplay('entity_test', 'entity_test'
);
$display->
setComponent('file_test',
[ 'label' => 'above',