You are here

protected function S3FileTestTrait::createFileEntity in Acquia Content Hub 8.2

Saves and returns a file entity based on the file name and scheme.

Optionally override every values by using the $values parameter.

Parameters

string $file_name: The file name. Used to generate uri.

string $scheme: The applicable scheme.

array $values: Values to override file entity fields.

Return value

\Drupal\file\FileInterface The newly created file entity.

Throws

\Drupal\Core\Entity\EntityStorageException

7 calls to S3FileTestTrait::createFileEntity()
S3FileEntityHandlerTest::testOnParseCdf in modules/acquia_contenthub_s3/tests/src/Kernel/S3FileEntityHandlerTest.php
@covers ::onParseCdf
S3FileMapperTest::testMapS3File in modules/acquia_contenthub_s3/tests/src/Kernel/S3FileMapperTest.php
@covers ::mapS3File
S3FileMapperTest::testMapS3FileNoBucket in modules/acquia_contenthub_s3/tests/src/Kernel/S3FileMapperTest.php
@covers ::mapS3File @dataProvider mapS3FileDataProvider
S3FileMapTest::testGetFileByUri in modules/acquia_contenthub_s3/tests/src/Kernel/S3FileMapTest.php
@covers ::getFileByUri
S3FileOriginLocatorTest::initFileFixture in modules/acquia_contenthub_s3/tests/src/Kernel/S3FileOriginLocatorTest.php
Initializes a file and inserts it into s3 file map table.

... See full list

File

modules/acquia_contenthub_s3/tests/src/Kernel/S3FileTestTrait.php, line 48

Class

S3FileTestTrait
Provides common methods for s3 related tests.

Namespace

Drupal\Tests\acquia_contenthub_s3\Kernel

Code

protected function createFileEntity(string $file_name, string $scheme, array $values = []) : FileInterface {
  if ($scheme === 's3') {
    $config = \Drupal::configFactory()
      ->getEditable('s3fs.settings');
    if (!$config
      ->get('bucket')) {
      $config
        ->set('bucket', 'test-bucket')
        ->save();
    }
  }
  $path = explode('/', $file_name);
  $data = [
    'uuid' => \Drupal::service('uuid')
      ->generate(),
    'langcode' => 'en',
    'uid' => 1,
    'filename' => end($path),
    'uri' => sprintf("{$scheme}://%s", implode('/', $path)),
    'filemime' => mimetype_from_extension($file_name),
    'filesize' => rand(1000, 5000),
    'status' => 1,
    'created' => time(),
  ];
  $data = array_merge($data, $values);
  $file = File::create($data);
  $file
    ->save();
  return $file;
}