function MediaTest::getExpectedDocument
Same name in other branches
- 8.9.x core/modules/jsonapi/tests/src/Functional/MediaTest.php \Drupal\Tests\jsonapi\Functional\MediaTest::getExpectedDocument()
- 10 core/modules/jsonapi/tests/src/Functional/MediaTest.php \Drupal\Tests\jsonapi\Functional\MediaTest::getExpectedDocument()
- 11.x core/modules/jsonapi/tests/src/Functional/MediaTest.php \Drupal\Tests\jsonapi\Functional\MediaTest::getExpectedDocument()
Overrides ResourceTestBase::getExpectedDocument
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,
'drupal_internal__target_id' => (int) $file->id(),
],
'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' => '',
'drupal_internal__target_id' => (int) $thumbnail->id(),
'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(),
'meta' => [
'drupal_internal__target_id' => 'camelids',
],
'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',
'meta' => [
'drupal_internal__target_id' => (int) $author->id(),
],
],
'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(),
'meta' => [
'drupal_internal__target_id' => (int) $author->id(),
],
'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,
],
],
],
],
],
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.