protected function FileFieldWidgetTest::createTemporaryFile in Drupal 9
Same name and namespace in other branches
- 8 core/modules/file/tests/src/Functional/FileFieldWidgetTest.php \Drupal\Tests\file\Functional\FileFieldWidgetTest::createTemporaryFile()
Creates a temporary file, for a specific user.
Parameters
string $data: A string containing the contents of the file.
\Drupal\user\UserInterface $user: The user of the file owner.
Return value
\Drupal\file\FileInterface A file object, or FALSE on error.
1 call to FileFieldWidgetTest::createTemporaryFile()
- FileFieldWidgetTest::doTestTemporaryFileRemovalExploit in core/
modules/ file/ tests/ src/ Functional/ FileFieldWidgetTest.php - Helper for testing exploiting the temporary file removal using fid.
File
- core/
modules/ file/ tests/ src/ Functional/ FileFieldWidgetTest.php, line 57
Class
- FileFieldWidgetTest
- Tests the file field widget with public and private files.
Namespace
Drupal\Tests\file\FunctionalCode
protected function createTemporaryFile($data, UserInterface $user = NULL) {
$file = file_save_data($data, NULL, NULL);
if ($file) {
if ($user) {
$file
->setOwner($user);
}
else {
$file
->setOwner($this->adminUser);
}
// Change the file status to be temporary.
$file
->setTemporary();
// Save the changes.
$file
->save();
}
return $file;
}