function WorkspaceTest::getExpectedDocument

Same name and namespace in other branches
  1. 11.x core/modules/jsonapi/tests/src/Functional/WorkspaceTest.php \Drupal\Tests\jsonapi\Functional\WorkspaceTest::getExpectedDocument()

Returns the expected JSON:API document for the entity.

Return value

array A JSON:API response document.

Overrides ResourceTestBase::getExpectedDocument

File

core/modules/jsonapi/tests/src/Functional/WorkspaceTest.php, line 115

Class

WorkspaceTest
JSON:API integration test for the "Workspace" content entity type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function getExpectedDocument() : array {
  $author = User::load($this->entity
    ->getOwnerId());
  $base_url = Url::fromUri('base:/jsonapi/workspace/workspace/' . $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' => static::$resourceTypeName,
      '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),
        'label' => 'Campaign',
        'drupal_internal__id' => 'campaign',
        'drupal_internal__revision_id' => 2,
      ],
      'relationships' => [
        'parent' => [
          'data' => NULL,
          'links' => [
            'related' => [
              'href' => $base_url->toString() . '/parent' . $version_query_string,
            ],
            'self' => [
              'href' => $base_url->toString() . '/relationships/parent' . $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,
            ],
          ],
        ],
      ],
    ],
  ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.