function ResourceTestBase::assertResourceErrorResponse
Same name in this branch
- 11.x core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::assertResourceErrorResponse()
Same name in other branches
- 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::assertResourceErrorResponse()
- 9 core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::assertResourceErrorResponse()
- 8.9.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::assertResourceErrorResponse()
- 8.9.x core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::assertResourceErrorResponse()
- 10 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::assertResourceErrorResponse()
- 10 core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::assertResourceErrorResponse()
Asserts that a resource error response has the given message.
Cache max-age is not yet considered when expected header is calculated.
Parameters
int $expected_status_code: The expected response status.
string $expected_message: The expected error message.
\Drupal\Core\Url|null $via_link: The source URL for the errors of the response. NULL if the error occurs for example during entity creation.
\Psr\Http\Message\ResponseInterface $response: The error response to assert.
string|false $pointer: The expected JSON Pointer to the associated entity in the request document. See http://jsonapi.org/format/#error-objects.
string[]|false $expected_cache_tags: (optional) The expected cache tags in the X-Drupal-Cache-Tags response header, or FALSE if that header should be absent. Defaults to FALSE.
string[]|false $expected_cache_contexts: (optional) The expected cache contexts in the X-Drupal-Cache-Contexts response header, or FALSE if that header should be absent. Defaults to FALSE.
'MISS','HIT','UNCACHEABLE (request policy)','UNCACHEABLE (response policy)'|NULL $expected_page_cache_header_value: (optional) The expected X-Drupal-Cache response header value, or NULL in case of no opinion on that. For possible string values, see the parameter type hint. Defaults to NULL.
'HIT','MISS','UNCACHEABLE (poor cacheability)','UNCACHEABLE (no cacheability)','UNCACHEABLE (request policy)','UNCACHEABLE (response policy)'|bool $expected_dynamic_page_cache_header_value: (optional) The expected X-Drupal-Dynamic-Cache response header value
- for possible string values, see the parameter type hint - or TRUE when
the value should be autogenerated from expected cache contexts, or FALSE if that header should be absent. Defaults to FALSE.
21 calls to ResourceTestBase::assertResourceErrorResponse()
- CommentExtrasTest::testPostIndividualDxWithoutCriticalBaseFields in core/
modules/ jsonapi/ tests/ src/ Functional/ CommentExtrasTest.php - Tests POSTing a comment without critical base fields.
- FileUploadTest::testFileUploadInvalidFileType in core/
modules/ jsonapi/ tests/ src/ Functional/ FileUploadTest.php - Tests using the file upload route with an invalid file type.
- FileUploadTest::testFileUploadLargerFileSize in core/
modules/ jsonapi/ tests/ src/ Functional/ FileUploadTest.php - Tests using the file upload route with a file size larger than allowed.
- FileUploadTest::testFileUploadMaliciousExtension in core/
modules/ jsonapi/ tests/ src/ Functional/ FileUploadTest.php - Tests using the file upload POST route with malicious extensions.
- FileUploadTest::testPostFileUpload in core/
modules/ jsonapi/ tests/ src/ Functional/ FileUploadTest.php - Tests using the file upload POST route; needs second request to "use" file.
File
-
core/
modules/ jsonapi/ tests/ src/ Functional/ ResourceTestBase.php, line 842
Class
- ResourceTestBase
- Subclass this for every JSON:API resource type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
protected function assertResourceErrorResponse($expected_status_code, $expected_message, $via_link, ResponseInterface $response, $pointer = FALSE, $expected_cache_tags = FALSE, $expected_cache_contexts = FALSE, $expected_page_cache_header_value = NULL, $expected_dynamic_page_cache_header_value = FALSE) {
assert(is_null($via_link) || $via_link instanceof Url);
$expected_error = [];
if (!empty(Response::$statusTexts[$expected_status_code])) {
$expected_error['title'] = Response::$statusTexts[$expected_status_code];
}
$expected_error['status'] = (string) $expected_status_code;
$expected_error['detail'] = $expected_message;
if ($via_link) {
$expected_error['links']['via']['href'] = $via_link->setAbsolute()
->toString();
}
if ($info_url = HttpExceptionNormalizer::getInfoUrl($expected_status_code)) {
$expected_error['links']['info']['href'] = $info_url;
}
if ($pointer !== FALSE) {
$expected_error['source']['pointer'] = $pointer;
}
$expected_document = [
'jsonapi' => static::$jsonApiMember,
'errors' => [
0 => $expected_error,
],
];
$this->assertResourceResponse($expected_status_code, $expected_document, $response, $expected_cache_tags, $expected_cache_contexts, $expected_page_cache_header_value, $expected_dynamic_page_cache_header_value);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.