Skip to content

Commit

Permalink
Updating AuthComponent's mapped actions features to use Router::prefi…
Browse files Browse the repository at this point in the history
…xes()

Adding tests for prefix interactions.
Adding tests for AuthComponent::logout, increasing code coverage.
  • Loading branch information
markstory committed Dec 9, 2009
1 parent 76780ab commit ecea49f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 16 deletions.
28 changes: 15 additions & 13 deletions cake/libs/controller/components/auth.php
Expand Up @@ -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');
Expand Down
42 changes: 39 additions & 3 deletions cake/tests/cases/libs/controller/components/auth.test.php
Expand Up @@ -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';
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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.