You are here

protected function CommentTest::getExpectedDocument in JSON:API 8.2

Same name and namespace in other branches
  1. 8 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

tests/src/Functional/CommentTest.php, line 147

Class

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

Namespace

Drupal\Tests\jsonapi\Functional

Code

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 &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' => 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',
            ],
          ],
        ],
      ],
    ],
  ];
}