function CommentResourceTestBase::testPostDxWithoutCriticalBaseFields
Same name in other branches
- 9 core/modules/comment/tests/src/Functional/Rest/CommentResourceTestBase.php \Drupal\Tests\comment\Functional\Rest\CommentResourceTestBase::testPostDxWithoutCriticalBaseFields()
- 8.9.x core/modules/comment/tests/src/Functional/Rest/CommentResourceTestBase.php \Drupal\Tests\comment\Functional\Rest\CommentResourceTestBase::testPostDxWithoutCriticalBaseFields()
- 10 core/modules/comment/tests/src/Functional/Rest/CommentResourceTestBase.php \Drupal\Tests\comment\Functional\Rest\CommentResourceTestBase::testPostDxWithoutCriticalBaseFields()
Tests POSTing a comment without critical base fields.
Tests with the most minimal normalization possible: the one returned by ::getNormalizedPostEntity().
But Comment entities have some very special edge cases:
- base fields that are not marked as required in \Drupal\comment\Entity\Comment::baseFieldDefinitions() yet in fact are required.
- base fields that are marked as required, but yet can still result in validation errors other than "missing required field".
File
-
core/
modules/ comment/ tests/ src/ Functional/ Rest/ CommentResourceTestBase.php, line 303
Class
Namespace
Drupal\Tests\comment\Functional\RestCode
public function testPostDxWithoutCriticalBaseFields() : void {
$this->initAuthentication();
$this->provisionEntityResource();
$this->setUpAuthorization('POST');
$url = $this->getEntityResourcePostUrl()
->setOption('query', [
'_format' => static::$format,
]);
$request_options = [];
$request_options[RequestOptions::HEADERS]['Accept'] = static::$mimeType;
$request_options[RequestOptions::HEADERS]['Content-Type'] = static::$mimeType;
$request_options = array_merge_recursive($request_options, $this->getAuthenticationRequestOptions('POST'));
// DX: 422 when missing 'entity_type' field.
$request_options[RequestOptions::BODY] = $this->serializer
->encode(array_diff_key($this->getNormalizedPostEntity(), [
'entity_type' => TRUE,
]), static::$format);
$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 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);
$this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nentity_id: This value should not be null.\n", $response);
// DX: 422 when missing 'field_name' field.
$request_options[RequestOptions::BODY] = $this->serializer
->encode(array_diff_key($this->getNormalizedPostEntity(), [
'field_name' => TRUE,
]), static::$format);
$response = $this->request('POST', $url, $request_options);
$this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nfield_name: This value should not be null.\n", $response);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.