You are here

protected function EntityTestTest::getExpectedDocument in JSON:API 8.2

Same name and namespace in other branches
  1. 8 tests/src/Functional/EntityTestTest.php \Drupal\Tests\jsonapi\Functional\EntityTestTest::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/EntityTestTest.php, line 99

Class

EntityTestTest
JSON:API integration test for the "EntityTest" content entity type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function getExpectedDocument() {
  $self_url = Url::fromUri('base:/jsonapi/entity_test/entity_test/' . $this->entity
    ->uuid())
    ->setAbsolute()
    ->toString(TRUE)
    ->getGeneratedUrl();
  $author = User::load(0);
  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' => 'entity_test--entity_test',
      'links' => [
        'self' => [
          'href' => $self_url,
        ],
      ],
      'attributes' => [
        'created' => (new \DateTime())
          ->setTimestamp($this->entity
          ->get('created')->value)
          ->setTimezone(new \DateTimeZone('UTC'))
          ->format(\DateTime::RFC3339),
        'field_test_text' => NULL,
        'langcode' => 'en',
        'name' => 'Llama',
        'entity_test_type' => 'entity_test',
        'drupal_internal__id' => 1,
      ],
      'relationships' => [
        'user_id' => [
          'data' => [
            'id' => $author
              ->uuid(),
            'type' => 'user--user',
          ],
          'links' => [
            'related' => [
              'href' => $self_url . '/user_id',
            ],
            'self' => [
              'href' => $self_url . '/relationships/user_id',
            ],
          ],
        ],
      ],
    ],
  ];
}