Skip to content

Commit

Permalink
Fix user() return value for nested data
Browse files Browse the repository at this point in the history
  • Loading branch information
ceeram committed May 31, 2012
1 parent 1193774 commit 6c9b2a1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Controller/Component/AuthComponent.php
Expand Up @@ -569,8 +569,8 @@ public static function user($key = null) {
if ($key === null) {
return $user;
}
if (isset($user[$key])) {
return $user[$key];
if ($value = Hash::get($user, $key)) {
return $value;
}
return null;
}
Expand Down
33 changes: 33 additions & 0 deletions lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php
Expand Up @@ -1254,4 +1254,37 @@ public function testPassword() {
$this->assertEquals($expected, $result);
}

/**
* testUser method
*
* @return void
*/
public function testUser() {
$data = array(
'User' => array(
'id' => '2',
'username' => 'mark',
'group_id' => 1,
'Group' => array(
'id' => '1',
'name' => 'Members'
),
));
$this->Auth->Session->write('Auth', $data);

$result = $this->Auth->user();
$this->assertEquals($data['User'], $result);

$result = $this->Auth->user('username');
$this->assertEquals($data['User']['username'], $result);

$result = $this->Auth->user('Group.name');
$this->assertEquals($data['User']['Group']['name'], $result);

$result = $this->Auth->user('invalid');
$this->assertEquals(null, $result);

$result = $this->Auth->user('Company.invalid');
$this->assertEquals(null, $result);
}
}

0 comments on commit 6c9b2a1

Please sign in to comment.