You are here

protected function FileListingTest::createFile in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/file/tests/src/Functional/FileListingTest.php \Drupal\Tests\file\Functional\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/tests/src/Functional/FileListingTest.php
Tests file overview with different user permissions.

File

core/modules/file/tests/src/Functional/FileListingTest.php, line 221

Class

FileListingTest
Tests file listing page functionality.

Namespace

Drupal\Tests\file\Functional

Code

protected function createFile() {

  // Create a new file entity.
  $file = File::create([
    'uid' => 1,
    'filename' => 'druplicon.txt',
    'uri' => 'public://druplicon.txt',
    'filemime' => 'text/plain',
    'created' => 1,
    'changed' => 1,
  ]);
  $file
    ->setPermanent();
  file_put_contents($file
    ->getFileUri(), 'hello world');

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