function JsonApiDocumentTopLevelNormalizerTest::testNormalizeRelated

@covers ::normalize

File

core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php, line 304

Class

JsonApiDocumentTopLevelNormalizerTest
@coversDefaultClass \Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer @group jsonapi

Namespace

Drupal\Tests\jsonapi\Kernel\Normalizer

Code

public function testNormalizeRelated() {
    $this->markTestIncomplete('This fails and should be fixed by https://www.drupal.org/project/drupal/issues/2922121');
    list($request, $resource_type) = $this->generateProphecies('node', 'article', 'uid');
    $request->query = new ParameterBag([
        'fields' => [
            'user--user' => 'name,roles',
        ],
        'include' => 'roles',
    ]);
    $document_wrapper = $this->prophesize(JsonApiDocumentTopLevel::class);
    $author = $this->node
        ->get('uid')->entity;
    $document_wrapper->getData()
        ->willReturn($author);
    $jsonapi_doc_object = $this->getNormalizer()
        ->normalize($document_wrapper->reveal(), 'api_json', [
        'resource_type' => $resource_type,
        'account' => NULL,
    ]);
    $normalized = $jsonapi_doc_object->getNormalization();
    $this->assertSame($normalized['data']['attributes']['name'], 'user1');
    $this->assertEquals($normalized['data']['id'], User::load(1)->uuid());
    $this->assertEquals($normalized['data']['type'], 'user--user');
    // Make sure that the cache tags for the includes and the requested entities
    // are bubbling as expected.
    $this->assertSame([
        'user:1',
    ], $jsonapi_doc_object->getCacheTags());
    $this->assertSame(Cache::PERMANENT, $jsonapi_doc_object->getCacheMaxAge());
}

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