class RouterTest
Same name in this branch
- main core/modules/system/tests/src/Functional/Routing/RouterTest.php \Drupal\Tests\system\Functional\Routing\RouterTest
- main core/tests/Drupal/Tests/Core/Routing/RouterTest.php \Drupal\Tests\Core\Routing\RouterTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Routing/RouterTest.php \Drupal\Tests\system\Functional\Routing\RouterTest
- 11.x core/tests/Drupal/Tests/Core/Routing/RouterTest.php \Drupal\Tests\Core\Routing\RouterTest
- 10 core/modules/system/tests/src/Functional/Routing/RouterTest.php \Drupal\Tests\system\Functional\Routing\RouterTest
- 10 core/tests/Drupal/Tests/Core/Routing/RouterTest.php \Drupal\Tests\Core\Routing\RouterTest
- 9 core/modules/system/tests/src/Functional/Routing/RouterTest.php \Drupal\Tests\system\Functional\Routing\RouterTest
- 9 core/tests/Drupal/Tests/Core/Routing/RouterTest.php \Drupal\Tests\Core\Routing\RouterTest
- 8.9.x core/modules/system/tests/src/Functional/Routing/RouterTest.php \Drupal\Tests\system\Functional\Routing\RouterTest
- 8.9.x core/tests/Drupal/Tests/Core/Routing/RouterTest.php \Drupal\Tests\Core\Routing\RouterTest
- 11.x core/tests/Drupal/KernelTests/Core/Routing/RouterTest.php \Drupal\KernelTests\Core\Routing\RouterTest
Tests the router.
Attributes
#[Group('Routing')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\Tests\BrowserHtmlDebugTrait, \Drupal\Tests\HttpKernelUiHelperTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Routing\RouterTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of RouterTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Routing/ RouterTest.php, line 17
Namespace
Drupal\KernelTests\Core\RoutingView source
class RouterTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
];
/**
* The router.
*
* @var \Drupal\Core\Routing\Router
*/
protected Router $router;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->router = $this->container
->get('router.no_access_checks');
}
/**
* {@inheritdoc}
*/
protected function tearDown() : void {
parent::tearDown();
}
/**
* Tests the router request matching.
*/
public function testMatchRequest() : void {
$defaults = $this->router
->match('/admin');
$this->assertIsArray($defaults);
$this->assertArrayHasKey('_route', $defaults);
$this->assertEquals('system.admin', $defaults['_route']);
try {
$this->router
->match('/does/not/exist');
$this->fail(sprintf('%s::match() should throw an exception for a non-existing path.', Router::class));
} catch (CacheableResourceNotFoundException $exception) {
$this->assertEquals([], $exception->getCacheContexts());
$this->assertEquals([], $exception->getCacheTags());
$this->assertEquals(Cache::PERMANENT, $exception->getCacheMaxAge());
} catch (\Throwable $exception) {
$this->fail(sprintf('%s::match() should throw %s, %s thrown instead.', Router::class, CacheableResourceNotFoundException::class, get_class($exception)));
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.