public function ExceptionHandlingTest::testJson404 in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Routing/ExceptionHandlingTest.php \Drupal\KernelTests\Core\Routing\ExceptionHandlingTest::testJson404()
- 10 core/tests/Drupal/KernelTests/Core/Routing/ExceptionHandlingTest.php \Drupal\KernelTests\Core\Routing\ExceptionHandlingTest::testJson404()
Tests the exception handling for json and 404 status code.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Routing/ ExceptionHandlingTest.php, line 66
Class
- ExceptionHandlingTest
- Tests the exception handling for various cases.
Namespace
Drupal\KernelTests\Core\RoutingCode
public function testJson404() {
$request = Request::create('/not-found');
$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_NOT_FOUND, $response
->getStatusCode());
$this
->assertEquals('application/json', $response->headers
->get('Content-type'));
$this
->assertEquals('{"message":"No route found for \\u0022GET \\/not-found\\u0022"}', $response
->getContent());
}