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->actionMap = array_merge($this->actionMap, array_combine($crud, $crud));
|
||||||
$this->_methods = $controller->methods;
|
$this->_methods = $controller->methods;
|
||||||
|
|
||||||
$admin = Configure::read('Routing.admin');
|
$prefixes = Router::prefixes();
|
||||||
if (!empty($admin)) {
|
if (!empty($prefixes)) {
|
||||||
$this->actionMap = array_merge($this->actionMap, array(
|
foreach ($prefixes as $prefix) {
|
||||||
$admin . '_index' => 'read',
|
$this->actionMap = array_merge($this->actionMap, array(
|
||||||
$admin . '_add' => 'create',
|
$prefix . '_index' => 'read',
|
||||||
$admin . '_edit' => 'update',
|
$prefix . '_add' => 'create',
|
||||||
$admin . '_view' => 'read',
|
$prefix . '_edit' => 'update',
|
||||||
$admin . '_remove' => 'delete',
|
$prefix . '_view' => 'read',
|
||||||
$admin . '_create' => 'create',
|
$prefix . '_remove' => 'delete',
|
||||||
$admin . '_read' => 'read',
|
$prefix . '_create' => 'create',
|
||||||
$admin . '_update' => 'update',
|
$prefix . '_read' => 'read',
|
||||||
$admin . '_delete' => 'delete'
|
$prefix . '_update' => 'update',
|
||||||
));
|
$prefix . '_delete' => 'delete'
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (Configure::read() > 0) {
|
if (Configure::read() > 0) {
|
||||||
App::import('Debugger');
|
App::import('Debugger');
|
||||||
|
|
|
@ -1330,8 +1330,8 @@ class AuthTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testAdminRoute() {
|
function testAdminRoute() {
|
||||||
$admin = Configure::read('Routing.admin');
|
$prefixes = Configure::read('Routing.prefixes');
|
||||||
Configure::write('Routing.admin', 'admin');
|
Configure::write('Routing.prefixes', array('admin'));
|
||||||
Router::reload();
|
Router::reload();
|
||||||
|
|
||||||
$url = '/admin/auth_test/add';
|
$url = '/admin/auth_test/add';
|
||||||
|
@ -1358,7 +1358,7 @@ class AuthTest extends CakeTestCase {
|
||||||
$this->Controller->Auth->startup($this->Controller);
|
$this->Controller->Auth->startup($this->Controller);
|
||||||
$this->assertEqual($this->Controller->testUrl, '/admin/auth_test/login');
|
$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->Controller->Auth->shutdown($this->Controller);
|
||||||
$this->assertFalse($this->Controller->Session->read('Auth.redirect'));
|
$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