You are here

public function JsonApiDocumentTopLevelNormalizerTest::testNormalizeConfig in Drupal 8

@covers ::normalize

File

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

Class

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

Namespace

Drupal\Tests\jsonapi\Kernel\Normalizer

Code

public function testNormalizeConfig() {
  list($request, $resource_type) = $this
    ->generateProphecies('node_type', 'node_type', 'id');
  $resource_object = ResourceObject::createFromEntity($resource_type, $this->nodeType);
  $document_wrapper = new JsonApiDocumentTopLevel(new ResourceObjectData([
    $resource_object,
  ], 1), new NullIncludedData(), new LinkCollection([]));
  $jsonapi_doc_object = $this
    ->getNormalizer()
    ->normalize($document_wrapper, 'api_json', [
    'resource_type' => $resource_type,
    'account' => NULL,
    'sparse_fieldset' => [
      'node_type--node_type' => [
        'description',
        'display_submitted',
      ],
    ],
  ]);
  $normalized = $jsonapi_doc_object
    ->getNormalization();
  $this
    ->assertSame([
    'description',
    'display_submitted',
  ], array_keys($normalized['data']['attributes']));
  $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());
}