Closed (fixed)
Project:
SimpleTest
Version:
5.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
25 Jan 2008 at 06:44 UTC
Updated:
24 Aug 2008 at 00:20 UTC
I have the following test method in bio.module:
/**
* Ensure that the "Use bio for user profiles" option is working properly.
*/
function testBioProfile() {
// Enable setting and login as basic user to test.
$this->drupalVariableSet('bio_profile', 1);
$this->drupalLoginUser($this->basic_user);
$uid = $this->basic_user->uid; # Not 1. 231 or whatever.
// Check to see if link to edit bio shows up in user profile.
$this->drupalGet("user/$uid");
$this->assertWantedRaw("user/$uid/bio", t('Checking for link to edit bio on user profile'));
// Fill in bio form.
$edit['title'] = $this->randomName(32);
$edit['body'] = $this->randomName(32);
$this->drupalPostRequest("user/$uid/bio", $edit, t('Submit'));
$content = $this->drupalGetContent();
$this->assertNoUnwantedRaw('This user already has a Biography.', t('Checking for incorrect error message')); # FAIL
// Check for bio information on user profile page.
$html = $this->drupalGet("user/$uid");
$this->assertText($edit['body'], t('Checking for bio content on user profile')); # FAIL
}
The two lines marked # FAIL fail because this check in bio_nodeapi is getting fired. It thinks my user ID is still 1.
case 'validate':
// Ensure this user doesn't already have a bio node.
$account = user_load(array('name' => $node->name));
$nid = bio_for_user($account->uid);
if ($nid && ($nid != $node->nid)) {
form_set_error('name', t('This user already has a @bio. Edit it <a href="@link">here</a> or assign this entry to another user.', array('@bio' => node_get_types('name', $node), '@link' => url('node/'. $nid .'/edit'))));
}
Any ideas what could be happening?
Comments
Comment #1
webchickAh, ok.
bio_for_user uses the global $user variable's $uid when $uid is not otherwise set. global $user; within the context of a SimpleTest test, is still user 1.
Not sure if this is by design or not. Seems like it probably is, so if a test fails in the middle, you don't end up logged in as simpletest_x763.
Comment #2
webchickOk. I think I figured out what's going on.
When the simpletest_XXXX user attempts to access user/123/bio, they invoke this check in bio_menu:
...and they end up at a big fat "Access denied" screen. Because Drupal doesn't care what kind of $_POST values you throw at an access denied screen, the drupalPostRequest() line doesn't fail.
So now, I guess the question is... is this behaviour by design or not? And can you recommend any better access checking solutions for bio module? In the meantime, I can work around this by creating the bio in a different way.
Comment #3
Rok Žlender commentedHm so this doesnt make any sense to me. You are using drupalGet which uses internal SimpleTest browser which has no idea about your uid. So there must be another problem with code or your tests. Which module is this test for? Maybe I can have a look.
Comment #4
webchickThe test file is located at http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/bio/tests/b...
And the module file is located at http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/bio/bio.mod...
What I'm trying to test is heading to user/X/bio and creating the bio there, rather than node/add/bio. But it's erroneously telling me that my simpletest_XXXX user already has a bio, when it is in fact user 1 (the user I'm logged in as while running the tests) who does.
Comment #5
Rok Žlender commentedOk wild shot but, if I see correctly you write this for D5 and drupalGet patch which removes need for url call just went it today so maybe this is why your tests were failing. I just tested testBioProfile with every other test commented out and I also uncommented/commented proper code so now
Produces only passes.
Comment #6
boombatower commentedThis needs a response from webchick.
Comment #7
boombatower commentedClosing due to inactivity.