You are here

protected function EntityShareClientFunctionalTestBase::preparePhysicalFilesAndFileEntitiesData in Entity Share 8.2

Same name and namespace in other branches
  1. 8.3 modules/entity_share_client/tests/src/Functional/EntityShareClientFunctionalTestBase.php \Drupal\Tests\entity_share_client\Functional\EntityShareClientFunctionalTestBase::preparePhysicalFilesAndFileEntitiesData()

Helper function.

Return value

array An array of data.

3 calls to EntityShareClientFunctionalTestBase::preparePhysicalFilesAndFileEntitiesData()
FileDeletedTest::getEntitiesDataArray in modules/entity_share_client/tests/src/Functional/FileDeletedTest.php
Helper function to get a mapping of the entities data.
FileTest::getEntitiesDataArray in modules/entity_share_client/tests/src/Functional/FileTest.php
Helper function to get a mapping of the entities data.
MediaEntityReferenceTest::getEntitiesDataArray in modules/entity_share_client/tests/src/Functional/MediaEntityReferenceTest.php
Helper function to get a mapping of the entities data.

File

modules/entity_share_client/tests/src/Functional/EntityShareClientFunctionalTestBase.php, line 808

Class

EntityShareClientFunctionalTestBase
Base class for Entity share server functional tests.

Namespace

Drupal\Tests\entity_share_client\Functional

Code

protected function preparePhysicalFilesAndFileEntitiesData() {

  /** @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager */
  $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager');

  /** @var \Drupal\Core\File\FileSystemInterface $file_system */
  $file_system = \Drupal::service('file_system');
  $files_entities_data = [];
  foreach (static::$filesData as $file_uuid => $file_data) {
    $stream_wrapper = $stream_wrapper_manager
      ->getViaUri($file_data['uri']);
    $directory_uri = $stream_wrapper
      ->dirname($file_data['uri']);
    $file_system
      ->prepareDirectory($directory_uri, FileSystemInterface::CREATE_DIRECTORY);
    if (isset($file_data['file_content'])) {
      file_put_contents($file_data['uri'], $file_data['file_content']);
      $this->filesSize[$file_uuid] = filesize($file_data['uri']);
    }
    elseif (isset($file_data['file_content_callback'])) {
      $this
        ->{$file_data['file_content_callback']}($file_uuid, $file_data);
    }
    $files_entities_data[$file_uuid] = [
      'filename' => [
        'value' => $file_data['filename'],
        'checker_callback' => 'getValue',
      ],
      'uri' => [
        'value' => $file_data['uri'],
        'checker_callback' => 'getValue',
      ],
      'filemime' => [
        'value' => $file_data['filemime'],
        'checker_callback' => 'getValue',
      ],
      'status' => [
        'value' => FILE_STATUS_PERMANENT,
        'checker_callback' => 'getValue',
      ],
    ];
  }
  return $files_entities_data;
}