function ExceptionHandlingTest::doTest404Route

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Routing/ExceptionHandlingTest.php \Drupal\KernelTests\Core\Routing\ExceptionHandlingTest::doTest404Route()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Routing/ExceptionHandlingTest.php \Drupal\KernelTests\Core\Routing\ExceptionHandlingTest::doTest404Route()
  3. 10 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 152

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.