You are here

protected function CommentTest::getExpectedDocument in Drupal 9

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

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' => (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->commented_entity
              ->uuid(),
            'meta' => [
              'drupal_internal__target_id' => (int) $this->commented_entity
                ->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',
            ],
          ],
        ],
      ],
    ],
  ];
}