/** * Returns a user instance given the user name. * @param string user name, null if it is a guest. * @return TUser the user instance, null if the specified username is not in the user database. */ public function getUser($username = null) { if ($username === null) { $user = new TUser($this); $user->setIsGuest(true); return $user; } else { $username = strtolower($username); if (isset($this->_users[$username])) { $user = new TUser($this); $user->setName($username); $user->setIsGuest(false); if (isset($this->_roles[$username])) { $user->setRoles($this->_roles[$username]); } return $user; } else { return null; } } }
public function testLoadFromString() { $user = new TUser(self::$mgr); $user->setName('John'); $user->setIsGuest(false); $user->setRoles('Administrator, Writer'); $save = $user->saveToString(); $user2 = new TUser(self::$mgr); $user2->loadFromString($save); self::assertEquals($user, $user2); }