You are here

protected function BlockContentTest::getExpectedDocument in JSON:API 8

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

Class

BlockContentTest
JSON API integration test for the "BlockContent" content entity type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function getExpectedDocument() {
  $self_url = Url::fromUri('base:/jsonapi/block_content/basic/' . $this->entity
    ->uuid())
    ->setAbsolute()
    ->toString(TRUE)
    ->getGeneratedUrl();
  $expected_document = [
    'jsonapi' => [
      'meta' => [
        'links' => [
          'self' => 'http://jsonapi.org/format/1.0/',
        ],
      ],
      'version' => '1.0',
    ],
    'links' => [
      'self' => $self_url,
    ],
    'data' => [
      'id' => $this->entity
        ->uuid(),
      'type' => 'block_content--basic',
      'links' => [
        'self' => $self_url,
      ],
      'attributes' => [
        'id' => 1,
        'body' => [
          'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
          'format' => 'plain_text',
          'summary' => NULL,
          'processed' => "<p>The name &quot;llama&quot; was adopted by European settlers from native Peruvians.</p>\n",
        ],
        'changed' => $this->entity
          ->getChangedTime(),
        // @todo uncomment this in https://www.drupal.org/project/jsonapi/issues/2929932

        /* 'changed' => $this->formatExpectedTimestampItemValues($this->entity->getChangedTime()), */
        'info' => 'Llama',
        'revision_id' => 1,
        'revision_log' => NULL,
        'revision_created' => (int) $this->entity
          ->getRevisionCreationTime(),
        // @todo uncomment this in https://www.drupal.org/project/jsonapi/issues/2929932

        /* 'revision_created' => $this->formatExpectedTimestampItemValues($this->entity->getRevisionCreationTime()), */

        // @todo Attempt to remove this in https://www.drupal.org/project/drupal/issues/2933518.
        'revision_translation_affected' => TRUE,
        'status' => FALSE,
        'langcode' => 'en',
        'default_langcode' => TRUE,
        'uuid' => $this->entity
          ->uuid(),
      ],
      'relationships' => [
        'type' => [
          'data' => [
            'id' => BlockContentType::load('basic')
              ->uuid(),
            'type' => 'block_content_type--block_content_type',
          ],
          'links' => [
            'related' => $self_url . '/type',
            'self' => $self_url . '/relationships/type',
          ],
        ],
        'revision_user' => [
          'data' => NULL,
          'links' => [
            'related' => $self_url . '/revision_user',
            'self' => $self_url . '/relationships/revision_user',
          ],
        ],
      ],
    ],
  ];
  if (floatval(\Drupal::VERSION) >= 8.6) {
    $expected_document['data']['attributes']['reusable'] = TRUE;
  }
  return $expected_document;
}