diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index b14c766e4a9..e05cdc8d867 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -259,19 +259,21 @@ function initialize(&$controller) { $this->actionMap = array_merge($this->actionMap, array_combine($crud, $crud)); $this->_methods = $controller->methods; - $admin = Configure::read('Routing.admin'); - if (!empty($admin)) { - $this->actionMap = array_merge($this->actionMap, array( - $admin . '_index' => 'read', - $admin . '_add' => 'create', - $admin . '_edit' => 'update', - $admin . '_view' => 'read', - $admin . '_remove' => 'delete', - $admin . '_create' => 'create', - $admin . '_read' => 'read', - $admin . '_update' => 'update', - $admin . '_delete' => 'delete' - )); + $prefixes = Router::prefixes(); + if (!empty($prefixes)) { + foreach ($prefixes as $prefix) { + $this->actionMap = array_merge($this->actionMap, array( + $prefix . '_index' => 'read', + $prefix . '_add' => 'create', + $prefix . '_edit' => 'update', + $prefix . '_view' => 'read', + $prefix . '_remove' => 'delete', + $prefix . '_create' => 'create', + $prefix . '_read' => 'read', + $prefix . '_update' => 'update', + $prefix . '_delete' => 'delete' + )); + } } if (Configure::read() > 0) { App::import('Debugger'); diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index dfde56d69e5..664da4b0fc9 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -1330,8 +1330,8 @@ function testCustomField() { * @return void */ function testAdminRoute() { - $admin = Configure::read('Routing.admin'); - Configure::write('Routing.admin', 'admin'); + $prefixes = Configure::read('Routing.prefixes'); + Configure::write('Routing.prefixes', array('admin')); Router::reload(); $url = '/admin/auth_test/add'; @@ -1358,7 +1358,7 @@ function testAdminRoute() { $this->Controller->Auth->startup($this->Controller); $this->assertEqual($this->Controller->testUrl, '/admin/auth_test/login'); - Configure::write('Routing.admin', $admin); + Configure::write('Routing.prefixes', $prefixes); } /** @@ -1479,5 +1479,41 @@ function testShutDown() { $this->Controller->Auth->shutdown($this->Controller); $this->assertFalse($this->Controller->Session->read('Auth.redirect')); } + +/** + * test the initialize callback and its interactions with Router::prefixes() + * + * @return void + */ + function testInitializeAndRoutingPrefixes() { + $restore = Configure::read('Routing'); + Configure::write('Routing.prefixes', array('admin', 'super_user')); + Router::reload(); + $this->Controller->Auth->initialize($this->Controller); + + $this->assertTrue(isset($this->Controller->Auth->actionMap['delete'])); + $this->assertTrue(isset($this->Controller->Auth->actionMap['view'])); + $this->assertTrue(isset($this->Controller->Auth->actionMap['add'])); + $this->assertTrue(isset($this->Controller->Auth->actionMap['admin_view'])); + $this->assertTrue(isset($this->Controller->Auth->actionMap['super_user_delete'])); + + Configure::write('Routing', $restore); + } + +/** + * test that logout deletes the session variables. and returns the correct url + * + * @return void + */ + function testLogout() { + $this->Controller->Session->write('Auth.User.id', '1'); + $this->Controller->Session->write('Auth.redirect', '/users/login'); + $this->Controller->Auth->logoutRedirect = '/'; + $result = $this->Controller->Auth->logout(); + + $this->assertEqual($result, '/'); + $this->assertNull($this->Controller->Session->read('Auth.AuthUser')); + $this->assertNull($this->Controller->Session->read('Auth.redirect')); + } } ?> \ No newline at end of file