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 055a1e76c34..302122aa199 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 @@ class PathMatcherTest extends UnitTestBase { $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 04817088404..f5b4a1893f4 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 @@ class RouterTest extends WebTestBase { /** * 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('', '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('', '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 1b0f23c8584..fa92fd89b3e 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 @@ class TestControllers { 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 529a276c32b..4da939d7059 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; }