You are here

protected function InlineBlockPrivateFilesTest::createPrivateFile in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockPrivateFilesTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\InlineBlockPrivateFilesTest::createPrivateFile()

Creates a private file.

Parameters

string $file_name: The file name.

Return value

\Drupal\Core\Entity\EntityInterface|\Drupal\file\Entity\File The file entity.

1 call to InlineBlockPrivateFilesTest::createPrivateFile()
InlineBlockPrivateFilesTest::testPrivateFiles in core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockPrivateFilesTest.php
Test access to private files added via inline blocks in the layout builder.

File

core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockPrivateFilesTest.php, line 224

Class

InlineBlockPrivateFilesTest
Test access to private files in block fields on the Layout Builder.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

protected function createPrivateFile($file_name) {

  // Create a new file entity.
  $file = File::create([
    'uid' => 1,
    'filename' => $file_name,
    'uri' => "private://{$file_name}",
    'filemime' => 'text/plain',
    'status' => FILE_STATUS_PERMANENT,
  ]);
  file_put_contents($file
    ->getFileUri(), $this
    ->getFileSecret($file));
  $file
    ->save();
  return $file;
}