You are here

public function ExceptionHandlingTest::testJson404 in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Routing/ExceptionHandlingTest.php \Drupal\system\Tests\Routing\ExceptionHandlingTest::testJson404()

Tests the exception handling for json and 404 status code.

File

core/modules/system/src/Tests/Routing/ExceptionHandlingTest.php, line 57
Contains \Drupal\system\Tests\Routing\ExceptionHandlingTest.

Class

ExceptionHandlingTest
Tests the exception handling for various cases.

Namespace

Drupal\system\Tests\Routing

Code

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
    ->assertEqual($response
    ->getStatusCode(), Response::HTTP_NOT_FOUND);
  $this
    ->assertEqual($response->headers
    ->get('Content-type'), 'application/json');
  $this
    ->assertEqual('{"message":"No route found for \\u0022GET \\/not-found\\u0022"}', $response
    ->getContent());
}