public function JsonApiDocumentTopLevelNormalizerTest::testDenormalizeUuid in JSON:API 8
Same name in this branch
- 8 tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Unit\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testDenormalizeUuid()
- 8 tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testDenormalizeUuid()
Same name and namespace in other branches
- 8.2 tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Unit\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testDenormalizeUuid()
Ensures only valid UUIDs can be specified.
@covers ::denormalize @dataProvider denormalizeUuidProvider
Parameters
string $id: The input UUID. May be invalid.
bool $expect_exception: Whether to expect an exception.
File
- tests/
src/ Unit/ Normalizer/ JsonApiDocumentTopLevelNormalizerTest.php, line 216
Class
- JsonApiDocumentTopLevelNormalizerTest
- @coversDefaultClass \Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer @group jsonapi
Namespace
Drupal\Tests\jsonapi\Unit\NormalizerCode
public function testDenormalizeUuid($id, $expect_exception) {
$data['data'] = isset($id) ? [
'type' => 'node--article',
'id' => $id,
] : [
'type' => 'node--article',
];
if ($expect_exception) {
$this
->setExpectedException(UnprocessableEntityHttpException::class, 'IDs should be properly generated and formatted UUIDs as described in RFC 4122.');
}
$denormalized = $this->normalizer
->denormalize($data, NULL, 'api_json', [
'resource_type' => new ResourceType($this
->randomMachineName(), $this
->randomMachineName(), FieldableEntityInterface::class),
]);
if (isset($id)) {
$this
->assertSame($id, $denormalized['uuid']);
}
else {
$this
->assertArrayNotHasKey('uuid', $denormalized);
}
}