function ExceptionHandlingTest::testJson403

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Routing/ExceptionHandlingTest.php \Drupal\KernelTests\Core\Routing\ExceptionHandlingTest::testJson403()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Routing/ExceptionHandlingTest.php \Drupal\KernelTests\Core\Routing\ExceptionHandlingTest::testJson403()
  3. 10 core/tests/Drupal/KernelTests/Core/Routing/ExceptionHandlingTest.php \Drupal\KernelTests\Core\Routing\ExceptionHandlingTest::testJson403()

Tests the exception handling for json and 403 status code.

File

core/tests/Drupal/KernelTests/Core/Routing/ExceptionHandlingTest.php, line 63

Class

ExceptionHandlingTest
Tests the exception handling for various cases.

Namespace

Drupal\KernelTests\Core\Routing

Code

public function testJson403() : void {
    $request = Request::create('/router_test/test15');
    $request->query
        ->set('_format', 'json');
    $request->setRequestFormat('json');
    
    /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $kernel */
    $kernel = \Drupal::getContainer()->get('http_kernel');
    $response = $kernel->handle($request);
    $this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode());
    $this->assertEquals('application/json', $response->headers
        ->get('Content-type'));
    $this->assertEquals('{"message":""}', $response->getContent());
    $this->assertInstanceOf(CacheableJsonResponse::class, $response);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.