You are here

public function FileFieldWidgetTest::getTestFile in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/file/tests/src/FunctionalJavascript/FileFieldWidgetTest.php \Drupal\Tests\file\FunctionalJavascript\FileFieldWidgetTest::getTestFile()
  2. 10 core/modules/file/tests/src/FunctionalJavascript/FileFieldWidgetTest.php \Drupal\Tests\file\FunctionalJavascript\FileFieldWidgetTest::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/FunctionalJavascript/FileFieldWidgetTest.php, line 222

Class

FileFieldWidgetTest
Tests the file field widget, single and multi-valued, using AJAX upload.

Namespace

Drupal\Tests\file\FunctionalJavascript

Code

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

  // Get a file to upload.
  $file = current($this
    ->getTestFiles($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);
}