You are here

protected function ResourceTestBase::assertResourceErrorResponse in Drupal 10

Same name in this branch
  1. 10 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::assertResourceErrorResponse()
  2. 10 core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::assertResourceErrorResponse()
Same name and namespace in other branches
  1. 8 core/modules/rest/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\rest\Functional\ResourceTestBase::assertResourceErrorResponse()
  2. 9 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.

\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.

7 calls to ResourceTestBase::assertResourceErrorResponse()
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.
EntityResourceTestBase::testPatch in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Tests a PATCH request for an entity, plus edge cases to ensure good DX.
EntityResourceTestBase::testPost in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Tests a POST request for an entity, plus edge cases to ensure good DX.

... See full list

File

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

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);
}