You are here

public function JsonApiDocumentTopLevelNormalizerTest::testNormalizeConfig in JSON:API 8.2

Same name and namespace in other branches
  1. 8 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');
  $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());
}