function EntityTestComputedFieldTest::getExpectedDocument

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/EntityTestComputedFieldTest.php \Drupal\Tests\jsonapi\Functional\EntityTestComputedFieldTest::getExpectedDocument()
  2. 10 core/modules/jsonapi/tests/src/Functional/EntityTestComputedFieldTest.php \Drupal\Tests\jsonapi\Functional\EntityTestComputedFieldTest::getExpectedDocument()

Overrides ResourceTestBase::getExpectedDocument

File

core/modules/jsonapi/tests/src/Functional/EntityTestComputedFieldTest.php, line 91

Class

EntityTestComputedFieldTest
JSON:API integration test for the "EntityTestComputedField" content entity type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function getExpectedDocument() : array {
    $self_url = Url::fromUri('base:/jsonapi/entity_test_computed_field/entity_test_computed_field/' . $this->entity
        ->uuid())
        ->setAbsolute()
        ->toString(TRUE)
        ->getGeneratedUrl();
    $author = User::load(0);
    return [
        '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' => 'entity_test_computed_field--entity_test_computed_field',
            'links' => [
                'self' => [
                    'href' => $self_url,
                ],
            ],
            'attributes' => [
                'created' => (new \DateTime())->setTimestamp((int) $this->entity
                    ->get('created')->value)
                    ->setTimezone(new \DateTimeZone('UTC'))
                    ->format(\DateTime::RFC3339),
                'name' => 'Llama',
                'drupal_internal__id' => 1,
                'computed_string_field' => NULL,
                'computed_test_cacheable_string_field' => 'computed test cacheable string field',
                'computed_test_cacheable_integer_field' => 0,
            ],
            'relationships' => [
                'computed_reference_field' => [
                    'data' => NULL,
                    'links' => [
                        'related' => [
                            'href' => $self_url . '/computed_reference_field',
                        ],
                        'self' => [
                            'href' => $self_url . '/relationships/computed_reference_field',
                        ],
                    ],
                ],
                'user_id' => [
                    'data' => [
                        'id' => $author->uuid(),
                        'meta' => [
                            'drupal_internal__target_id' => (int) $author->id(),
                        ],
                        'type' => 'user--user',
                    ],
                    'links' => [
                        'related' => [
                            'href' => $self_url . '/user_id',
                        ],
                        'self' => [
                            'href' => $self_url . '/relationships/user_id',
                        ],
                    ],
                ],
            ],
        ],
    ];
}

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