You are here

protected function FileListingTest::createFile in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Tests/FileListingTest.php \Drupal\file\Tests\FileListingTest::createFile()

Creates and saves a test file.

Return value

\Drupal\Core\Entity\EntityInterface A file entity.

1 call to FileListingTest::createFile()
FileListingTest::testFileListingPages in core/modules/file/src/Tests/FileListingTest.php
Tests file overview with different user permissions.

File

core/modules/file/src/Tests/FileListingTest.php, line 158
Contains \Drupal\file\Tests\FileListingTest.

Class

FileListingTest
Tests file listing page functionality.

Namespace

Drupal\file\Tests

Code

protected function createFile() {

  // Create a new file entity.
  $file = entity_create('file', array(
    'uid' => 1,
    'filename' => 'druplicon.txt',
    'uri' => 'public://druplicon.txt',
    'filemime' => 'text/plain',
    'created' => 1,
    'changed' => 1,
    'status' => FILE_STATUS_PERMANENT,
  ));
  file_put_contents($file
    ->getFileUri(), 'hello world');

  // Save it, inserting a new record.
  $file
    ->save();
  return $file;
}