You are here

protected function ExportTest::createFile in Acquia Content Hub 8.2

Creates a Drupal file entity.

Parameters

int $uid: Id of the owner (user).

int $items_expected: Expected number of items in the queue.

array $cdf_expectations: The sets of expectation arguments for CDF object validation.

Throws

\Drupal\Core\Entity\EntityStorageException

2 calls to ExportTest::createFile()
ExportTest::testPublishing in tests/src/Kernel/ExportTest.php
Tests Acquia ContentHub content/configuration export.
ExportTest::testQueue in tests/src/Kernel/ExportTest.php
Tests Acquia ContentHub export queue.

File

tests/src/Kernel/ExportTest.php, line 1127

Class

ExportTest
Tests entity exports.

Namespace

Drupal\Tests\acquia_contenthub\Kernel

Code

protected function createFile($uid, &$items_expected, array &$cdf_expectations = []) {
  $filename = 'contenthub_export_test.txt';
  $uri = 'public://contenthub_export_test.txt';
  $filemime = 'text/plain';
  $content = $this
    ->getRandomGenerator()
    ->paragraphs(5);
  $file = File::create();
  $file
    ->setOwnerId($uid);
  $file
    ->setFilename($filename);
  $file
    ->setMimeType($filemime);
  $file
    ->setFileUri($uri);
  $file
    ->set('status', FILE_STATUS_PERMANENT);
  $file
    ->save();
  file_put_contents($file
    ->getFileUri(), $content);
  $items_expected = 1;
  $cdf_expectations = [
    [
      $filename,
      $uri,
      $filemime,
    ],
  ];
}