installEntitySchema('date_format'); } /** * Tests on a route with a non-supported HTTP method. */ public function test405() { $request = Request::create('/router_test/test15', 'PATCH'); /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $kernel */ $kernel = \Drupal::getContainer()->get('http_kernel'); $response = $kernel->handle($request); $this->assertEqual(Response::HTTP_METHOD_NOT_ALLOWED, $response->getStatusCode()); } /** * Tests the exception handling for json and 403 status code. */ public function testJson403() { $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->assertEqual($response->getStatusCode(), Response::HTTP_FORBIDDEN); $this->assertEqual($response->headers->get('Content-type'), 'application/json'); $this->assertEqual('{"message":""}', $response->getContent()); } /** * Tests the exception handling for json and 404 status 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()); } /** * Tests the exception handling for HTML and 403 status code. */ public function testHtml403() { $request = Request::create('/router_test/test15'); $request->setFormat('html', ['text/html']); /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $kernel */ $kernel = \Drupal::getContainer()->get('http_kernel'); $response = $kernel->handle($request)->prepare($request); $this->assertEqual($response->getStatusCode(), Response::HTTP_FORBIDDEN); $this->assertEqual($response->headers->get('Content-type'), 'text/html; charset=UTF-8'); } /** * Tests the exception handling for HTML and 404 status code. */ public function testHtml404() { $request = Request::create('/not-found'); $request->setFormat('html', ['text/html']); /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $kernel */ $kernel = \Drupal::getContainer()->get('http_kernel'); $response = $kernel->handle($request)->prepare($request); $this->assertEqual($response->getStatusCode(), Response::HTTP_NOT_FOUND); $this->assertEqual($response->headers->get('Content-type'), 'text/html; charset=UTF-8'); } /** * Tests that the exception response is executed in the original context. */ public function testExceptionResponseGeneratedForOriginalRequest() { // Test with 404 path pointing to a route that uses '_controller'. $response = $this->doTest404Route('/router_test/test25'); $this->assertTrue(strpos($response->getContent(), '/not-found') !== FALSE); // Test with 404 path pointing to a route that uses '_form'. $response = $this->doTest404Route('/router_test/test26'); $this->assertTrue(strpos($response->getContent(), '