You are here

protected function MediaResourceTestBase::getExpectedNormalizedFileEntity in Drupal 10

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

Gets the expected file entity.

Return value

array The expected normalized data array.

1 call to MediaResourceTestBase::getExpectedNormalizedFileEntity()
MediaResourceTestBase::uploadFile in core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php
This duplicates some of the 'file_upload' REST resource plugin test coverage, to be able to test it on a concrete use case.

File

core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php, line 388

Class

MediaResourceTestBase

Namespace

Drupal\Tests\media\Functional\Rest

Code

protected function getExpectedNormalizedFileEntity() {
  $file = File::load(3);
  $owner = static::$auth ? $this->account : User::load(0);
  return [
    'fid' => [
      [
        'value' => 3,
      ],
    ],
    'uuid' => [
      [
        'value' => $file
          ->uuid(),
      ],
    ],
    'langcode' => [
      [
        'value' => 'en',
      ],
    ],
    'uid' => [
      [
        'target_id' => (int) $owner
          ->id(),
        'target_type' => 'user',
        'target_uuid' => $owner
          ->uuid(),
        'url' => base_path() . 'user/' . $owner
          ->id(),
      ],
    ],
    'filename' => [
      [
        'value' => 'drupal rocks 🤘.txt',
      ],
    ],
    'uri' => [
      [
        'value' => 'public://' . date('Y-m') . '/drupal rocks 🤘.txt',
        'url' => base_path() . $this->siteDirectory . '/files/' . date('Y-m') . '/drupal%20rocks%20%F0%9F%A4%98.txt',
      ],
    ],
    'filemime' => [
      [
        'value' => 'text/plain',
      ],
    ],
    'filesize' => [
      [
        'value' => 19,
      ],
    ],
    '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,
      ],
    ],
  ];
}