Permalink
Browse files

Updating AuthComponent's mapped actions features to use Router::prefi…

…xes()

Adding tests for prefix interactions.
Adding tests for AuthComponent::logout, increasing code coverage.
  • Loading branch information...
1 parent 76780ab commit ecea49f8239b901a28f57f6cf08f1c8d14bee968 @markstory markstory committed Dec 9, 2009
Showing with 54 additions and 16 deletions.
  1. +15 −13 cake/libs/controller/components/auth.php
  2. +39 −3 cake/tests/cases/libs/controller/components/auth.test.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');
@@ -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'));
+ }
}
?>

0 comments on commit ecea49f

Please sign in to comment.