function EntityTestMapFieldTest::getExpectedDocument

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

Overrides ResourceTestBase::getExpectedDocument

File

core/modules/jsonapi/tests/src/Functional/EntityTestMapFieldTest.php, line 90

Class

EntityTestMapFieldTest
JSON:API integration test for the "EntityTestMapField" content entity type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function getExpectedDocument() {
    $self_url = Url::fromUri('base:/jsonapi/entity_test_map_field/entity_test_map_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_map_field--entity_test_map_field',
            'links' => [
                'self' => [
                    'href' => $self_url,
                ],
            ],
            'attributes' => [
                'created' => (new \DateTime())->setTimestamp($this->entity
                    ->get('created')->value)
                    ->setTimezone(new \DateTimeZone('UTC'))
                    ->format(\DateTime::RFC3339),
                'langcode' => 'en',
                'name' => 'Llama',
                'data' => static::$mapValue,
                'drupal_internal__id' => 1,
            ],
            'relationships' => [
                'user_id' => [
                    'data' => [
                        'id' => $author->uuid(),
                        '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.