protected function CommentTest::getExpectedDocument in Drupal 8
Same name and namespace in other branches
- 9 core/modules/jsonapi/tests/src/Functional/CommentTest.php \Drupal\Tests\jsonapi\Functional\CommentTest::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/ CommentTest.php, line 138
Class
- CommentTest
- JSON:API integration test for the "Comment" content entity type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
protected function getExpectedDocument() {
$self_url = Url::fromUri('base:/jsonapi/comment/comment/' . $this->entity
->uuid())
->setAbsolute()
->toString(TRUE)
->getGeneratedUrl();
$author = User::load($this->entity
->getOwnerId());
return [
'jsonapi' => [
'meta' => [
'links' => [
'self' => [
'href' => 'http://jsonapi.org/format/1.0/',
],
],
],
'version' => '1.0',
],
'links' => [
'self' => [
'href' => $self_url,
],
],
'data' => [
'id' => $this->entity
->uuid(),
'type' => 'comment--comment',
'links' => [
'self' => [
'href' => $self_url,
],
],
'attributes' => [
'created' => '1973-11-29T21:33:09+00:00',
'changed' => (new \DateTime())
->setTimestamp($this->entity
->getChangedTime())
->setTimezone(new \DateTimeZone('UTC'))
->format(\DateTime::RFC3339),
'comment_body' => [
'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
'format' => 'plain_text',
'processed' => "<p>The name "llama" was adopted by European settlers from native Peruvians.</p>\n",
],
'default_langcode' => TRUE,
'entity_type' => 'entity_test',
'field_name' => 'comment',
'homepage' => NULL,
'langcode' => 'en',
'name' => NULL,
'status' => TRUE,
'subject' => 'Llama',
'thread' => '01/',
'drupal_internal__cid' => 1,
],
'relationships' => [
'uid' => [
'data' => [
'id' => $author
->uuid(),
'type' => 'user--user',
],
'links' => [
'related' => [
'href' => $self_url . '/uid',
],
'self' => [
'href' => $self_url . '/relationships/uid',
],
],
],
'comment_type' => [
'data' => [
'id' => CommentType::load('comment')
->uuid(),
'type' => 'comment_type--comment_type',
],
'links' => [
'related' => [
'href' => $self_url . '/comment_type',
],
'self' => [
'href' => $self_url . '/relationships/comment_type',
],
],
],
'entity_id' => [
'data' => [
'id' => EntityTest::load(1)
->uuid(),
'type' => 'entity_test--bar',
],
'links' => [
'related' => [
'href' => $self_url . '/entity_id',
],
'self' => [
'href' => $self_url . '/relationships/entity_id',
],
],
],
'pid' => [
'data' => NULL,
'links' => [
'related' => [
'href' => $self_url . '/pid',
],
'self' => [
'href' => $self_url . '/relationships/pid',
],
],
],
],
],
];
}