You are here

protected function MinisiteTestBase::convertToFileEntity in Mini site 8

Convert file provided by absolute path to file entity.

Parameters

string $absolute_file_path: Absolute path to file.

Return value

\Drupal\file\Entity\File The File entity object.

2 calls to MinisiteTestBase::convertToFileEntity()
MinisiteTestBase::getTestArchiveInvalidFormat in tests/src/Functional/MinisiteTestBase.php
Shorthand to get an invalid archive file.
MinisiteTestBase::getTestArchiveValid in tests/src/Functional/MinisiteTestBase.php
Shorthand to get a valid archive file.

File

tests/src/Functional/MinisiteTestBase.php, line 275

Class

MinisiteTestBase
Provides methods specifically for testing Minisite module's field handling.

Namespace

Drupal\Tests\minisite\Functional

Code

protected function convertToFileEntity($absolute_file_path) {
  $archive_file = basename($absolute_file_path);
  $file = new \stdClass();
  $file->uri = $absolute_file_path;
  $file->filename = $archive_file;
  $file->name = pathinfo($archive_file, PATHINFO_FILENAME);

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