Closed (fixed)
Project:
SimpleTest
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
23 Jan 2008 at 20:40 UTC
Updated:
1 Apr 2008 at 00:12 UTC
I have SimpleTest code that goes something like this:
// Create a biography for the basic user.
$this->drupalLoginUser($this->basic_user);
$node = $this->bioCreateBio();
// Have user attempt to create another one; confirm they're redirected back
// to their existing bio node.
$this->drupalGet('node/add/bio');
$this->assertText($node->title, t("Checking for redirection to existing bio node"));
// Create a biography for the admin user.
$this->drupalLoginUser($this->admin_user);
$node = $this->bioCreateBio();
This results in multiple failures, because when a logged in user attempts to go to user/login, they receive an access denied. Therefore, there's no form to fill out the values.
It'd be nice if drupalLoginUser would recognize if a user's already logged in, and if so, terminate the session in advance of calling up the form.
I lost a bunch of time on this trying to figure out why my simple calls to DrupalTestCase's built-in methods weren't succeeding.
Comments
Comment #1
webchickHm. I'm upgrading this to a bug report, as the only work around appears to be:
Something's not quite right here.
Comment #2
Rok Žlender commentedIt makes sense that you can't login twice in a row.
This code works for me.
But we could make our lives easier a bit. So how can we be sure that user is logged in. Can we check for 'log out' text on page would this be reliable. We could just put another param in drupalLoginUser with TRUE for log out first and FALSE as default for no log out. What do you think?
Comment #3
webchickBIZARRE. I swear that this:
Spat out failures the other day, but I guess I'm wrong. :)
As for function parameters in drupalLoginUser(), I'd kind of rather the function just be smart and do what I mean. ;)
I think it's safe to assume that when I do:
What I mean by that second call is, "I don't want to be logged in as $test_user anymore. Please log me in as $test_user_2 now."
So the function ought to just override the existing session, if it exists, with one for the new user, at least imo. We could make this a flag I suppose, but I'm trying to figure out under what circumstances having to type in an extra line of code each time you switch users is considered a "feature."
However, if you still want to require an explicit log out between logins, then an alternative would be creating a drupalLogoutUser() would be much more intuitive than drupalGet('logout') as the "opposite" or drupalLoginUser().
(As a side note, now that I write it out like this, drupalLoginUser() is another one of those functions like drupalPostReqest() that could stand to drop a word at the end and still be descrptiive. I'll go file a separate patch for that.)
Comment #4
boombatower commentedCommitted.
Comment #5
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.