function FileListingTest::createFile

Same name in other branches
  1. 9 core/modules/file/tests/src/Functional/FileListingTest.php \Drupal\Tests\file\Functional\FileListingTest::createFile()
  2. 8.9.x core/modules/file/tests/src/Functional/FileListingTest.php \Drupal\Tests\file\Functional\FileListingTest::createFile()
  3. 11.x 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 264

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.