class RouteCompilerTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Routing/RouteCompilerTest.php \Drupal\Tests\Core\Routing\RouteCompilerTest
- 8.9.x core/tests/Drupal/Tests/Core/Routing/RouteCompilerTest.php \Drupal\Tests\Core\Routing\RouteCompilerTest
- 10 core/tests/Drupal/Tests/Core/Routing/RouteCompilerTest.php \Drupal\Tests\Core\Routing\RouteCompilerTest
@coversDefaultClass \Drupal\Core\Routing\RouteCompiler @group Routing
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Routing\RouteCompilerTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of RouteCompilerTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Routing/ RouteCompilerTest.php, line 16
Namespace
Drupal\Tests\Core\RoutingView source
class RouteCompilerTest extends UnitTestCase {
/**
* Tests RouteCompiler::getFit().
*
* @param string $path
* A path whose fit will be calculated in the test.
* @param int $expected
* The expected fit returned by RouteCompiler::getFit()
*
* @dataProvider providerTestGetFit
*/
public function testGetFit($path, $expected) : void {
$route_compiler = new RouteCompiler();
$result = $route_compiler->getFit($path);
$this->assertSame($expected, $result);
}
/**
* Provides data for RouteCompilerTest::testGetFit()
*
* @return array
* An array of arrays, where each inner array has the path whose fit is to
* be calculated as the first value and the expected fit as the second
* value.
*/
public static function providerTestGetFit() {
return [
[
'test',
1,
],
[
'/estWithLeadingSlash',
1,
],
[
'testWithTrailingSlash/',
1,
],
[
'/testWithSlashes/',
1,
],
[
'test/with/multiple/parts',
15,
],
[
'test/with/{some}/slugs',
13,
],
[
'test/very/long/path/that/drupal/7/could/not/have/handled',
2047,
],
];
}
/**
* Confirms that a route compiles properly with the necessary data.
*/
public function testCompilation() : void {
$route = new Route('/test/{something}/more');
$route->setOption('compiler_class', RouteCompiler::class);
$compiled = $route->compile();
$this->assertEquals(5, $compiled->getFit(), 'The fit was incorrect.');
$this->assertEquals('/test/%/more', $compiled->getPatternOutline(), 'The pattern outline was not correct.');
}
/**
* Confirms that a compiled route with default values has the correct outline.
*/
public function testCompilationDefaultValue() : void {
// Because "here" has a default value, it should not factor into the outline
// or the fitness.
$route = new Route('/test/{something}/more/{here}', [
'here' => 'there',
]);
$route->setOption('compiler_class', RouteCompiler::class);
$compiled = $route->compile();
$this->assertEquals(5, $compiled->getFit(), 'The fit was not correct.');
$this->assertEquals('/test/%/more', $compiled->getPatternOutline(), 'The pattern outline was not correct.');
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
RouteCompilerTest::providerTestGetFit | public static | function | Provides data for RouteCompilerTest::testGetFit() | |
RouteCompilerTest::testCompilation | public | function | Confirms that a route compiles properly with the necessary data. | |
RouteCompilerTest::testCompilationDefaultValue | public | function | Confirms that a compiled route with default values has the correct outline. | |
RouteCompilerTest::testGetFit | public | function | Tests RouteCompiler::getFit(). | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setUp | protected | function | 356 | |
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.