function MediaResourceTestBase::getExpectedNormalizedFileEntity

Same name in other branches
  1. 9 core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php \Drupal\Tests\media\Functional\Rest\MediaResourceTestBase::getExpectedNormalizedFileEntity()
  2. 8.9.x core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php \Drupal\Tests\media\Functional\Rest\MediaResourceTestBase::getExpectedNormalizedFileEntity()
  3. 11.x 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
Tests the 'file_upload' REST resource plugin.

File

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

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,
            ],
        ],
    ];
}

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