public function CommentResourceTestBase::testPostDxWithoutCriticalBaseFields in Drupal 9
Same name and namespace in other branches
- 8 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".
3 methods override CommentResourceTestBase::testPostDxWithoutCriticalBaseFields()
- CommentXmlAnonTest::testPostDxWithoutCriticalBaseFields in core/
modules/ comment/ tests/ src/ Functional/ Rest/ CommentXmlAnonTest.php - Tests POSTing a comment without critical base fields.
- CommentXmlBasicAuthTest::testPostDxWithoutCriticalBaseFields in core/
modules/ comment/ tests/ src/ Functional/ Rest/ CommentXmlBasicAuthTest.php - Tests POSTing a comment without critical base fields.
- CommentXmlCookieTest::testPostDxWithoutCriticalBaseFields in core/
modules/ comment/ tests/ src/ Functional/ Rest/ CommentXmlCookieTest.php - Tests POSTing a comment without critical base fields.
File
- core/
modules/ comment/ tests/ src/ Functional/ Rest/ CommentResourceTestBase.php, line 288
Class
Namespace
Drupal\Tests\comment\Functional\RestCode
public function testPostDxWithoutCriticalBaseFields() {
$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);
}