You are here

public function JsonApiDocumentTopLevelNormalizerTest::testNormalizeConfig 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::testNormalizeConfig()

@covers ::normalize

File

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

Class

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

Namespace

Drupal\Tests\jsonapi\Kernel\Normalizer

Code

public function testNormalizeConfig() {
  list($request, $resource_type) = $this
    ->generateProphecies('node_type', 'node_type', 'id');
  $document_wrapper = $this
    ->prophesize(JsonApiDocumentTopLevel::class);
  $document_wrapper
    ->getData()
    ->willReturn($this->nodeType);
  $request->query = new ParameterBag([
    'fields' => [
      'node_type--node_type' => 'uuid,display_submitted',
    ],
    'include' => NULL,
  ]);
  $jsonapi_doc_object = $this
    ->getNormalizer()
    ->normalize($document_wrapper
    ->reveal(), 'api_json', [
    'request' => $request,
    'resource_type' => $resource_type,
  ]);
  $normalized = $jsonapi_doc_object
    ->rasterizeValue();
  $this
    ->assertTrue(empty($normalized['data']['attributes']['type']));
  $this
    ->assertTrue(!empty($normalized['data']['attributes']['uuid']));
  $this
    ->assertSame($normalized['data']['attributes']['display_submitted'], TRUE);
  $this
    ->assertSame($normalized['data']['id'], NodeType::load('article')
    ->uuid());
  $this
    ->assertSame($normalized['data']['type'], 'node_type--node_type');

  // Make sure that the cache tags for the includes and the requested entities
  // are bubbling as expected.
  $this
    ->assertSame([
    'config:node.type.article',
  ], $jsonapi_doc_object
    ->getCacheTags());
}