You are here

protected function JwtPathAuthTest::createPrivateFile in JSON Web Token Authentication (JWT) 8

Creates a private file.

Parameters

string $file_name: The file name.

int $uid: The file owning user ID.

int $status: The file status.

Return value

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

Throws

\Drupal\Core\Entity\EntityStorageException

1 call to JwtPathAuthTest::createPrivateFile()
JwtPathAuthTest::testPathAdmin in tests/src/Functional/JwtPathAuthTest.php
Test admin form updates and actual path auth.

File

tests/src/Functional/JwtPathAuthTest.php, line 215

Class

JwtPathAuthTest
Tests path-based authentication.

Namespace

Drupal\Tests\jwt\Functional

Code

protected function createPrivateFile($file_name, $uid = 1, $status = FILE_STATUS_PERMANENT) {

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