You are here

protected function BlockContentTest::getExpectedDocument in JSON:API 8.2

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

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' => [
            'href' => 'http://jsonapi.org/format/1.0/',
          ],
        ],
      ],
      'version' => '1.0',
    ],
    'links' => [
      'self' => [
        'href' => $self_url,
      ],
    ],
    'data' => [
      'id' => $this->entity
        ->uuid(),
      'type' => 'block_content--basic',
      'links' => [
        'self' => [
          'href' => $self_url,
        ],
      ],
      'attributes' => [
        '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' => (new \DateTime())
          ->setTimestamp($this->entity
          ->getChangedTime())
          ->setTimezone(new \DateTimeZone('UTC'))
          ->format(\DateTime::RFC3339),
        'info' => 'Llama',
        'revision_log' => NULL,
        'revision_created' => (new \DateTime())
          ->setTimestamp($this->entity
          ->getRevisionCreationTime())
          ->setTimezone(new \DateTimeZone('UTC'))
          ->format(\DateTime::RFC3339),
        'revision_translation_affected' => TRUE,
        'status' => FALSE,
        'langcode' => 'en',
        'default_langcode' => TRUE,
        'drupal_internal__id' => 1,
        'drupal_internal__revision_id' => 1,
      ],
      'relationships' => [
        'block_content_type' => [
          'data' => [
            'id' => BlockContentType::load('basic')
              ->uuid(),
            'type' => 'block_content_type--block_content_type',
          ],
          'links' => [
            'related' => [
              'href' => $self_url . '/block_content_type',
            ],
            'self' => [
              'href' => $self_url . '/relationships/block_content_type',
            ],
          ],
        ],
        'revision_user' => [
          'data' => NULL,
          'links' => [
            'related' => [
              'href' => $self_url . '/revision_user',
            ],
            'self' => [
              'href' => $self_url . '/relationships/revision_user',
            ],
          ],
        ],
      ],
    ],
  ];
  if (floatval(\Drupal::VERSION) >= 8.6) {
    $expected_document['data']['attributes']['reusable'] = TRUE;
  }
  return $expected_document;
}