protected function MediaTest::getExpectedDocument in Drupal 8
Same name and namespace in other branches
- 9 core/modules/jsonapi/tests/src/Functional/MediaTest.php \Drupal\Tests\jsonapi\Functional\MediaTest::getExpectedDocument()
Returns the expected JSON:API document for the entity.
Return value
array A JSON:API response document.
Overrides ResourceTestBase::getExpectedDocument
See also
::createEntity()
File
- core/
modules/ jsonapi/ tests/ src/ Functional/ MediaTest.php, line 153
Class
- MediaTest
- JSON:API integration test for the "Media" content entity type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
protected function getExpectedDocument() {
$file = File::load(1);
$thumbnail = File::load(3);
$author = User::load($this->entity
->getOwnerId());
$base_url = Url::fromUri('base:/jsonapi/media/camelids/' . $this->entity
->uuid())
->setAbsolute();
$self_url = clone $base_url;
$version_identifier = 'id:' . $this->entity
->getRevisionId();
$self_url = $self_url
->setOption('query', [
'resourceVersion' => $version_identifier,
]);
$version_query_string = '?resourceVersion=' . urlencode($version_identifier);
return [
'jsonapi' => [
'meta' => [
'links' => [
'self' => [
'href' => 'http://jsonapi.org/format/1.0/',
],
],
],
'version' => '1.0',
],
'links' => [
'self' => [
'href' => $base_url
->toString(),
],
],
'data' => [
'id' => $this->entity
->uuid(),
'type' => 'media--camelids',
'links' => [
'self' => [
'href' => $self_url
->toString(),
],
],
'attributes' => [
'langcode' => 'en',
'name' => 'Llama',
'status' => TRUE,
'created' => '1973-11-29T21:33:09+00:00',
'changed' => (new \DateTime())
->setTimestamp($this->entity
->getChangedTime())
->setTimezone(new \DateTimeZone('UTC'))
->format(\DateTime::RFC3339),
'revision_created' => (new \DateTime())
->setTimestamp($this->entity
->getRevisionCreationTime())
->setTimezone(new \DateTimeZone('UTC'))
->format(\DateTime::RFC3339),
'default_langcode' => TRUE,
'revision_log_message' => NULL,
// @todo Attempt to remove this in https://www.drupal.org/project/drupal/issues/2933518.
'revision_translation_affected' => TRUE,
'drupal_internal__mid' => 1,
'drupal_internal__vid' => 1,
],
'relationships' => [
'field_media_file' => [
'data' => [
'id' => $file
->uuid(),
'meta' => [
'description' => NULL,
'display' => NULL,
],
'type' => 'file--file',
],
'links' => [
'related' => [
'href' => $base_url
->toString() . '/field_media_file' . $version_query_string,
],
'self' => [
'href' => $base_url
->toString() . '/relationships/field_media_file' . $version_query_string,
],
],
],
'thumbnail' => [
'data' => [
'id' => $thumbnail
->uuid(),
'meta' => [
'alt' => '',
'width' => 180,
'height' => 180,
'title' => NULL,
],
'type' => 'file--file',
],
'links' => [
'related' => [
'href' => $base_url
->toString() . '/thumbnail' . $version_query_string,
],
'self' => [
'href' => $base_url
->toString() . '/relationships/thumbnail' . $version_query_string,
],
],
],
'bundle' => [
'data' => [
'id' => MediaType::load('camelids')
->uuid(),
'type' => 'media_type--media_type',
],
'links' => [
'related' => [
'href' => $base_url
->toString() . '/bundle' . $version_query_string,
],
'self' => [
'href' => $base_url
->toString() . '/relationships/bundle' . $version_query_string,
],
],
],
'uid' => [
'data' => [
'id' => $author
->uuid(),
'type' => 'user--user',
],
'links' => [
'related' => [
'href' => $base_url
->toString() . '/uid' . $version_query_string,
],
'self' => [
'href' => $base_url
->toString() . '/relationships/uid' . $version_query_string,
],
],
],
'revision_user' => [
'data' => [
'id' => $author
->uuid(),
'type' => 'user--user',
],
'links' => [
'related' => [
'href' => $base_url
->toString() . '/revision_user' . $version_query_string,
],
'self' => [
'href' => $base_url
->toString() . '/relationships/revision_user' . $version_query_string,
],
],
],
],
],
];
}