Commit 852a07d5 authored by alexpott's avatar alexpott

Issue #2532280 by mr.baileys, DuaelFr: Fatal error while trying to use...

Issue #2532280 by mr.baileys, DuaelFr: Fatal error while trying to use \Drupal\file\Plugin\Field\FieldType\FileItem::generateSampleValue()
parent 14c552f3
......@@ -309,8 +309,12 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin
$random = new Random();
$settings = $field_definition->getSettings();
// Prepare destination.
$dirname = $settings['uri_scheme'] . '://' . $settings['file_directory'];
file_prepare_directory($dirname, FILE_CREATE_DIRECTORY);
// Generate a file entity.
$destination = $settings['uri_scheme'] . '://' . $settings['file_directory'] . $random->name(10, TRUE) . '.txt';
$destination = $dirname . '/' . $random->name(10, TRUE) . '.txt';
$data = $random->paragraphs(3);
$file = file_save_data($data, $destination, FILE_EXISTS_ERROR);
$values = array(
......
......@@ -33,6 +33,13 @@ class FileItemTest extends FieldUnitTestBase {
*/
protected $file;
/**
* Directory where the sample files are stored.
*
* @var string
*/
protected $directory;
protected function setUp() {
parent::setUp();
......@@ -45,10 +52,12 @@ protected function setUp() {
'type' => 'file',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
))->save();
$this->directory = $this->getRandomGenerator()->name(8);
entity_create('field_config', array(
'entity_type' => 'entity_test',
'field_name' => 'file_test',
'bundle' => 'entity_test',
'settings' => array('file_directory' => $this->directory),
))->save();
file_put_contents('public://example.txt', $this->randomMachineName());
$this->file = entity_create('file', array(
......@@ -100,6 +109,9 @@ public function testFileItem() {
$entity = entity_create('entity_test');
$entity->file_test->generateSampleItems();
$this->entityValidateAndSave($entity);
// Verify that the sample file was stored in the correct directory.
$uri = $entity->file_test->entity->getFileUri();
$this->assertEqual($this->directory, dirname(file_uri_target($uri)));
// Make sure the computed files reflects updates to the file.
file_put_contents('public://example-3.txt', $this->randomMachineName());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment