You are here

public function JsonApiDocumentTopLevelNormalizerTest::testNormalizeRelated in JSON:API 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testNormalizeRelated()

@covers ::normalize

File

tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php, line 302

Class

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

Namespace

Drupal\Tests\jsonapi\Kernel\Normalizer

Code

public function testNormalizeRelated() {
  $this
    ->markTestIncomplete('This fails and should be fixed by https://www.drupal.org/project/jsonapi/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', [
    'request' => $request,
    'resource_type' => $resource_type,
  ]);
  $normalized = $jsonapi_doc_object
    ->rasterizeValue();
  $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());
}