User tests: Successful: Unsuccessful:
I wanted to load user by username, like in Example 2 at http://docs.joomla.org/JFactory/getUser.
But, due to a bug in JFactory::getUser() that is not possible.
If we pass a username, we reach this condition:
elseif ($instance->id != $id)
{
$instance = JUser::getInstance($id);
}
But $instance->id will be 0 if person viewing the site is not logged in, and because $id is string and loose comparison is used, string will evaluate to 0 as well, condition won't be satisfied, and empty user object will be returned.
The fix is simple, just making it a strict comparison instead of loose.
To test, make sure nothing broke on the user pages or anywhere where you load User object
or I have to pretend I made another commit to force it run?
I think so. I don't know how to trigger it manually. I also think it has nothing to do with this PR.
Title |
|
Done, Travis is happy again.
Side note:
Basically what I'm doing is to use JFactory::getUser() on only for the current user and JUser::getInstance() for everyone else.
Joomla is moving away from using JFactory class, so it makes no sense to use it unless really needed.
That said, your change looks good -- just to be sure, I'd test it also works with (string) $id, meaning that the id comes from the database.
PS. whatever we try to do, the function doesn't work with numeric usernames....
Closed as per the comment on the tracker
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2014-08-08 14:32:34 |
FYI: The Travis CI build failed. I've no clue why it doesn't match though: