diff --git a/core/modules/system/lib/Drupal/system/Tests/Routing/FirstEntryFinalMatcherTest.php b/core/modules/system/lib/Drupal/system/Tests/Routing/FirstEntryFinalMatcherTest.php new file mode 100644 index 00000000000..0f174770b71 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Routing/FirstEntryFinalMatcherTest.php @@ -0,0 +1,116 @@ + 'FirstEntryFinalMatcher tests', + 'description' => 'Confirm that the FirstEntryFinalMatcher is working properly.', + 'group' => 'Routing', + ); + } + + function __construct($test_id = NULL) { + parent::__construct($test_id); + + $this->fixtures = new RoutingFixtures(); + } + public function setUp() { + parent::setUp(); + } + + /** + * Confirms the final matcher returns correct attributes for static paths. + */ + public function testFinalMatcherStatic() { + + $collection = new RouteCollection(); + $collection->add('route_a', new Route('/path/one', array( + '_controller' => 'foo', + ))); + + $request = Request::create('/path/one', 'GET'); + + $matcher = new FirstEntryFinalMatcher(); + $matcher->setCollection($collection); + $attributes = $matcher->matchRequest($request); + + $this->assertEqual($attributes['_route'], 'route_a', 'The correct matching route was found.'); + $this->assertEqual($attributes['_controller'], 'foo', 'The correct controller was found.'); + } + + /** + * Confirms the final matcher returns correct attributes for pattern paths. + */ + public function testFinalMatcherPattern() { + + $collection = new RouteCollection(); + $collection->add('route_a', new Route('/path/one/{value}', array( + '_controller' => 'foo', + ))); + + $request = Request::create('/path/one/narf', 'GET'); + $request->attributes->set('system_path', 'path/one/narf'); + + $matcher = new FirstEntryFinalMatcher(); + $matcher->setCollection($collection); + $attributes = $matcher->matchRequest($request); + + $this->assertEqual($attributes['_route'], 'route_a', 'The correct matching route was found.'); + $this->assertEqual($attributes['_controller'], 'foo', 'The correct controller was found.'); + $this->assertEqual($attributes['value'], 'narf', 'Required placeholder value found.'); + } + + /** + * Confirms the final matcher returns correct attributes with default values. + */ + public function testFinalMatcherPatternDefalts() { + + $collection = new RouteCollection(); + $collection->add('route_a', new Route('/path/one/{value}', array( + '_controller' => 'foo', + 'value' => 'poink' + ))); + + $request = Request::create('/path/one', 'GET'); + $request->attributes->set('system_path', 'path/one'); + + $matcher = new FirstEntryFinalMatcher(); + $matcher->setCollection($collection); + $attributes = $matcher->matchRequest($request); + + $this->assertEqual($attributes['_route'], 'route_a', 'The correct matching route was found.'); + $this->assertEqual($attributes['_controller'], 'foo', 'The correct controller was found.'); + $this->assertEqual($attributes['value'], 'poink', 'Optional placeholder value used default.'); + } +} +