diff --git a/system/Router/Router.php b/system/Router/Router.php index f6b841041d..c0f79684b1 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -241,7 +241,7 @@ class Router implements RouterInterface $segments = $this->validateRequest($segments); - // If we don't have aany segments left - try the default controller; + // If we don't have any segments left - try the default controller; // WARNING: Directories get shifted out of tge segments array. if (empty($segments)) { diff --git a/tests/Router/RouterTest.php b/tests/Router/RouterTest.php index 1076ea3eb7..57ad098cd2 100644 --- a/tests/Router/RouterTest.php +++ b/tests/Router/RouterTest.php @@ -1,6 +1,10 @@ collection = new \CodeIgniter\Router\RouteCollection(); @@ -25,6 +35,8 @@ class RouterTest extends PHPUnit_Framework_TestCase ]; $this->collection->map($routes); + + $this->root = vfsStream::setup(APPPATH.'controllers'); } //-------------------------------------------------------------------- @@ -134,4 +146,44 @@ class RouterTest extends PHPUnit_Framework_TestCase } //-------------------------------------------------------------------- + + public function testAutoRouteFindsControllerWithFileAndMethod() + { + $router = new Router($this->collection); + + $router->autoRoute('myController/someMethod'); + + $this->assertEquals('MyController', $router->controllerName()); + $this->assertEquals('someMethod', $router->methodName()); + } + + //-------------------------------------------------------------------- + + public function testAutoRouteFindsControllerWithFile() + { + $router = new Router($this->collection); + + $router->autoRoute('myController'); + + $this->assertEquals('MyController', $router->controllerName()); + $this->assertEquals('index', $router->methodName()); + } + + //-------------------------------------------------------------------- + + public function testAutoRouteFindsControllerWithSubfolder() + { + $router = new Router($this->collection); + + mkdir(APPPATH.'controllers/subfolder'); + + $router->autoRoute('subfolder/myController/someMethod'); + + rmdir(APPPATH.'controllers/subfolder'); + + $this->assertEquals('MyController', $router->controllerName()); + $this->assertEquals('someMethod', $router->methodName()); + } + + //-------------------------------------------------------------------- } \ No newline at end of file