function JsonApiDocumentTopLevelNormalizerTest::testNormalizeConfig

Same name and namespace in other branches
  1. 8.9.x core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testNormalizeConfig()
  2. 10 core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testNormalizeConfig()
  3. 11.x core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testNormalizeConfig()

@covers ::normalize

File

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

Class

JsonApiDocumentTopLevelNormalizerTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21jsonapi%21src%21Normalizer%21JsonApiDocumentTopLevelNormalizer.php/class/JsonApiDocumentTopLevelNormalizer/9" title="Normalizes the top-level document according to the JSON:API specification." class="local">\Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer</a> @group jsonapi

Namespace

Drupal\Tests\jsonapi\Kernel\Normalizer

Code

public function testNormalizeConfig() {
    $resource_type = $this->container
        ->get('jsonapi.resource_type.repository')
        ->get('node_type', 'node_type');
    $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());
}

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