mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Updating AuthComponent's mapped actions features to use Router::prefixes()
Adding tests for prefix interactions. Adding tests for AuthComponent::logout, increasing code coverage.
This commit is contained in:
parent
76780ab99c
commit
ecea49f823
2 changed files with 54 additions and 16 deletions
|
@ -259,19 +259,21 @@ class AuthComponent extends Object {
|
|||
$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 @@ class AuthTest extends CakeTestCase {
|
|||
* @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 @@ class AuthTest extends CakeTestCase {
|
|||
$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 @@ class AuthTest extends CakeTestCase {
|
|||
$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'));
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue