3 namespace Drupal\Tests\Core\Routing;
5 use Drupal\Core\Routing\RouteCompiler;
6 use Symfony\Component\Routing\Route;
8 use Drupal\Tests\UnitTestCase;
11 * @coversDefaultClass \Drupal\Core\Routing\RouteCompiler
14 class RouteCompilerTest extends UnitTestCase {
17 * Tests RouteCompiler::getFit().
20 * A path whose fit will be calculated in the test.
21 * @param int $expected
22 * The expected fit returned by RouteCompiler::getFit()
24 * @dataProvider providerTestGetFit
26 public function testGetFit($path, $expected) {
27 $route_compiler = new RouteCompiler();
28 $result = $route_compiler->getFit($path);
29 $this->assertSame($expected, $result);
33 * Provides data for RouteCompilerTest::testGetFit()
36 * An array of arrays, where each inner array has the path whose fit is to
37 * be calculated as the first value and the expected fit as the second
40 public function providerTestGetFit() {
43 ['/testwithleadingslash', 1],
44 ['testwithtrailingslash/', 1],
45 ['/testwithslashes/', 1],
46 ['test/with/multiple/parts', 15],
47 ['test/with/{some}/slugs', 13],
48 ['test/very/long/path/that/drupal/7/could/not/have/handled', 2047],
53 * Confirms that a route compiles properly with the necessary data.
55 public function testCompilation() {
56 $route = new Route('/test/{something}/more');
57 $route->setOption('compiler_class', 'Drupal\Core\Routing\RouteCompiler');
58 $compiled = $route->compile();
60 $this->assertEquals($compiled->getFit(), 5 /* That's 101 binary*/, 'The fit was incorrect.');
61 $this->assertEquals($compiled->getPatternOutline(), '/test/%/more', 'The pattern outline was not correct.');
65 * Confirms that a compiled route with default values has the correct outline.
67 public function testCompilationDefaultValue() {
68 // Because "here" has a default value, it should not factor into the outline
70 $route = new Route('/test/{something}/more/{here}', [
73 $route->setOption('compiler_class', 'Drupal\Core\Routing\RouteCompiler');
74 $compiled = $route->compile();
76 $this->assertEquals($compiled->getFit(), 5 /* That's 101 binary*/, 'The fit was not correct.');
77 $this->assertEquals($compiled->getPatternOutline(), '/test/%/more', 'The pattern outline was not correct.');