Browse Source

Merge pull request #3680 from cakephp/3.0-camelcase-actions

3.0 - No inflector in routes
José Lorenzo Rodríguez 11 years ago
parent
commit
0fbad5ddfe

+ 26 - 7
src/Config/routes.php

@@ -58,23 +58,42 @@ $pluginShortMatch = [
 ];
 
 if ($prefixPattern && $pluginPattern) {
-	$match = ['prefix' => $prefixPattern, 'plugin' => $pluginPattern, 'defaultRoute' => true];
-	Router::connect('/:prefix/:plugin', $indexParams, $match + $pluginShortMatch);
+	$match = [
+		'prefix' => $prefixPattern,
+		'plugin' => $pluginPattern,
+		'defaultRoute' => true,
+		'routeClass' => 'Cake\Routing\Route\InflectedRoute'
+	];
+	Router::connect('/:prefix/:plugin', $indexParams, $pluginShortMatch + $match);
 	Router::connect('/:prefix/:plugin/:controller', $indexParams, $match);
 	Router::connect('/:prefix/:plugin/:controller/:action/*', [], $match);
 }
 if ($pluginPattern) {
-	$match = ['plugin' => $pluginPattern, 'defaultRoute' => true];
-	Router::connect('/:plugin', $indexParams, $match + $pluginShortMatch);
+	$match = [
+		'plugin' => $pluginPattern,
+		'defaultRoute' => true,
+		'routeClass' => 'Cake\Routing\Route\InflectedRoute'
+	];
+	Router::connect('/:plugin', $indexParams, $pluginShortMatch + $match);
 	Router::connect('/:plugin/:controller', $indexParams, $match);
 	Router::connect('/:plugin/:controller/:action/*', [], $match);
 }
 if ($prefixPattern) {
-	$match = ['prefix' => $prefixPattern, 'defaultRoute' => true];
+	$match = [
+		'prefix' => $prefixPattern,
+		'defaultRoute' => true,
+		'routeClass' => 'Cake\Routing\Route\InflectedRoute'
+	];
 	Router::connect('/:prefix/:controller', $indexParams, $match);
 	Router::connect('/:prefix/:controller/:action/*', [], $match);
 }
-Router::connect('/:controller', ['action' => 'index']);
-Router::connect('/:controller/:action/*');
+Router::connect('/:controller', ['action' => 'index'], [
+	'defaultRoute' => true,
+	'routeClass' => 'Cake\Routing\Route\InflectedRoute'
+]);
+Router::connect('/:controller/:action/*', [], [
+	'defaultRoute' => true,
+	'routeClass' => 'Cake\Routing\Route\InflectedRoute'
+]);
 
 unset($prefixes, $prefixPattern, $plugins, $pluginPattern, $indexParams, $match);

+ 1 - 1
src/Console/Command/Task/ViewTask.php

@@ -431,7 +431,7 @@ class ViewTask extends BakeTask {
 					'primaryKey' => (array)$target->primaryKey(),
 					'displayField' => $target->displayField(),
 					'foreignKey' => $assoc->foreignKey(),
-					'controller' => Inflector::underscore($alias),
+					'controller' => $alias,
 					'fields' => $target->schema()->columns(),
 				];
 			}

+ 1 - 1
src/Controller/Controller.php

@@ -340,7 +340,7 @@ class Controller implements EventListener {
  */
 	public function setRequest(Request $request) {
 		$this->request = $request;
-		$this->plugin = isset($request->params['plugin']) ? Inflector::camelize($request->params['plugin']) : null;
+		$this->plugin = isset($request->params['plugin']) ? $request->params['plugin'] : null;
 		$this->view = isset($request->params['action']) ? $request->params['action'] : null;
 
 		if (isset($request->params['pass'])) {

+ 3 - 3
src/Routing/Filter/ControllerFactoryFilter.php

@@ -59,13 +59,13 @@ class ControllerFactoryFilter extends DispatcherFilter {
 		$pluginPath = $controller = null;
 		$namespace = 'Controller';
 		if (!empty($request->params['plugin'])) {
-			$pluginPath = Inflector::camelize($request->params['plugin']) . '.';
+			$pluginPath = $request->params['plugin'] . '.';
 		}
 		if (!empty($request->params['controller'])) {
-			$controller = Inflector::camelize($request->params['controller']);
+			$controller = $request->params['controller'];
 		}
 		if (!empty($request->params['prefix'])) {
-			$namespace .= '/' . Inflector::camelize($request->params['prefix']);
+			$namespace .= '/' . $request->params['prefix'];
 		}
 		$className = false;
 		if ($pluginPath . $controller) {

+ 73 - 0
src/Routing/Route/InflectedRoute.php

@@ -0,0 +1,73 @@
+<?php
+/**
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * For full copyright and license information, please see the LICENSE.txt
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link          http://cakephp.org CakePHP(tm) Project
+ * @since         3.0.0
+ * @license       http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+namespace Cake\Routing\Route;
+
+use Cake\Routing\Route\Route;
+use Cake\Utility\Inflector;
+
+/**
+ * This route class will transparently inflect the controller and plugin routing
+ * parameters, so that requesting `/my_controller` is parsed as `['controller' => 'MyController']`
+ */
+class InflectedRoute extends Route {
+
+/**
+ * Parses a string URL into an array. If it mathes, it will convert the prefix, controller and
+ * plugin keys to their camelized form
+ *
+ * @param string $url The URL to parse
+ * @return mixed false on failure, or an array of request parameters
+ */
+	public function parse($url) {
+		$params = parent::parse($url);
+		if (!$params) {
+			return false;
+		}
+		if (!empty($params['controller'])) {
+			$params['controller'] = Inflector::camelize($params['controller']);
+		}
+		if (!empty($params['plugin'])) {
+			$params['plugin'] = Inflector::camelize($params['plugin']);
+		}
+		if (!empty($params['prefix'])) {
+			$params['prefix'] = Inflector::camelize($params['prefix']);
+		}
+		return $params;
+	}
+
+/**
+ * Underscores the prefix, controller and plugin params before passing them on to the
+ * parent class
+ *
+ * @param array $url Array of parameters to convert to a string.
+ * @param array $context An array of the current request context.
+ *   Contains information such as the current host, scheme, port, and base
+ *   directory.
+ * @return mixed either false or a string URL.
+ */
+	public function match(array $url, array $context = array()) {
+		if (!empty($url['controller'])) {
+			$url['controller'] = Inflector::underscore($url['controller']);
+		}
+		if (!empty($url['plugin'])) {
+			$url['plugin'] = Inflector::underscore($url['plugin']);
+		}
+		if (!empty($url['prefix'])) {
+			$url['prefix'] = Inflector::underscore($url['prefix']);
+		}
+		return parent::match($url, $context);
+	}
+
+}

+ 2 - 2
src/Routing/Route/PluginShortRoute.php

@@ -14,14 +14,14 @@
  */
 namespace Cake\Routing\Route;
 
-use Cake\Routing\Route\Route;
+use Cake\Routing\Route\InflectedRoute;
 
 /**
  * Plugin short route, that copies the plugin param to the controller parameters
  * It is used for supporting /:plugin routes.
  *
  */
-class PluginShortRoute extends Route {
+class PluginShortRoute extends InflectedRoute {
 
 /**
  * Parses a string URL into an array. If a plugin key is found, it will be copied to the

+ 4 - 7
src/Routing/Router.php

@@ -446,12 +446,9 @@ class Router {
 		foreach ((array)$controller as $name) {
 			list($plugin, $name) = pluginSplit($name);
 			$urlName = Inflector::underscore($name);
-
-			if ($plugin) {
-				$plugin = Inflector::underscore($plugin);
-			}
-
+			$pluginUrl = $plugin ? Inflector::underscore($plugin) : null;
 			$prefix = $ext = null;
+
 			if (!empty($options['prefix'])) {
 				$prefix = $options['prefix'];
 			}
@@ -461,10 +458,10 @@ class Router {
 
 			foreach (static::$_resourceMap as $params) {
 				$id = $params['id'] ? ':id' : '';
-				$url = '/' . implode('/', array_filter(array($prefix, $plugin, $urlName, $id)));
+				$url = '/' . implode('/', array_filter(array($prefix, $pluginUrl, $urlName, $id)));
 				$params = array(
 					'plugin' => $plugin,
-					'controller' => $urlName,
+					'controller' => $name,
 					'action' => $params['action'],
 					'[method]' => $params['method'],
 					'_ext' => $ext

+ 2 - 2
src/TestSuite/ControllerTestCase.php

@@ -286,9 +286,9 @@ abstract class ControllerTestCase extends TestCase {
 		if ($this->controller === null && $this->autoMock) {
 			$plugin = '';
 			if (!empty($request->params['plugin'])) {
-				$plugin = Inflector::camelize($request->params['plugin']) . '.';
+				$plugin = $request->params['plugin'] . '.';
 			}
-			$controllerName = Inflector::camelize($request->params['controller']);
+			$controllerName = $request->params['controller'];
 			if (!empty($request->params['prefix'])) {
 				$controllerName = Inflector::camelize($request->params['prefix']) . '/' . $controllerName;
 			}

+ 2 - 1
tests/TestCase/Controller/Component/SessionComponentTest.php

@@ -87,7 +87,8 @@ class SessionComponentTest extends TestCase {
  */
 	public function testSessionIdConsistentAcrossRequestAction() {
 		Configure::write('App.namespace', 'TestApp');
-		Router::connect('/:controller/:action');
+		Router::connect('/session_test/:action', ['controller' => 'SessionTest']);
+		Router::connect('/orange_session_test/:action', ['controller' => 'OrangeSessionTest']);
 
 		$Controller = new Controller();
 		$Session = new SessionComponent($this->ComponentRegistry);

+ 6 - 6
tests/TestCase/Routing/DispatcherTest.php

@@ -322,7 +322,7 @@ class DispatcherTest extends TestCase {
 		$request = new Request([
 			'url' => 'some_pages/responseGenerator',
 			'params' => [
-				'controller' => 'some_pages',
+				'controller' => 'SomePages',
 				'action' => 'responseGenerator',
 				'pass' => []
 			]
@@ -345,8 +345,8 @@ class DispatcherTest extends TestCase {
 		$request = new Request([
 			'url' => 'admin/posts/index',
 			'params' => [
-				'prefix' => 'admin',
-				'controller' => 'posts',
+				'prefix' => 'Admin',
+				'controller' => 'Posts',
 				'action' => 'index',
 				'pass' => [],
 				'return' => 1
@@ -375,9 +375,9 @@ class DispatcherTest extends TestCase {
 		$request = new Request([
 			'url' => 'admin/test_plugin/comments/index',
 			'params' => [
-				'plugin' => 'test_plugin',
-				'prefix' => 'admin',
-				'controller' => 'comments',
+				'plugin' => 'TestPlugin',
+				'prefix' => 'Admin',
+				'controller' => 'Comments',
 				'action' => 'index',
 				'pass' => [],
 				'return' => 1

+ 2 - 4
tests/TestCase/Routing/Filter/CacheFilterTest.php

@@ -63,9 +63,7 @@ class CacheFilterTest extends TestCase {
 		return array(
 			array('/'),
 			array('test_cached_pages/index'),
-			array('TestCachedPages/index'),
 			array('test_cached_pages/test_nocache_tags'),
-			array('TestCachedPages/test_nocache_tags'),
 			array('test_cached_pages/view/param/param'),
 			array('test_cached_pages/view?q=cakephp'),
 		);
@@ -84,8 +82,8 @@ class CacheFilterTest extends TestCase {
 		Configure::write('debug', true);
 
 		Router::reload();
-		Router::connect('/', array('controller' => 'test_cached_pages', 'action' => 'index'));
-		Router::connect('/:controller/:action/*');
+		Router::connect('/', array('controller' => 'TestCachedPages', 'action' => 'index'));
+		Router::connect('/test_cached_pages/:action/*', ['controller' => 'TestCachedPages']);
 
 		$dispatcher = new Dispatcher();
 		$dispatcher->addFilter(new RoutingFilter());

+ 20 - 18
tests/TestCase/Routing/RequestActionTraitTest.php

@@ -44,6 +44,8 @@ class RequestActionTraitTest extends TestCase {
 		DispatcherFactory::add('Routing');
 		DispatcherFactory::add('ControllerFactory');
 		$this->object = $this->getObjectForTrait('Cake\Routing\RequestActionTrait');
+		Router::connect('/request_action/:action/*', ['controller' => 'RequestAction']);
+		Router::connect('/tests_apps/:action/*', ['controller' => 'TestsApps']);
 	}
 
 /**
@@ -54,6 +56,7 @@ class RequestActionTraitTest extends TestCase {
 	public function tearDown() {
 		parent::tearDown();
 		DispatcherFactory::clear();
+		Router::reload();
 	}
 
 /**
@@ -105,6 +108,7 @@ class RequestActionTraitTest extends TestCase {
 	public function testRequestActionPlugins() {
 		Plugin::load('TestPlugin');
 		Router::reload();
+		Router::connect('/test_plugin/tests/:action/*', ['controller' => 'Tests', 'plugin' => 'TestPlugin']);
 
 		$result = $this->object->requestAction('/test_plugin/tests/index', array('return'));
 		$expected = 'test plugin index';
@@ -115,7 +119,7 @@ class RequestActionTraitTest extends TestCase {
 		$this->assertEquals($expected, $result);
 
 		$result = $this->object->requestAction(
-			array('controller' => 'tests', 'action' => 'index', 'plugin' => 'test_plugin'), array('return')
+			array('controller' => 'Tests', 'action' => 'index', 'plugin' => 'TestPlugin'), array('return')
 		);
 		$expected = 'test plugin index';
 		$this->assertEquals($expected, $result);
@@ -125,7 +129,7 @@ class RequestActionTraitTest extends TestCase {
 		$this->assertEquals($expected, $result);
 
 		$result = $this->object->requestAction(
-			array('controller' => 'tests', 'action' => 'some_method', 'plugin' => 'test_plugin')
+			array('controller' => 'Tests', 'action' => 'some_method', 'plugin' => 'TestPlugin')
 		);
 		$expected = 25;
 		$this->assertEquals($expected, $result);
@@ -140,41 +144,41 @@ class RequestActionTraitTest extends TestCase {
 		Plugin::load(array('TestPlugin'));
 
 		$result = $this->object->requestAction(
-			array('controller' => 'request_action', 'action' => 'test_request_action')
+			array('controller' => 'RequestAction', 'action' => 'test_request_action')
 		);
 		$expected = 'This is a test';
 		$this->assertEquals($expected, $result);
 
 		$result = $this->object->requestAction(
-			array('controller' => 'request_action', 'action' => 'another_ra_test'),
+			array('controller' => 'RequestAction', 'action' => 'another_ra_test'),
 			array('pass' => array('5', '7'))
 		);
 		$expected = 12;
 		$this->assertEquals($expected, $result);
 
 		$result = $this->object->requestAction(
-			array('controller' => 'tests_apps', 'action' => 'index'), array('return')
+			array('controller' => 'TestsApps', 'action' => 'index'), array('return')
 		);
 		$expected = 'This is the TestsAppsController index view ';
 		$this->assertEquals($expected, $result);
 
-		$result = $this->object->requestAction(array('controller' => 'tests_apps', 'action' => 'some_method'));
+		$result = $this->object->requestAction(array('controller' => 'TestsApps', 'action' => 'some_method'));
 		$expected = 5;
 		$this->assertEquals($expected, $result);
 
 		$result = $this->object->requestAction(
-			array('controller' => 'request_action', 'action' => 'normal_request_action')
+			array('controller' => 'RequestAction', 'action' => 'normal_request_action')
 		);
 		$expected = 'Hello World';
 		$this->assertEquals($expected, $result);
 
 		$result = $this->object->requestAction(
-			array('controller' => 'request_action', 'action' => 'paginate_request_action')
+			array('controller' => 'RequestAction', 'action' => 'paginate_request_action')
 		);
 		$this->assertNull($result);
 
 		$result = $this->object->requestAction(
-			array('controller' => 'request_action', 'action' => 'paginate_request_action'),
+			array('controller' => 'RequestAction', 'action' => 'paginate_request_action'),
 			array('pass' => array(5))
 		);
 		$this->assertNull($result);
@@ -201,7 +205,7 @@ class RequestActionTraitTest extends TestCase {
 		$result = $this->object->requestAction('/request_action/params_pass');
 		$result = json_decode($result, true);
 		$this->assertEquals('request_action/params_pass', $result['url']);
-		$this->assertEquals('request_action', $result['params']['controller']);
+		$this->assertEquals('RequestAction', $result['params']['controller']);
 		$this->assertEquals('params_pass', $result['params']['action']);
 		$this->assertNull($result['params']['plugin']);
 	}
@@ -216,12 +220,12 @@ class RequestActionTraitTest extends TestCase {
 		$_POST = array(
 			'item' => 'value'
 		);
-		$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'));
+		$result = $this->object->requestAction(array('controller' => 'RequestAction', 'action' => 'post_pass'));
 		$result = json_decode($result, true);
 		$this->assertEmpty($result);
 
 		$result = $this->object->requestAction(
-			array('controller' => 'request_action', 'action' => 'post_pass'),
+			array('controller' => 'RequestAction', 'action' => 'post_pass'),
 			array('post' => $_POST)
 		);
 		$result = json_decode($result, true);
@@ -235,18 +239,16 @@ class RequestActionTraitTest extends TestCase {
  * @return void
  */
 	public function testRequestActionWithQueryString() {
-		Router::reload();
-		require CAKE . 'Config/routes.php';
 		$query = ['page' => 1, 'sort' => 'title'];
 		$result = $this->object->requestAction(
-			['controller' => 'request_action', 'action' => 'query_pass'],
+			['controller' => 'RequestAction', 'action' => 'query_pass'],
 			['query' => $query]
 		);
 		$result = json_decode($result, true);
 		$this->assertEquals($query, $result);
 
 		$result = $this->object->requestAction([
-			'controller' => 'request_action',
+			'controller' => 'RequestAction',
 			'action' => 'query_pass',
 			'?' => $query
 		]);
@@ -271,7 +273,7 @@ class RequestActionTraitTest extends TestCase {
 			'Post' => array('id' => 2)
 		);
 		$result = $this->object->requestAction(
-			array('controller' => 'request_action', 'action' => 'post_pass'),
+			array('controller' => 'RequestAction', 'action' => 'post_pass'),
 			array('post' => $data)
 		);
 		$result = json_decode($result, true);
@@ -298,7 +300,7 @@ class RequestActionTraitTest extends TestCase {
 		$this->assertEquals('value', $result['query']['get']);
 
 		$result = $this->object->requestAction(
-			array('controller' => 'request_action', 'action' => 'params_pass'),
+			array('controller' => 'RequestAction', 'action' => 'params_pass'),
 			array('query' => array('get' => 'value', 'limit' => 5))
 		);
 		$result = json_decode($result, true);

+ 2 - 2
tests/TestCase/Routing/Route/PluginShortRouteTest.php

@@ -46,8 +46,8 @@ class PluginShortRouteTest extends TestCase {
 		$route = new PluginShortRoute('/:plugin', array('action' => 'index'), array('plugin' => 'foo|bar'));
 
 		$result = $route->parse('/foo');
-		$this->assertEquals('foo', $result['plugin']);
-		$this->assertEquals('foo', $result['controller']);
+		$this->assertEquals('Foo', $result['plugin']);
+		$this->assertEquals('Foo', $result['controller']);
 		$this->assertEquals('index', $result['action']);
 
 		$result = $route->parse('/wrong');

+ 36 - 35
tests/TestCase/Routing/RouterTest.php

@@ -38,7 +38,6 @@ class RouterTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 		Configure::write('Routing', array('admin' => null, 'prefixes' => []));
-		Router::reload();
 		Router::fullbaseUrl('');
 		Configure::write('App.fullBaseUrl', 'http://localhost');
 	}
@@ -53,6 +52,7 @@ class RouterTest extends TestCase {
 		Plugin::unload();
 		Router::fullBaseUrl('');
 		Configure::write('App.fullBaseUrl', 'http://localhost');
+		Router::reload();
 	}
 
 /**
@@ -114,7 +114,7 @@ class RouterTest extends TestCase {
 		$expected = [
 			'pass' => [],
 			'plugin' => null,
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'index',
 			'[method]' => 'GET',
 			'_ext' => null
@@ -127,7 +127,7 @@ class RouterTest extends TestCase {
 		$expected = [
 			'pass' => ['13'],
 			'plugin' => null,
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'view',
 			'id' => '13',
 			'[method]' => 'GET',
@@ -140,7 +140,7 @@ class RouterTest extends TestCase {
 		$expected = [
 			'pass' => [],
 			'plugin' => null,
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'add',
 			'[method]' => 'POST',
 			'_ext' => null
@@ -152,7 +152,7 @@ class RouterTest extends TestCase {
 		$expected = [
 			'pass' => ['13'],
 			'plugin' => null,
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'edit',
 			'id' => '13',
 			'[method]' => 'PUT',
@@ -164,7 +164,7 @@ class RouterTest extends TestCase {
 		$expected = [
 			'pass' => ['475acc39-a328-44d3-95fb-015000000000'],
 			'plugin' => null,
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'edit',
 			'id' => '475acc39-a328-44d3-95fb-015000000000',
 			'[method]' => 'PUT',
@@ -177,7 +177,7 @@ class RouterTest extends TestCase {
 		$expected = [
 			'pass' => ['13'],
 			'plugin' => null,
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'delete',
 			'id' => '13',
 			'[method]' => 'DELETE',
@@ -198,7 +198,7 @@ class RouterTest extends TestCase {
 		$expected = [
 			'pass' => ['add'],
 			'plugin' => null,
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'view',
 			'id' => 'add',
 			'[method]' => 'GET',
@@ -211,7 +211,7 @@ class RouterTest extends TestCase {
 		$expected = [
 			'pass' => ['name'],
 			'plugin' => null,
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'edit',
 			'id' => 'name',
 			'[method]' => 'PUT',
@@ -233,8 +233,8 @@ class RouterTest extends TestCase {
 		$result = Router::parse('/test_plugin/test_plugin');
 		$expected = array(
 			'pass' => [],
-			'plugin' => 'test_plugin',
-			'controller' => 'test_plugin',
+			'plugin' => 'TestPlugin',
+			'controller' => 'TestPlugin',
 			'action' => 'index',
 			'[method]' => 'GET',
 			'_ext' => null
@@ -246,8 +246,8 @@ class RouterTest extends TestCase {
 		$result = Router::parse('/test_plugin/test_plugin/13');
 		$expected = array(
 			'pass' => array('13'),
-			'plugin' => 'test_plugin',
-			'controller' => 'test_plugin',
+			'plugin' => 'TestPlugin',
+			'controller' => 'TestPlugin',
 			'action' => 'view',
 			'id' => '13',
 			'[method]' => 'GET',
@@ -270,7 +270,7 @@ class RouterTest extends TestCase {
 
 		$expected = array(
 			'plugin' => null,
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'index',
 			'pass' => [],
 			'prefix' => 'api',
@@ -294,7 +294,7 @@ class RouterTest extends TestCase {
 
 		$expected = array(
 			'plugin' => null,
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'index',
 			'pass' => [],
 			'[method]' => 'GET',
@@ -361,8 +361,8 @@ class RouterTest extends TestCase {
 		$result = Router::parse('/api/test_plugin/test_plugin');
 		$expected = array(
 			'pass' => [],
-			'plugin' => 'test_plugin',
-			'controller' => 'test_plugin',
+			'plugin' => 'TestPlugin',
+			'controller' => 'TestPlugin',
 			'prefix' => 'api',
 			'action' => 'index',
 			'[method]' => 'GET',
@@ -378,7 +378,7 @@ class RouterTest extends TestCase {
 		$expected = array(
 			'pass' => [],
 			'plugin' => null,
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'index',
 			'[method]' => 'GET',
 			'prefix' => 'api',
@@ -427,7 +427,7 @@ class RouterTest extends TestCase {
 		Router::mapResources('Posts');
 
 		$result = Router::url([
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'index',
 			'[method]' => 'GET'
 		]);
@@ -435,7 +435,7 @@ class RouterTest extends TestCase {
 		$this->assertEquals($expected, $result);
 
 		$result = Router::url([
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'view',
 			'[method]' => 'GET',
 			'id' => 10
@@ -443,19 +443,19 @@ class RouterTest extends TestCase {
 		$expected = '/posts/10';
 		$this->assertEquals($expected, $result);
 
-		$result = Router::url(['controller' => 'posts', 'action' => 'add', '[method]' => 'POST']);
+		$result = Router::url(['controller' => 'Posts', 'action' => 'add', '[method]' => 'POST']);
 		$expected = '/posts';
 		$this->assertEquals($expected, $result);
 
-		$result = Router::url(['controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT', 'id' => 10]);
+		$result = Router::url(['controller' => 'Posts', 'action' => 'edit', '[method]' => 'PUT', 'id' => 10]);
 		$expected = '/posts/10';
 		$this->assertEquals($expected, $result);
 
-		$result = Router::url(['controller' => 'posts', 'action' => 'delete', '[method]' => 'DELETE', 'id' => 10]);
+		$result = Router::url(['controller' => 'Posts', 'action' => 'delete', '[method]' => 'DELETE', 'id' => 10]);
 		$expected = '/posts/10';
 		$this->assertEquals($expected, $result);
 
-		$result = Router::url(['controller' => 'posts', 'action' => 'edit', '[method]' => 'POST', 'id' => 10]);
+		$result = Router::url(['controller' => 'Posts', 'action' => 'edit', '[method]' => 'POST', 'id' => 10]);
 		$expected = '/posts/10';
 		$this->assertEquals($expected, $result);
 	}
@@ -1191,7 +1191,7 @@ class RouterTest extends TestCase {
 
 		Router::connect(
 			'/posts/:value/:somevalue/:othervalue/*',
-			array('controller' => 'posts', 'action' => 'view'),
+			array('controller' => 'Posts', 'action' => 'view'),
 			array('value', 'somevalue', 'othervalue')
 		);
 		$result = Router::parse('/posts/2007/08/01/title-of-post-here');
@@ -1199,7 +1199,7 @@ class RouterTest extends TestCase {
 			'value' => '2007',
 			'somevalue' => '08',
 			'othervalue' => '01',
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'view',
 			'plugin' => null,
 			'pass' => array('0' => 'title-of-post-here')
@@ -1283,7 +1283,7 @@ class RouterTest extends TestCase {
 		$expected = array(
 			'plugin' => null,
 			'pass' => array('home'),
-			'controller' => 'pages',
+			'controller' => 'Pages',
 			'action' => 'display'
 		);
 		$this->assertEquals($expected, $result);
@@ -1507,6 +1507,7 @@ class RouterTest extends TestCase {
  * @dataProvider parseReverseSymmetryData
  */
 	public function testParseReverseSymmetry($url) {
+		require CAKE . 'Config/routes.php';
 		$this->assertSame($url, Router::reverse(Router::parse($url) + array('url' => [])));
 	}
 
@@ -1674,7 +1675,7 @@ class RouterTest extends TestCase {
 		$result = Router::parse('/posts.rss');
 		$expected = array(
 			'plugin' => null,
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'index',
 			'_ext' => 'rss',
 			'pass' => []
@@ -1684,7 +1685,7 @@ class RouterTest extends TestCase {
 		$result = Router::parse('/posts/view/1.rss');
 		$expected = array(
 			'plugin' => null,
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'view',
 			'pass' => array('1'),
 			'_ext' => 'rss'
@@ -1702,7 +1703,7 @@ class RouterTest extends TestCase {
 		$result = Router::parse('/posts.xml');
 		$expected = array(
 			'plugin' => null,
-			'controller' => 'posts',
+			'controller' => 'Posts',
 			'action' => 'index',
 			'_ext' => 'xml',
 			'pass' => []
@@ -1712,7 +1713,7 @@ class RouterTest extends TestCase {
 		$result = Router::parse('/posts.atom?hello=goodbye');
 		$expected = array(
 			'plugin' => null,
-			'controller' => 'posts.atom',
+			'controller' => 'Posts.atom',
 			'action' => 'index',
 			'pass' => [],
 			'?' => array('hello' => 'goodbye')
@@ -2326,12 +2327,12 @@ class RouterTest extends TestCase {
 		Router::reload();
 		require CAKE . 'Config/routes.php';
 
-		$result = Router::url(array('plugin' => 'plugin_js', 'controller' => 'js_file', 'action' => 'index'));
+		$result = Router::url(array('plugin' => 'PluginJs', 'controller' => 'JsFile', 'action' => 'index'));
 		$this->assertEquals('/plugin_js/js_file', $result);
 
 		$result = Router::parse('/plugin_js/js_file');
 		$expected = array(
-			'plugin' => 'plugin_js', 'controller' => 'js_file', 'action' => 'index',
+			'plugin' => 'PluginJs', 'controller' => 'JsFile', 'action' => 'index',
 			'pass' => []
 		);
 		$this->assertEquals($expected, $result);
@@ -2341,8 +2342,8 @@ class RouterTest extends TestCase {
 
 		$result = Router::parse('/test_plugin');
 		$expected = array(
-			'plugin' => 'test_plugin',
-			'controller' => 'test_plugin',
+			'plugin' => 'TestPlugin',
+			'controller' => 'TestPlugin',
 			'action' => 'index',
 			'pass' => []
 		);

+ 1 - 24
tests/TestCase/TestSuite/ControllerTestCaseTest.php

@@ -52,6 +52,7 @@ class ControllerTestCaseTest extends TestCase {
 		DispatcherFactory::add('Routing');
 		DispatcherFactory::add('ControllerFactory');
 		Router::reload();
+		require CAKE . 'Config/routes.php';
 		TableRegistry::clear();
 	}
 
@@ -228,36 +229,12 @@ class ControllerTestCaseTest extends TestCase {
 	}
 
 /**
- * Tests using loaded routes during tests
- *
- * @return void
- */
-	public function testUseRoutes() {
-		Router::connect('/:controller/:action/*');
-		include APP . '/Config/routes.php';
-
-		$controller = $this->Case->generate('TestsApps');
-		$controller->components()->load('RequestHandler');
-		$result = $this->Case->testAction('/tests_apps/index.json', array('return' => 'contents'));
-		$result = json_decode($result, true);
-		$expected = array('cakephp' => 'cool');
-		$this->assertEquals($expected, $result);
-
-		include APP . '/Config/routes.php';
-		$result = $this->Case->testAction('/some_alias');
-		$this->assertEquals(5, $result);
-	}
-
-/**
  * Tests not using loaded routes during tests
  *
  * @expectedException \Cake\Controller\Error\MissingActionException
  * @return void
  */
 	public function testSkipRoutes() {
-		Router::connect('/:controller/:action/*');
-		include APP . 'Config/routes.php';
-
 		$this->Case->loadRoutes = false;
 		$this->Case->testAction('/tests_apps/missing_action.json', array('return' => 'view'));
 	}