f3252e75aad3f82e1322481a2a064427def1dbc9
Author: Phally
Date: 2009-08-21 11:28:32 +0200
diff --git a/plugins/users/controllers/components/access.php b/plugins/users/controllers/components/access.php
index 925f2d7..fdeae61 100755
--- a/plugins/users/controllers/components/access.php
+++ b/plugins/users/controllers/components/access.php
@@ -280,6 +280,7 @@ class AccessComponent extends Object {
$auth->userModel = $this->userModel;
$auth->authorize = 'object';
$auth->object = $auth->authenticate = $this;
+ $auth->loginAction = array('plugin' => 'users', 'controller' => 'users', 'action' => 'login');
if (!$auth->user()) {
$auth->authError = __('You need to login first.', true);
diff --git a/plugins/users/tests/cases/helpers/auth.test.php b/plugins/users/tests/cases/helpers/auth.test.php
index 83c1a61..c106e11 100755
--- a/plugins/users/tests/cases/helpers/auth.test.php
+++ b/plugins/users/tests/cases/helpers/auth.test.php
@@ -1,47 +1,40 @@
<?php
-App::import('Controller', 'Users.AppController');
-App::import('Helper', 'Users.Auth');
-App::import('Helper', 'Session');
-
-class FakeController extends UsersAppController {
- public $helpers = array('Auth');
- public $uses = array();
-}
-
class AuthHelperTestCase extends CakeTestCase {
- private $Controller = null;
private $Auth = null;
+ public function startCase() {
+ App::import('Helper', 'Users.Auth');
+ App::import('Helper', 'Session');
+ Mock::generate('SessionHelper');
+ }
+
public function startTest($method) {
- parent::startTest($method);
$this->Auth = new AuthHelper();
- $this->Auth->Session = new SessionHelper();
- $this->Controller = new FakeController();
- $this->Controller->constructClasses();
- $this->Controller->Session->delete('Auth.User');
+ $this->Auth->Session = new MockSessionHelper();
}
public function testHelperInstances() {
$this->assertIsA($this->Auth, 'AuthHelper');
- $this->assertIsA($this->Auth->Session, 'SessionHelper');
}
public function testLoggedOnNotSignedInUser() {
+ $this->Auth->Session->setReturnValue('check', false);
+ $this->Auth->Session->setReturnValue('read', null);
$this->Auth->beforeRender();
$this->assertFalse($this->Auth->logged());
}
public function testLoggedOnSignedInUser() {
- $this->Controller->Session->write('Auth.User', array(
- 'username' => 'Phally',
- 'group_id' => 100)
- );
+ $this->Auth->Session->setReturnValue('check', true);
+ $this->Auth->Session->setReturnValue('read', 100);
$this->Auth->beforeRender();
$this->assertTrue($this->Auth->logged());
}
public function testVisibilityOnNotSignedInUser() {
+ $this->Auth->Session->setReturnValue('check', false);
+ $this->Auth->Session->setReturnValue('read', null);
$this->Auth->beforeRender();
$this->assertFalse($this->Auth->visible(10));
$this->assertFalse($this->Auth->visible(50));
@@ -49,10 +42,8 @@ class AuthHelperTestCase extends CakeTestCase {
}
public function testVisibilityOnMemberUser() {
- $this->Controller->Session->write('Auth.User', array(
- 'group_id' => 10
- ));
-
+ $this->Auth->Session->setReturnValue('check', true);
+ $this->Auth->Session->setReturnValue('read', 10);
$this->Auth->beforeRender();
$this->assertTrue($this->Auth->visible(10));
$this->assertFalse($this->Auth->visible(50));
@@ -60,10 +51,8 @@ class AuthHelperTestCase extends CakeTestCase {
}
public function testVisibilityOnModeratorUser() {
- $this->Controller->Session->write('Auth.User', array(
- 'group_id' => 50
- ));
-
+ $this->Auth->Session->setReturnValue('check', true);
+ $this->Auth->Session->setReturnValue('read', 50);
$this->Auth->beforeRender();
$this->assertTrue($this->Auth->visible(10));
$this->assertTrue($this->Auth->visible(50));
@@ -71,10 +60,8 @@ class AuthHelperTestCase extends CakeTestCase {
}
public function testVisibilityOnAdministratorUser() {
- $this->Controller->Session->write('Auth.User', array(
- 'group_id' => 100
- ));
-
+ $this->Auth->Session->setReturnValue('check', true);
+ $this->Auth->Session->setReturnValue('read', 100);
$this->Auth->beforeRender();
$this->assertTrue($this->Auth->visible(10));
$this->assertTrue($this->Auth->visible(50));
@@ -92,30 +79,20 @@ class AuthHelperTestCase extends CakeTestCase {
}
public function testUserOnSignedInUser() {
- $this->Controller->Session->write('Auth.User', array(
- 'username' => 'Phally',
- 'group_id' => 100
- ));
+ $this->Auth->Session->setReturnValue('check', true);
+ $this->Auth->Session->setReturnValue('read', 100);
- $expected = array(
- 'User' => array(
- 'username' => 'Phally',
- 'group_id' => 100
- )
- );
-
- $result = $this->Auth->user();
- $this->assertEqual($expected, $result);
+ $this->Auth->beforeRender();
- $expected = 100;
+ $this->Auth->Session->expect('read', array('Auth.Users'));
+ $this->Auth->user();
- $result = $this->Auth->user('group_id');
- $this->assertEqual($expected, $result);
+ $this->Auth->Session->expect('read', array('Auth.Users.User.group_id'));
+ $this->Auth->user('group_id');
- $expected = 'Phally';
-
- $result = $this->Auth->user('username');
- $this->assertEqual($expected, $result);
+ $this->Auth->Session->expect('read', array('Auth.Users.User.username'));
+ $this->Auth->user('username');
}
+
}
?>
\ No newline at end of file
diff --git a/plugins/users/views/helpers/auth.php b/plugins/users/views/helpers/auth.php
index 95d926b..0534c29 100755
--- a/plugins/users/views/helpers/auth.php
+++ b/plugins/users/views/helpers/auth.php
@@ -36,7 +36,7 @@ class AuthHelper extends AppHelper {
* @var string
* @access public
*/
- public $user = 'User';
+ public $user = 'Users.User';
/**
* The session key of the group ID in the userdata.
@@ -110,8 +110,16 @@ class AuthHelper extends AppHelper {
*/
public function user($field = null) {
$path = $this->auth;
+
+ if (strpos($this->user, '.')) {
+ list($plugin, $alias) = explode('.', $this->user);
+ $path .= '.' . $plugin;
+ } else {
+ $alias = $this->user;
+ }
+
if ($field) {
- $path .= '.' . $this->user . '.' . $field;
+ $path .= '.' . $alias . '.' . $field;
}
return $this->Session->read($path);
}
