function ResourceTestBase::assertResourceErrorResponse

Same name in this branch
  1. 9 core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::assertResourceErrorResponse()
Same name and namespace in other branches
  1. 8.9.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::assertResourceErrorResponse()
  2. 8.9.x core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::assertResourceErrorResponse()
  3. 10 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::assertResourceErrorResponse()
  4. 10 core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::assertResourceErrorResponse()
  5. 11.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::assertResourceErrorResponse()
  6. 11.x core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::assertResourceErrorResponse()

Asserts that a resource error response has the given message.

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.

string|false $expected_page_cache_header_value: (optional) The expected X-Drupal-Cache response header value, or FALSE if that header should be absent. Possible strings: 'MISS', 'HIT'. Defaults to FALSE.

string|false $expected_dynamic_page_cache_header_value: (optional) The expected X-Drupal-Dynamic-Cache response header value, or FALSE if that header should be absent. Possible strings: 'MISS', 'HIT'. Defaults to FALSE.

20 calls to ResourceTestBase::assertResourceErrorResponse()
CommentTest::testPostIndividualDxWithoutCriticalBaseFields in core/modules/jsonapi/tests/src/Functional/CommentTest.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.

... See full list

File

core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php, line 838

Class

ResourceTestBase
Subclass this for every JSON:API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

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 = FALSE, $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.