function FileUploadResourceTestBase::getExpectedNormalizedEntity

Same name and namespace in other branches
  1. 9 core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::getExpectedNormalizedEntity()
  2. 8.9.x core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::getExpectedNormalizedEntity()
  3. 11.x core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::getExpectedNormalizedEntity()

Gets the expected file entity.

Parameters

int $fid: The file ID to load and create normalized data for.

string $expected_filename: The expected filename for the stored file.

bool $expected_as_filename: Whether the expected filename should be the filename property too.

Return value

array The expected normalized data array.

7 calls to FileUploadResourceTestBase::getExpectedNormalizedEntity()
FileUploadResourceTestBase::testFileUploadMaliciousExtension in core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php
Tests using the file upload POST route with malicious extensions.
FileUploadResourceTestBase::testFileUploadNoExtensionSetting in core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php
Tests using the file upload POST route no extension configured.
FileUploadResourceTestBase::testFileUploadStrippedFilePath in core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php
Tests using the file upload route with any path prefixes being stripped.
FileUploadResourceTestBase::testFileUploadUnicodeFilename in core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php
Tests using the file upload route with a unicode file name.
FileUploadResourceTestBase::testFileUploadZeroByteFile in core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php
Tests using the file upload route with a zero byte file.

... See full list

File

core/modules/rest/tests/src/Functional/FileUploadResourceTestBase.php, line 684

Class

FileUploadResourceTestBase
Tests binary data file upload route.

Namespace

Drupal\Tests\rest\Functional

Code

protected function getExpectedNormalizedEntity($fid = 1, $expected_filename = 'example.txt', $expected_as_filename = FALSE) {
  $author = User::load(static::$auth ? $this->account
    ->id() : 0);
  $file = File::load($fid);
  $this->assertInstanceOf(FileInterface::class, $file);
  $expected_normalization = [
    'fid' => [
      [
        'value' => (int) $file->id(),
      ],
    ],
    'uuid' => [
      [
        'value' => $file->uuid(),
      ],
    ],
    'langcode' => [
      [
        'value' => 'en',
      ],
    ],
    'uid' => [
      [
        'target_id' => (int) $author->id(),
        'target_type' => 'user',
        'target_uuid' => $author->uuid(),
        'url' => base_path() . 'user/' . $author->id(),
      ],
    ],
    'filename' => [
      [
        'value' => $expected_as_filename ? $expected_filename : 'example.txt',
      ],
    ],
    'uri' => [
      [
        'value' => 'public://foobar/' . $expected_filename,
        'url' => base_path() . $this->siteDirectory . '/files/foobar/' . rawurlencode($expected_filename),
      ],
    ],
    'filemime' => [
      [
        'value' => 'text/plain',
      ],
    ],
    'filesize' => [
      [
        'value' => strlen($this->testFileData),
      ],
    ],
    'status' => [
      [
        'value' => FALSE,
      ],
    ],
    'created' => [
      [
        'value' => (new \DateTime())->setTimestamp($file->getCreatedTime())
          ->setTimezone(new \DateTimeZone('UTC'))
          ->format(\DateTime::RFC3339),
        'format' => \DateTime::RFC3339,
      ],
    ],
    'changed' => [
      [
        'value' => (new \DateTime())->setTimestamp($file->getChangedTime())
          ->setTimezone(new \DateTimeZone('UTC'))
          ->format(\DateTime::RFC3339),
        'format' => \DateTime::RFC3339,
      ],
    ],
  ];
  return $expected_normalization;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.