You are here

protected function EmbedTestBase::getTestFile in Embed 8

Retrieves a sample file of the specified type.

Parameters

string $type: File type, possible values: 'binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'.

int $size: (optional) File size in bytes to match. Defaults to NULL, which will not filter the returned list by size.

Return value

\Drupal\file\FileInterface The file entity.

See also

\Drupal\Tests\TestFileCreationTrait::getTestFiles()

File

tests/src/Functional/EmbedTestBase.php, line 108

Class

EmbedTestBase
Base class for all embed tests.

Namespace

Drupal\Tests\embed\Functional

Code

protected function getTestFile($type, $size = NULL) {

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

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