function ResourceTestBase::assertResourceErrorResponse

Same name in this branch
  1. 10 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::assertResourceErrorResponse()
Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::assertResourceErrorResponse()
  2. 9 core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::assertResourceErrorResponse()
  3. 8.9.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::assertResourceErrorResponse()
  4. 8.9.x 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|false $expected_message: The expected error message.

\Psr\Http\Message\ResponseInterface $response: The error response to assert.

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.

23 calls to ResourceTestBase::assertResourceErrorResponse()
CommentResourceTestBase::testPostDxWithoutCriticalBaseFields in core/modules/comment/tests/src/Functional/Rest/CommentResourceTestBase.php
Tests POSTing a comment without critical base fields.
DbLogResourceTest::testWatchdog in core/modules/dblog/tests/src/Functional/DbLogResourceTest.php
Writes a log messages and retrieves it via the REST API.
EntityResourceTestBase::assertNormalizationEdgeCases in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Asserts normalization-specific edge cases.
EntityResourceTestBase::testDelete in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Tests a DELETE request for an entity, plus edge cases to ensure good DX.
EntityResourceTestBase::testGet in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Tests a GET request for an entity, plus edge cases to ensure good DX.

... See full list

File

core/modules/rest/tests/src/Functional/ResourceTestBase.php, line 455

Class

ResourceTestBase
Subclass this for every REST resource, every format and every auth provider.

Namespace

Drupal\Tests\rest\Functional

Code

protected function assertResourceErrorResponse($expected_status_code, $expected_message, ResponseInterface $response, $expected_cache_tags = FALSE, $expected_cache_contexts = FALSE, $expected_page_cache_header_value = FALSE, $expected_dynamic_page_cache_header_value = FALSE) {
    $expected_body = $expected_message !== FALSE ? $this->serializer
        ->encode([
        'message' => $expected_message,
    ], static::$format) : FALSE;
    $this->assertResourceResponse($expected_status_code, $expected_body, $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.