mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix user() return value for nested data
This commit is contained in:
parent
119377422e
commit
6c9b2a1fec
2 changed files with 35 additions and 2 deletions
|
@ -569,8 +569,8 @@ class AuthComponent extends Component {
|
|||
if ($key === null) {
|
||||
return $user;
|
||||
}
|
||||
if (isset($user[$key])) {
|
||||
return $user[$key];
|
||||
if ($value = Hash::get($user, $key)) {
|
||||
return $value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1254,4 +1254,37 @@ class AuthComponentTest extends CakeTestCase {
|
|||
$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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue