function FileManagedTestBase::createFile

Create a file and save it to the files table and assert that it occurs correctly.

Parameters

$filepath: Optional string specifying the file path. If none is provided then a randomly named file will be created in the site's files directory.

$contents: Optional contents to save into the file. If a NULL value is provided an arbitrary string will be used.

$scheme: Optional string indicating the stream scheme to use. Drupal core includes public, private, and temporary. The public wrapper is the default.

Return value

File object.

23 calls to FileManagedTestBase::createFile()
CopyTest::testExistingError in drupal/core/modules/file/lib/Drupal/file/Tests/CopyTest.php
Test that copying over an existing file fails when FILE_EXISTS_ERROR is specified.
CopyTest::testExistingRename in drupal/core/modules/file/lib/Drupal/file/Tests/CopyTest.php
Test renaming when copying over a file that already exists.
CopyTest::testExistingReplace in drupal/core/modules/file/lib/Drupal/file/Tests/CopyTest.php
Test replacement when copying over a file that already exists.
CopyTest::testNormal in drupal/core/modules/file/lib/Drupal/file/Tests/CopyTest.php
Test file copying in the normal, base case.
DeleteTest::testInUse in drupal/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php
Tries deleting a file that is in use.

... See full list

File

drupal/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php, line 106
Definition of Drupal\file\Tests\FileManagedTestBase.

Class

FileManagedTestBase
Base class for file tests that use the file_test module to test uploads and hooks.

Namespace

Drupal\file\Tests

Code

function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) {
  $file = new stdClass();
  $file->uri = $this
    ->createUri($filepath, $contents, $scheme);
  $file->filename = drupal_basename($file->uri);
  $file->filemime = 'text/plain';
  $file->uid = 1;
  $file->timestamp = REQUEST_TIME;
  $file->filesize = filesize($file->uri);
  $file->status = 0;

  // Write the record directly rather than using the API so we don't invoke
  // the hooks.
  $this
    ->assertNotIdentical(drupal_write_record('file_managed', $file), FALSE, t('The file was added to the database.'), 'Create test file');
  return entity_create('file', (array) $file);
}