public function JsonApiDocumentTopLevelNormalizerTest::testNormalizeUuid in Drupal 8
@covers ::normalize
File
- core/
modules/ jsonapi/ tests/ src/ Kernel/ Normalizer/ JsonApiDocumentTopLevelNormalizerTest.php, line 341
Class
- JsonApiDocumentTopLevelNormalizerTest
- @coversDefaultClass \Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer @group jsonapi
Namespace
Drupal\Tests\jsonapi\Kernel\NormalizerCode
public function testNormalizeUuid() {
list($request, $resource_type) = $this
->generateProphecies('node', 'article', 'uuid');
$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([]));
$request->query = new ParameterBag([
'fields' => [
'node--article' => 'title,node_type,uid,field_tags',
'user--user' => 'name',
],
'include' => $include_param,
]);
$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
->assertFalse(empty($normalized['included'][0]['id']));
$this
->assertTrue(empty($normalized['meta']['omitted']));
$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
->assertArraySubset([
'node:1',
'taxonomy_term:1',
'taxonomy_term:2',
'user:1',
], $jsonapi_doc_object
->getCacheTags());
}