You are here

protected function MediaHalJsonAnonTest::getExpectedNormalizedFileEntity in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media/tests/src/Functional/Hal/MediaHalJsonAnonTest.php \Drupal\Tests\media\Functional\Hal\MediaHalJsonAnonTest::getExpectedNormalizedFileEntity()

Gets the expected file entity.

Return value

array The expected normalized data array.

Overrides MediaResourceTestBase::getExpectedNormalizedFileEntity

File

core/modules/media/tests/src/Functional/Hal/MediaHalJsonAnonTest.php, line 161

Class

MediaHalJsonAnonTest
@group hal

Namespace

Drupal\Tests\media\Functional\Hal

Code

protected function getExpectedNormalizedFileEntity() {
  $normalization = parent::getExpectedNormalizedFileEntity();
  $owner = static::$auth ? $this->account : User::load(0);

  // Cannot use applyHalFieldNormalization() as it uses the $entity property
  // from the test class, which in the case of file upload tests, is the
  // parent entity test entity for the file that's created.
  // The HAL normalization adds entity reference fields to '_links' and
  // '_embedded'.
  unset($normalization['uid']);
  return $normalization + [
    '_links' => [
      'self' => [
        // @todo This can use a proper link once
        // https://www.drupal.org/project/drupal/issues/2907402 is complete.
        // This link matches what is generated from File::url(), a resource
        // URL is currently not available.
        'href' => \Drupal::service('file_url_generator')
          ->generateAbsoluteString($normalization['uri'][0]['value']),
      ],
      'type' => [
        'href' => $this->baseUrl . '/rest/type/file/file',
      ],
      $this->baseUrl . '/rest/relation/file/file/uid' => [
        [
          'href' => $this->baseUrl . '/user/' . $owner
            ->id() . '?_format=hal_json',
        ],
      ],
    ],
    '_embedded' => [
      $this->baseUrl . '/rest/relation/file/file/uid' => [
        [
          '_links' => [
            'self' => [
              'href' => $this->baseUrl . '/user/' . $owner
                ->id() . '?_format=hal_json',
            ],
            'type' => [
              'href' => $this->baseUrl . '/rest/type/user/user',
            ],
          ],
          'uuid' => [
            [
              'value' => $owner
                ->uuid(),
            ],
          ],
        ],
      ],
    ],
  ];
}