public static function MockData::createFile in GatherContent 8.5
Same name and namespace in other branches
- 8.4 tests/modules/gathercontent_test/src/MockData.php \Drupal\gathercontent_test\MockData::createFile()
Create a file for every file element in item.
File
- tests/
modules/ gathercontent_test/ src/ MockData.php, line 169
Class
- MockData
- A class for getting static test data.
Namespace
Drupal\gathercontent_testCode
public static function createFile(Item $item) {
$fileElements = array_filter(reset($item->config)->elements, function ($element) {
return $element instanceof ElementFiles;
});
$files = [];
foreach ($fileElements as $element) {
$file = new File();
$file->id = static::getUniqueInt();
$file->userId = static::getUniqueInt();
$file->itemId = $item->id;
$file->field = $element->id;
$file->url = static::$drupalRoot . '/' . drupal_get_path('module', 'gathercontent_test') . '/images/test.png';
$file->fileName = 'test.jpg';
$file->size = 60892;
$file->type = 'field';
$file->createdAt = '2017-08-18 15:48:10';
$file->updatedAt = '2017-08-18 15:48:10';
$files[$file->id] = $file;
}
return $files;
}