You are here

protected function HalEntityNormalizationTrait::assertNormalizationEdgeCases in Drupal 8

Same name and namespace in other branches
  1. 9 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\EntityResource

Code

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);
  }
}