Browse Source

Add test for added cases in RouteCollection::_getNames()

The additional prefix names are needed for cases like this test.
Uncomment accidentally commented out test case.
mark_story 11 years ago
parent
commit
f981c7c8ec

+ 36 - 0
tests/TestCase/Routing/RouteCollectionTest.php

@@ -179,6 +179,42 @@ class RouteCollectionTest extends TestCase {
 	}
 
 /**
+ * Test that prefixes increase the specificity of a route match.
+ *
+ * Connect the admin route after the non prefixed version, this means
+ * the non-prefix route would have a more specific name (users:index)
+ *
+ * @return void
+ */
+	public function testMatchPrefixSpecificity() {
+		$context = [
+			'_base' => '/',
+			'_scheme' => 'http',
+			'_host' => 'example.org',
+		];
+		$routes = new RouteBuilder($this->collection, '/');
+		$routes->connect('/:action/*', ['controller' => 'Users']);
+		$routes->connect('/admin/:controller', ['prefix' => 'admin', 'action' => 'index']);
+
+		$url = [
+			'plugin' => null,
+			'prefix' => 'admin',
+			'controller' => 'Users',
+			'action' => 'index'
+		];
+		$result = $this->collection->match($url, $context);
+		$this->assertEquals('admin/Users', $result);
+
+		$url = [
+			'plugin' => null,
+			'controller' => 'Users',
+			'action' => 'index'
+		];
+		$result = $this->collection->match($url, $context);
+		$this->assertEquals('index', $result);
+	}
+
+/**
  * Test getting named routes.
  *
  * @return void

+ 3 - 3
tests/TestCase/Routing/RouterTest.php

@@ -1880,9 +1880,9 @@ class RouterTest extends TestCase {
 		Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
 		Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
 
-		// $result = Router::parse('/');
-		// $expected = array('pass' => array('home'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
-		// $this->assertEquals($expected, $result);
+		$result = Router::parse('/');
+		$expected = array('pass' => array('home'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
+		$this->assertEquals($expected, $result);
 
 		$result = Router::parse('/pages/home/');
 		$expected = array('pass' => array('home'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');