function MediaResourceTestBase::getExpectedNormalizedEntity

Same name in other branches
  1. 9 core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php \Drupal\Tests\media\Functional\Rest\MediaResourceTestBase::getExpectedNormalizedEntity()
  2. 8.9.x core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php \Drupal\Tests\media\Functional\Rest\MediaResourceTestBase::getExpectedNormalizedEntity()
  3. 11.x core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php \Drupal\Tests\media\Functional\Rest\MediaResourceTestBase::getExpectedNormalizedEntity()

Overrides EntityResourceTestBase::getExpectedNormalizedEntity

File

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

Class

MediaResourceTestBase

Namespace

Drupal\Tests\media\Functional\Rest

Code

protected function getExpectedNormalizedEntity() {
    $file = File::load(1);
    $thumbnail = File::load(2);
    $author = User::load($this->entity
        ->getOwnerId());
    return [
        'mid' => [
            [
                'value' => 1,
            ],
        ],
        'uuid' => [
            [
                'value' => $this->entity
                    ->uuid(),
            ],
        ],
        'vid' => [
            [
                'value' => 1,
            ],
        ],
        'langcode' => [
            [
                'value' => 'en',
            ],
        ],
        'bundle' => [
            [
                'target_id' => 'camelids',
                'target_type' => 'media_type',
                'target_uuid' => MediaType::load('camelids')->uuid(),
            ],
        ],
        'name' => [
            [
                'value' => 'Llama',
            ],
        ],
        'field_media_file' => [
            [
                'description' => NULL,
                'display' => NULL,
                'target_id' => (int) $file->id(),
                'target_type' => 'file',
                'target_uuid' => $file->uuid(),
                'url' => $file->createFileUrl(FALSE),
            ],
        ],
        'thumbnail' => [
            [
                'alt' => '',
                'width' => 180,
                'height' => 180,
                'target_id' => (int) $thumbnail->id(),
                'target_type' => 'file',
                'target_uuid' => $thumbnail->uuid(),
                'title' => NULL,
                'url' => $thumbnail->createFileUrl(FALSE),
            ],
        ],
        'status' => [
            [
                'value' => TRUE,
            ],
        ],
        'created' => [
            [
                'value' => (new \DateTime())->setTimestamp(123456789)
                    ->setTimezone(new \DateTimeZone('UTC'))
                    ->format(\DateTime::RFC3339),
                'format' => \DateTime::RFC3339,
            ],
        ],
        'changed' => [
            [
                'value' => (new \DateTime())->setTimestamp((int) $this->entity
                    ->getChangedTime())
                    ->setTimezone(new \DateTimeZone('UTC'))
                    ->format(\DateTime::RFC3339),
                'format' => \DateTime::RFC3339,
            ],
        ],
        'revision_created' => [
            [
                'value' => (new \DateTime())->setTimestamp((int) $this->entity
                    ->getRevisionCreationTime())
                    ->setTimezone(new \DateTimeZone('UTC'))
                    ->format(\DateTime::RFC3339),
                'format' => \DateTime::RFC3339,
            ],
        ],
        'default_langcode' => [
            [
                'value' => TRUE,
            ],
        ],
        'uid' => [
            [
                'target_id' => (int) $author->id(),
                'target_type' => 'user',
                'target_uuid' => $author->uuid(),
                'url' => base_path() . 'user/' . $author->id(),
            ],
        ],
        'revision_user' => [
            [
                'target_id' => (int) $author->id(),
                'target_type' => 'user',
                'target_uuid' => $author->uuid(),
                'url' => base_path() . 'user/' . $author->id(),
            ],
        ],
        'revision_translation_affected' => [
            [
                'value' => TRUE,
            ],
        ],
    ];
}

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