function FileFieldTestCase::createTemporaryFile

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 drupal/modules/file/tests/file.test
Helper for testing exploiting the temporary file removal using fid.

File

drupal/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;
}