You are here

function FileEntityTestBase::getFileByFilename in File Entity (fieldable files) 8.2

Get a file from the database based on its filename.

Parameters

$filename: A file filename, usually generated by $this->randomMachineName().

$reset: (optional) Whether to reset the internal file_load() cache.

Return value

\Drupal\file\FileInterface A file object matching $filename.

7 calls to FileEntityTestBase::getFileByFilename()
FileEntityCreationTest::testFileEntityCreationMultipleSteps in tests/src/Functional/FileEntityCreationTest.php
Upload a file with both private and public folder set.
FileEntityCreationTest::testImageAltTitleFields in tests/src/Functional/FileEntityCreationTest.php
Test the Title Text and Alt Text fields of to the predefined Image type.
FileEntityCreationTest::testSingleFileEntityCreation in tests/src/Functional/FileEntityCreationTest.php
Create a "document" file and verify its consistency in the database.
FileEntityEditTest::testFileEntityAssociatedUser in tests/src/Functional/FileEntityEditTest.php
Check changing file associated user fields.
FileEntityEditTest::testFileEntityEdit in tests/src/Functional/FileEntityEditTest.php
Check file edit functionality.

... See full list

File

tests/src/Functional/FileEntityTestBase.php, line 165

Class

FileEntityTestBase
Base class for file entity tests.

Namespace

Drupal\Tests\file_entity\Functional

Code

function getFileByFilename($filename, $reset = FALSE) {
  $files = \Drupal::entityTypeManager()
    ->getStorage('file')
    ->loadByProperties([
    'filename' => $filename,
  ], $reset);

  // Load the first file returned from the database.
  $returned_file = reset($files);
  return $returned_file;
}