Permalink
Browse files

Adding omitted default route, and test cases to test its functionality.

Fixes #212
  • Loading branch information...
1 parent 24c0883 commit 06ba7ac828afec12efc2972737768b6ce136861d @markstory markstory committed Jan 18, 2010
Showing with 29 additions and 1 deletion.
  1. +2 −0 cake/libs/router.php
  2. +27 −1 cake/tests/cases/libs/router.test.php
View
@@ -278,6 +278,7 @@ function connect($route, $defaults = array(), $options = array()) {
$routeClass = $options['routeClass'];
unset($options['routeClass']);
}
+ //TODO 2.0 refactor this to use a string class name, throw exception, and then construct.
$Route =& new $routeClass($route, $defaults, $options);
if ($routeClass !== 'CakeRoute' && !is_subclass_of($Route, 'CakeRoute')) {
trigger_error(__('Route classes must extend CakeRoute', true), E_USER_WARNING);
@@ -539,6 +540,7 @@ function __connectDefaultRoutes() {
$this->connect("/{$prefix}/:plugin/:controller", $indexParams, $match);
$this->connect("/{$prefix}/:plugin/:controller/:action/*", $params, $match);
}
+ $this->connect('/:plugin/:controller', array('action' => 'index'), $match);
$this->connect('/:plugin/:controller/:action/*', array(), $match);
}
@@ -1849,7 +1849,7 @@ function testStripPlugin() {
* @return void
* @access public
*/
- function testCurentRoute() {
+ function testCurrentRoute() {
$url = array('controller' => 'pages', 'action' => 'display', 'government');
Router::connect('/government', $url);
Router::parse('/government');
@@ -1925,6 +1925,32 @@ function testDefaultsMethod() {
}
/**
+ * test that the required default routes are connected.
+ *
+ * @return void
+ */
+ function testConnectDefaultRoutes() {
+ App::build(array(
+ 'plugins' => array(
+ TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS
+ )
+ ), true);
+ App::objects('plugin', null, false);
+
+ $plugins = App::objects('plugin');
+ $plugin = Inflector::underscore($plugins[0]);
+ $result = Router::url(array('plugin' => $plugin, 'controller' => 'js_file', 'action' => 'index'));
+ $this->assertEqual($result, '/plugin_js/js_file');
+
+ $result = Router::parse('/plugin_js/js_file');
+ $expected = array(
+ 'plugin' => 'plugin_js', 'controller' => 'js_file', 'action' => 'index',
+ 'named' => array(), 'pass' => array()
+ );
+ $this->assertEqual($result, $expected);
+ }
+
+/**
* test using a custom route class for route connection
*
* @return void

0 comments on commit 06ba7ac

Please sign in to comment.