You are here

function FileFieldTestCase::createTemporaryFile in Drupal 7

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

object A file object, or FALSE on error.

1 call to FileFieldTestCase::createTemporaryFile()
FileFieldWidgetTestCase::doTestTemporaryFileRemovalExploit in modules/file/tests/file.test
Helper for testing exploiting the temporary file removal using fid.

File

modules/file/tests/file.test, line 233
Tests for file.module.

Class

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

Code

function createTemporaryFile($data, $uid = NULL) {
  $file = file_save_data($data, NULL, NULL);
  if ($file) {
    $file->uid = isset($uid) ? $uid : $this->admin_user->uid;

    // Change the file status to be temporary.
    $file->status = NULL;
    return file_save($file);
  }
  return $file;
}