You are here

public function RestJsonApiUnsupported::testApiJsonNotSupportedInRest in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Functional/RestJsonApiUnsupported.php \Drupal\Tests\jsonapi\Functional\RestJsonApiUnsupported::testApiJsonNotSupportedInRest()

Deploying a REST resource using api_json format results in 400 responses.

See also

\Drupal\jsonapi\EventSubscriber\JsonApiRequestValidator::validateQueryParams()

File

core/modules/jsonapi/tests/src/Functional/RestJsonApiUnsupported.php, line 90

Class

RestJsonApiUnsupported
Ensures that the 'api_json' format is not supported by the REST module.

Namespace

Drupal\Tests\jsonapi\Functional

Code

public function testApiJsonNotSupportedInRest() {
  $this
    ->assertSame([
    'json',
    'xml',
  ], $this->container
    ->getParameter('serializer.formats'));
  $this
    ->provisionResource([
    'api_json',
  ], []);
  $this
    ->setUpAuthorization('GET');
  $url = Node::load(1)
    ->toUrl()
    ->setOption('query', [
    '_format' => 'api_json',
  ]);
  $request_options = [];
  $response = $this
    ->request('GET', $url, $request_options);
  $this
    ->assertResourceErrorResponse(400, FALSE, $response, [
    '4xx-response',
    'config:user.role.anonymous',
    'http_response',
    'node:1',
  ], [
    'url.query_args:_format',
    'url.site',
    'user.permissions',
  ], 'MISS', 'MISS');
}