RedirectOnExceptionTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Drupal\KernelTests\RequestProcessing;
  3. use Drupal\KernelTests\KernelTestBase;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. /**
  7. * Tests redirects on exception pages.
  8. *
  9. * @group request_processing
  10. */
  11. class RedirectOnExceptionTest extends KernelTestBase {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public static $modules = ['system', 'test_page_test'];
  16. /**
  17. * {@inheritdoc}
  18. */
  19. protected function setUp() {
  20. parent::setUp();
  21. \Drupal::service('router.builder')->rebuild();
  22. }
  23. public function testRedirectOn404() {
  24. \Drupal::configFactory()->getEditable('system.site')
  25. ->set('page.404', '/test-http-response-exception/' . Response::HTTP_PERMANENTLY_REDIRECT)
  26. ->save();
  27. /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel */
  28. $http_kernel = \Drupal::service('http_kernel');
  29. // Foo doesn't exist, so this triggers the 404 page.
  30. $request = Request::create('/foo');
  31. $response = $http_kernel->handle($request);
  32. $this->assertEquals(Response::HTTP_PERMANENTLY_REDIRECT, $response->getStatusCode());
  33. }
  34. }