function HalEntityNormalizationTrait::assertNormalizationEdgeCases
Same name in other branches
- 8.9.x core/modules/hal/tests/src/Functional/EntityResource/HalEntityNormalizationTrait.php \Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait::assertNormalizationEdgeCases()
File
-
core/
modules/ hal/ tests/ src/ Functional/ EntityResource/ HalEntityNormalizationTrait.php, line 76
Class
- HalEntityNormalizationTrait
- Trait for EntityResourceTestBase subclasses testing formats using HAL.
Namespace
Drupal\Tests\hal\Functional\EntityResourceCode
protected function assertNormalizationEdgeCases($method, Url $url, array $request_options) {
// \Drupal\hal\Normalizer\EntityNormalizer::denormalize(): entity
// types with bundles MUST send their bundle field to be denormalizable.
if ($this->entity
->getEntityType()
->hasKey('bundle')) {
$normalization = $this->getNormalizedPostEntity();
$normalization['_links']['type'] = Url::fromUri('base:rest/type/' . static::$entityTypeId . '/bad_bundle_name');
$request_options[RequestOptions::BODY] = $this->serializer
->encode($normalization, static::$format);
// DX: 422 when incorrect entity type bundle is specified.
$response = $this->request($method, $url, $request_options);
$this->assertResourceErrorResponse(422, 'No entity type(s) specified', $response);
unset($normalization['_links']['type']);
$request_options[RequestOptions::BODY] = $this->serializer
->encode($normalization, static::$format);
// DX: 422 when no entity type bundle is specified.
$response = $this->request($method, $url, $request_options);
$this->assertResourceErrorResponse(422, 'The type link relation must be specified.', $response);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.