You are here

public function FileFieldTestBase::getTestFile in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/file/tests/src/Functional/FileFieldTestBase.php \Drupal\Tests\file\Functional\FileFieldTestBase::getTestFile()
  2. 9 core/modules/file/tests/src/Functional/FileFieldTestBase.php \Drupal\Tests\file\Functional\FileFieldTestBase::getTestFile()

Retrieves a sample file of the specified type.

Return value

\Drupal\file\FileInterface The new unsaved file entity.

File

core/modules/file/tests/src/Functional/FileFieldTestBase.php, line 62

Class

FileFieldTestBase
Provides methods specifically for testing File module's field handling.

Namespace

Drupal\Tests\file\Functional

Code

public function getTestFile($type_name, $size = NULL) {

  // Get a file to upload.
  $file = current($this
    ->drupalGetTestFiles($type_name, $size));

  // Add a filesize property to files as would be read by
  // \Drupal\file\Entity\File::load().
  $file->filesize = filesize($file->uri);
  return File::create((array) $file);
}