1 file.test FileTestHelper::createTemporaryFile($data, $uid = NULL)

Creates a temporary file, for a specific user.

Parameters

string $data: A string containing the contents of the file.

int $uid: The user ID of the file owner.

Return value

File: A file object, or FALSE on error.

File

core/modules/file/tests/file.test, line 438
Tests for file.module.

Class

FileTestHelper
Provides methods specifically for testing File module's field handling.

Code

function createTemporaryFile($data, $uid = NULL) {
  $file = file_save_data($data);

  if ($file) {
    $file->uid = isset($uid) ? $uid : $this->admin_user->uid;
    // Change the file status to be temporary.
    $file->status = 0;
    file_save($file);
  }

  return $file;
}