You are here

protected function NodeTest::getExpectedDocument in Drupal 9

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

Class

NodeTest
JSON:API integration test for the "Node" content entity type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function getExpectedDocument() {
  $author = User::load($this->entity
    ->getOwnerId());
  $base_url = Url::fromUri('base:/jsonapi/node/camelids/' . $this->entity
    ->uuid())
    ->setAbsolute();
  $self_url = clone $base_url;
  $version_identifier = 'id:' . $this->entity
    ->getRevisionId();
  $self_url = $self_url
    ->setOption('query', [
    'resourceVersion' => $version_identifier,
  ]);
  $version_query_string = '?resourceVersion=' . urlencode($version_identifier);
  return [
    'jsonapi' => [
      'meta' => [
        'links' => [
          'self' => [
            'href' => 'http://jsonapi.org/format/1.0/',
          ],
        ],
      ],
      'version' => '1.0',
    ],
    'links' => [
      'self' => [
        'href' => $base_url
          ->toString(),
      ],
    ],
    'data' => [
      'id' => $this->entity
        ->uuid(),
      'type' => 'node--camelids',
      'links' => [
        'self' => [
          'href' => $self_url
            ->toString(),
        ],
      ],
      'attributes' => [
        'created' => '1973-11-29T21:33:09+00:00',
        'changed' => (new \DateTime())
          ->setTimestamp($this->entity
          ->getChangedTime())
          ->setTimezone(new \DateTimeZone('UTC'))
          ->format(\DateTime::RFC3339),
        'default_langcode' => TRUE,
        'langcode' => 'en',
        'path' => [
          'alias' => '/llama',
          'pid' => 1,
          'langcode' => 'en',
        ],
        'promote' => TRUE,
        'revision_log' => NULL,
        'revision_timestamp' => '1973-11-29T21:33:09+00:00',
        // @todo Attempt to remove this in https://www.drupal.org/project/drupal/issues/2933518.
        'revision_translation_affected' => TRUE,
        'status' => TRUE,
        'sticky' => FALSE,
        'title' => 'Llama',
        'drupal_internal__nid' => 1,
        'drupal_internal__vid' => 1,
      ],
      'relationships' => [
        'node_type' => [
          'data' => [
            'id' => NodeType::load('camelids')
              ->uuid(),
            'meta' => [
              'drupal_internal__target_id' => 'camelids',
            ],
            'type' => 'node_type--node_type',
          ],
          'links' => [
            'related' => [
              'href' => $base_url
                ->toString() . '/node_type' . $version_query_string,
            ],
            'self' => [
              'href' => $base_url
                ->toString() . '/relationships/node_type' . $version_query_string,
            ],
          ],
        ],
        'uid' => [
          'data' => [
            'id' => $author
              ->uuid(),
            'meta' => [
              'drupal_internal__target_id' => (int) $author
                ->id(),
            ],
            'type' => 'user--user',
          ],
          'links' => [
            'related' => [
              'href' => $base_url
                ->toString() . '/uid' . $version_query_string,
            ],
            'self' => [
              'href' => $base_url
                ->toString() . '/relationships/uid' . $version_query_string,
            ],
          ],
        ],
        'revision_uid' => [
          'data' => [
            'id' => $author
              ->uuid(),
            'meta' => [
              'drupal_internal__target_id' => (int) $author
                ->id(),
            ],
            'type' => 'user--user',
          ],
          'links' => [
            'related' => [
              'href' => $base_url
                ->toString() . '/revision_uid' . $version_query_string,
            ],
            'self' => [
              'href' => $base_url
                ->toString() . '/relationships/revision_uid' . $version_query_string,
            ],
          ],
        ],
      ],
    ],
  ];
}