diff --git a/core/modules/system/lib/Drupal/system/Tests/Routing/PathMatcherTest.php b/core/modules/system/lib/Drupal/system/Tests/Routing/PathMatcherTest.php index 055a1e76c34838b0117e819931c339d667781d9b..302122aa199a6b3607a19bf73cfc709a68d23145 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Routing/PathMatcherTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Routing/PathMatcherTest.php @@ -127,6 +127,46 @@ function testOutlinePathMatch() { $this->assertNotNull($routes->get('route_b'), 'The second matching route was not found.'); } + /** + * Confirms that we can find routes whose pattern would match the request. + */ + function testOutlinePathMatchDefaults() { + $connection = Database::getConnection(); + $matcher = new PathMatcher($connection, 'test_routes'); + + $this->fixtures->createTables($connection); + + $collection = new RouteCollection(); + $collection->add('poink', new Route('/some/path/{value}', array( + 'value' => 'poink', + ))); + + $dumper = new MatcherDumper($connection, 'test_routes'); + $dumper->addRoutes($collection); + $dumper->dump(); + + $path = '/some/path'; + + $request = Request::create($path, 'GET'); + + try { + $routes = $matcher->matchRequestPartial($request); + + // All of the matching paths have the correct pattern. + foreach ($routes as $route) { + $compiled = $route->compile(); + debug($compiled->getPatternOutline()); + $this->assertEqual($route->compile()->getPatternOutline(), '/path/path/%', 'Found path has correct pattern'); + } + + $this->assertEqual(count($routes->all()), 1, 'The correct number of routes was found.'); + $this->assertNotNull($routes->get('poink'), 'The first matching route was found.'); + } + catch (ResourceNotFoundException $e) { + $this->fail('No matching route found with default argument value.'); + } + } + /** * Confirm that an exception is thrown when no matching path is found. */ diff --git a/core/modules/system/lib/Drupal/system/Tests/Routing/RouterTest.php b/core/modules/system/lib/Drupal/system/Tests/Routing/RouterTest.php index 048170884049d8cc1e114acd77ab9bf71679fb4f..f5b4a1893f4d22f73b89576b06b6e1a333a70f27 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Routing/RouterTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Routing/RouterTest.php @@ -49,11 +49,20 @@ public function testDefaultController() { /** * Confirms that placeholders in paths work correctly. */ - public function testDefaultControllerPlaceholders() { + public function testControllerPlaceholders() { $value = $this->randomName(); $this->drupalGet('router_test/test3/' . $value); $this->assertRaw($value, 'The correct string was returned because the route was successful.'); $this->assertRaw('</html>', 'Page markup was found.'); } + /** + * Confirms that default placeholders in paths work correctly. + */ + public function testControllerPlaceholdersDefaultValues() { + $this->drupalGet('router_test/test4'); + $this->assertRaw('narf', 'The correct string was returned because the route was successful.'); + $this->assertRaw('</html>', 'Page markup was found.'); + } + } diff --git a/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/TestControllers.php b/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/TestControllers.php index 1b0f23c8584eded2de345904ed9fe9f1251f8ae9..fa92fd89b3e5969326bb48bf4f2418a369c915f8 100644 --- a/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/TestControllers.php +++ b/core/modules/system/tests/modules/router_test/lib/Drupal/router_test/TestControllers.php @@ -26,4 +26,8 @@ public function test3($value) { return $value; } + public function test4($value) { + return $value; + } + } diff --git a/core/modules/system/tests/modules/router_test/router_test.module b/core/modules/system/tests/modules/router_test/router_test.module index 529a276c32b6df5bb1a205da37611f4306400f7c..4da939d7059261b7016d5298971298d24a046200 100644 --- a/core/modules/system/tests/modules/router_test/router_test.module +++ b/core/modules/system/tests/modules/router_test/router_test.module @@ -24,5 +24,11 @@ function router_test_route_info() { )); $collection->add('router_test_3', $route); + $route = new Route('router_test/test4/{value}', array( + '_content' => '\Drupal\router_test\TestControllers::test4', + 'value' => 'narf', + )); + $collection->add('router_test_4', $route); + return $collection; }