Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix user() return value for nested data

  • Loading branch information...
commit 6c9b2a1feceda55ef10e2a2421ac825ee89aa5a5 1 parent 1193774
@ceeram ceeram authored
View
4 lib/Cake/Controller/Component/AuthComponent.php
@@ -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;
}
View
33 lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php
@@ -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);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.