core/modules/comment/src/Entity/Comment.php | 1 + .../Functional/EntityResource/Comment/CommentResourceTestBase.php | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index a244163..dc885fc 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -302,6 +302,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['entity_type'] = BaseFieldDefinition::create('string') ->setLabel(t('Entity type')) ->setDescription(t('The entity type to which this comment is attached.')) + ->setRequired(TRUE) ->setSetting('is_ascii', TRUE) ->setSetting('max_length', EntityTypeInterface::ID_MAX_LENGTH); diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php index 08816ad..0c99acc 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php @@ -280,6 +280,11 @@ public function testPostDxWithoutCriticalBaseFields() { $response = $this->request('POST', $url, $request_options); $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nentity_type: This value should not be null.\n", $response); + // DX: 422 when invalid 'entity_type' field. + $request_options[RequestOptions::BODY] = $this->serializer->encode(['entity_type' => ['value' => 'foobar']] + $this->getNormalizedPostEntity(), static::$format); + $response = $this->request('POST', $url, $request_options); + $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nentity_type: [error message TBD].\n", $response); + // DX: 422 when missing 'entity_id' field. $request_options[RequestOptions::BODY] = $this->serializer->encode(array_diff_key($this->getNormalizedPostEntity(), ['entity_id' => TRUE]), static::$format); $response = $this->request('POST', $url, $request_options);