function CommentTest::getExpectedDocument

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/CommentTest.php \Drupal\Tests\jsonapi\Functional\CommentTest::getExpectedDocument()
  2. 8.9.x core/modules/jsonapi/tests/src/Functional/CommentTest.php \Drupal\Tests\jsonapi\Functional\CommentTest::getExpectedDocument()
  3. 10 core/modules/jsonapi/tests/src/Functional/CommentTest.php \Drupal\Tests\jsonapi\Functional\CommentTest::getExpectedDocument()

Overrides ResourceTestBase::getExpectedDocument

File

core/modules/jsonapi/tests/src/Functional/CommentTest.php, line 146

Class

CommentTest
JSON:API integration test for the "Comment" content entity type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function getExpectedDocument() : array {
    $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 &quot;llama&quot; 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' => (int) $this->entity
                    ->id(),
            ],
            'relationships' => [
                'uid' => [
                    'data' => [
                        'id' => $author->uuid(),
                        'meta' => [
                            'drupal_internal__target_id' => (int) $author->id(),
                        ],
                        'type' => 'user--user',
                    ],
                    'links' => [
                        'related' => [
                            'href' => $self_url . '/uid',
                        ],
                        'self' => [
                            'href' => $self_url . '/relationships/uid',
                        ],
                    ],
                ],
                'comment_type' => [
                    'data' => [
                        'id' => CommentType::load('comment')->uuid(),
                        'meta' => [
                            'drupal_internal__target_id' => 'comment',
                        ],
                        'type' => 'comment_type--comment_type',
                    ],
                    'links' => [
                        'related' => [
                            'href' => $self_url . '/comment_type',
                        ],
                        'self' => [
                            'href' => $self_url . '/relationships/comment_type',
                        ],
                    ],
                ],
                'entity_id' => [
                    'data' => [
                        'id' => $this->commentedEntity
                            ->uuid(),
                        'meta' => [
                            'drupal_internal__target_id' => (int) $this->commentedEntity
                                ->id(),
                        ],
                        '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',
                        ],
                    ],
                ],
            ],
        ],
    ];
}

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