1 file.test | protected FileAccessFunctionsAlignedTestCase::createExampleFile($filename, $owner_uid, $public) |
Helper function to create some files.
File
- core/
modules/ file/ tests/ file.test, line 3736 - Tests for file.module.
Class
- FileAccessFunctionsAlignedTestCase
- Tests that file_access and File::access are in sync with what they return.
Code
protected function createExampleFile($filename, $owner_uid, $public) {
if ($public) {
$filepath = 'public://' . $filename;
}
else {
$filepath = 'private://' . $filename;
}
file_put_contents($filepath, $this->randomName(15));
$file = new File();
$file->uri = $filepath;
$file->filename = $filename;
$file->filemime = 'text/plain';
$file->uid = $owner_uid;
$file->timestamp = REQUEST_TIME;
$file->filesize = filesize($file->uri);
$file->status = 1;
$file->type = 'document';
backdrop_write_record('file_managed', $file);
return entity_create('file', (array) $file);
}