You are here

protected function EntityTestTest::getExpectedDocument in JSON:API 8

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

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);
  $normalization = [
    'jsonapi' => [
      'meta' => [
        'links' => [
          'self' => 'http://jsonapi.org/format/1.0/',
        ],
      ],
      'version' => '1.0',
    ],
    'links' => [
      'self' => $self_url,
    ],
    'data' => [
      'id' => $this->entity
        ->uuid(),
      'type' => 'entity_test--entity_test',
      'links' => [
        'self' => $self_url,
      ],
      'attributes' => [
        'id' => 1,
        'created' => (int) $this->entity
          ->get('created')->value,
        // @todo uncomment this in https://www.drupal.org/project/jsonapi/issues/2929932

        /* 'created' => $this->formatExpectedTimestampItemValues((int) $this->entity->get('created')->value), */
        'field_test_text' => NULL,
        'langcode' => 'en',
        'name' => 'Llama',
        'type' => 'entity_test',
        'uuid' => $this->entity
          ->uuid(),
      ],
      'relationships' => [
        'user_id' => [
          'data' => [
            'id' => $author
              ->uuid(),
            'type' => 'user--user',
          ],
          'links' => [
            'related' => $self_url . '/user_id',
            'self' => $self_url . '/relationships/user_id',
          ],
        ],
      ],
    ],
  ];

  // @todo Remove this modification when JSON API requires Drupal 8.5 or newer, and do an early return above instead.
  if (floatval(\Drupal::VERSION) < 8.5) {
    unset($normalization['data']['attributes']['internal_string_field']);
  }
  return $normalization;
}