4

How do you retrieve the current 'simpletest' user during a simpletest.

During a simpletest is the $user GLOBAL from the test environment or the live environment?

3

Inside the test method?

No idea what in $GLOBALS['user'] is, but you certainly can't rely on it. You are never "logged in" in that context, you are only logged in when doing requests with drupalGet()/drupalPost().

If you used drupalLogin(), you can look for $this->loggedInUser. If not, then it's not possible, other than maybe doing a GET to /user and then trying to get the username from title.

Inside a page callback, $GLOBALS['user'] is the current user, just like you'd expect.

| improve this answer | |
  • Thank you @Berdir. $this->loggedInUser and user_load did the trick and makes for a way cleaner test class. – Citricguy Dec 18 '11 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.