? Success

User tests: Successful: Unsuccessful:

avatar mbabker
mbabker
19 Jul 2015

Update of PR #4675 to resolve merge conflict.

Original Description

public static function getUser($id = null)
{
$instance = self::getSession()->get('user');
if (is_null($id))
{
if (!($instance instanceof JUser))
{
$instance = JUser::getInstance();
}
}
elseif ($instance->id != $id)
{
$instance = JUser::getInstance($id);
}
return $instance;
}

When I write a unit test case for a function, which has the code JFactory::getUser(); inside, then I need to set user in session. Otherwise session does not contain anything, and return NULL on first line of function. If $instance is null then it gets an error for "Accessing undefined property on on non-object" ($instance->id ).

There should be a check before using "elseif ($instance->id != $id)"

Test Instructions

  • Download this test CLI script to your CMS install - https://gist.github.com/mbabker/37600809b162b17de2d4
  • Run this script from command line (in order to better represent the issue being addressed, a command line environment is preferred as web requests do not seem to hit this issue)
  • Pre-patch, you should get a Notice: Trying to get property of non-object in libraries/joomla/factory.php on line 246 message
  • Apply the patch
  • Post patch, the message should not appear
avatar mbabker mbabker - open - 19 Jul 2015
avatar mbabker mbabker - change - 19 Jul 2015
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 19 Jul 2015
Labels Added: ?
avatar brianteeman brianteeman - change - 22 Jul 2015
Category Libraries
avatar Fedik
Fedik - comment - 23 Jul 2015

test works as described

avatar Fedik Fedik - test_item - 23 Jul 2015 - Tested successfully
avatar zero-24 zero-24 - test_item - 23 Aug 2015 - Tested successfully
avatar zero-24 zero-24 - change - 23 Aug 2015
Status Pending Ready to Commit
avatar zero-24
zero-24 - comment - 23 Aug 2015

Just tested successful with your example CLI Script. Thanks. Together with @Fedik 's test i'm moving to RTC here.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/7473.

avatar joomla-cms-bot joomla-cms-bot - change - 23 Aug 2015
Labels Added: ?
avatar wilsonge wilsonge - change - 24 Aug 2015
Status Ready to Commit Closed
Closed_Date 0000-00-00 00:00:00 2015-08-24 10:06:29
Closed_By wilsonge
avatar wilsonge wilsonge - close - 24 Aug 2015
avatar joomla-cms-bot joomla-cms-bot - close - 24 Aug 2015
avatar wilsonge wilsonge - reference | 2f25d80 - 24 Aug 15
avatar wilsonge wilsonge - merge - 24 Aug 2015
avatar wilsonge wilsonge - close - 24 Aug 2015
avatar joomla-cms-bot joomla-cms-bot - change - 24 Aug 2015
Labels Removed: ?
avatar wilsonge wilsonge - change - 24 Aug 2015
Milestone Added:
avatar mbabker mbabker - head_ref_deleted - 24 Aug 2015

Add a Comment

Login with GitHub to post a comment