You are here

protected function ExceptionHandlingTest::doTest404Route in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Routing/ExceptionHandlingTest.php \Drupal\KernelTests\Core\Routing\ExceptionHandlingTest::doTest404Route()
  2. 9 core/tests/Drupal/KernelTests/Core/Routing/ExceptionHandlingTest.php \Drupal\KernelTests\Core\Routing\ExceptionHandlingTest::doTest404Route()

Sets the given path to use as the 404 page and triggers a 404.

Parameters

string $path: The path to test.

Return value

\Drupal\Core\Render\HtmlResponse

See also

\Drupal\system\Tests\Routing\ExceptionHandlingTest::testExceptionResponseGeneratedForOriginalRequest()

1 call to ExceptionHandlingTest::doTest404Route()
ExceptionHandlingTest::testExceptionResponseGeneratedForOriginalRequest in core/tests/Drupal/KernelTests/Core/Routing/ExceptionHandlingTest.php
Tests that the exception response is executed in the original context.

File

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

Class

ExceptionHandlingTest
Tests the exception handling for various cases.

Namespace

Drupal\KernelTests\Core\Routing

Code

protected function doTest404Route($path) {
  $this
    ->config('system.site')
    ->set('page.404', $path)
    ->save();
  $request = Request::create('/not-found');
  $request
    ->setFormat('html', [
    'text/html',
  ]);

  /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $kernel */
  $kernel = \Drupal::getContainer()
    ->get('http_kernel');
  return $kernel
    ->handle($request)
    ->prepare($request);
}