function EntityResourceTestBase::assertNormalizationEdgeCases

Same name in other branches
  1. 8.9.x core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::assertNormalizationEdgeCases()
  2. 10 core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::assertNormalizationEdgeCases()
  3. 11.x core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::assertNormalizationEdgeCases()

Overrides ResourceTestBase::assertNormalizationEdgeCases

5 calls to EntityResourceTestBase::assertNormalizationEdgeCases()
EntityResourceTestBase::testPatch in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Tests a PATCH request for an entity, plus edge cases to ensure good DX.
EntityResourceTestBase::testPost in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Tests a POST request for an entity, plus edge cases to ensure good DX.
EntityTestDateonlyTest::assertNormalizationEdgeCases in core/modules/datetime/tests/src/Functional/EntityResource/EntityTest/EntityTestDateonlyTest.php
Asserts normalization-specific edge cases.
EntityTestDateRangeTest::assertNormalizationEdgeCases in core/modules/datetime_range/tests/src/Functional/EntityResource/EntityTest/EntityTestDateRangeTest.php
Asserts normalization-specific edge cases.
EntityTestDatetimeTest::assertNormalizationEdgeCases in core/modules/datetime/tests/src/Functional/EntityResource/EntityTest/EntityTestDatetimeTest.php
Asserts normalization-specific edge cases.
3 methods override EntityResourceTestBase::assertNormalizationEdgeCases()
EntityTestDateonlyTest::assertNormalizationEdgeCases in core/modules/datetime/tests/src/Functional/EntityResource/EntityTest/EntityTestDateonlyTest.php
Asserts normalization-specific edge cases.
EntityTestDateRangeTest::assertNormalizationEdgeCases in core/modules/datetime_range/tests/src/Functional/EntityResource/EntityTest/EntityTestDateRangeTest.php
Asserts normalization-specific edge cases.
EntityTestDatetimeTest::assertNormalizationEdgeCases in core/modules/datetime/tests/src/Functional/EntityResource/EntityTest/EntityTestDatetimeTest.php
Asserts normalization-specific edge cases.

File

core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php, line 1169

Class

EntityResourceTestBase
Defines a base class for testing all entity resources.

Namespace

Drupal\Tests\rest\Functional\EntityResource

Code

protected function assertNormalizationEdgeCases($method, Url $url, array $request_options) {
    // \Drupal\serialization\Normalizer\EntityNormalizer::denormalize(): entity
    // types with bundles MUST send their bundle field to be denormalizable.
    $entity_type = $this->entity
        ->getEntityType();
    if ($entity_type->hasKey('bundle')) {
        $bundle_field_name = $this->entity
            ->getEntityType()
            ->getKey('bundle');
        $normalization = $this->getNormalizedPostEntity();
        // The bundle type itself can be validated only if there's a bundle entity
        // type.
        if ($entity_type->getBundleEntityType()) {
            $normalization[$bundle_field_name] = '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, '"bad_bundle_name" is not a valid bundle type for denormalization.', $response);
        }
        unset($normalization[$bundle_field_name]);
        $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, sprintf('Could not determine entity type bundle: "%s" field is missing.', $bundle_field_name), $response);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.