function JsonApiDocumentTopLevelNormalizerTest::testNormalizeUuid
Same name in other branches
- 8.9.x core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testNormalizeUuid()
- 10 core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testNormalizeUuid()
- 11.x core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testNormalizeUuid()
@covers ::normalize
File
-
core/
modules/ jsonapi/ tests/ src/ Kernel/ Normalizer/ JsonApiDocumentTopLevelNormalizerTest.php, line 360
Class
- JsonApiDocumentTopLevelNormalizerTest
- @coversDefaultClass \Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer @group jsonapi
Namespace
Drupal\Tests\jsonapi\Kernel\NormalizerCode
public function testNormalizeUuid() {
$resource_type = $this->container
->get('jsonapi.resource_type.repository')
->get('node', 'article');
$resource_object = ResourceObject::createFromEntity($resource_type, $this->node);
$include_param = 'uid,field_tags';
$includes = $this->includeResolver
->resolve($resource_object, $include_param);
$document_wrapper = new JsonApiDocumentTopLevel(new ResourceObjectData([
$resource_object,
], 1), $includes, new LinkCollection([]));
$jsonapi_doc_object = $this->getNormalizer()
->normalize($document_wrapper, 'api_json', [
'resource_type' => $resource_type,
'account' => NULL,
'include' => [
'uid',
'field_tags',
],
]);
$normalized = $jsonapi_doc_object->getNormalization();
$this->assertStringMatchesFormat($this->node
->uuid(), $normalized['data']['id']);
$this->assertEquals($this->node->type->entity
->uuid(), $normalized['data']['relationships']['node_type']['data']['id']);
$this->assertEquals($this->user
->uuid(), $normalized['data']['relationships']['uid']['data']['id']);
$this->assertNotEmpty($normalized['included'][0]['id']);
$this->assertArrayNotHasKey('meta', $normalized);
$this->assertEquals($this->user
->uuid(), $normalized['included'][0]['id']);
$this->assertCount(1, $normalized['included'][0]['attributes']);
$this->assertCount(12, $normalized['included'][1]['attributes']);
// Make sure that the cache tags for the includes and the requested entities
// are bubbling as expected.
$this->assertEqualsCanonicalizing([
'node:1',
'taxonomy_term:1',
'taxonomy_term:2',
'user:1',
], $jsonapi_doc_object->getCacheTags());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.