I am trying to login a user with DrupalWebTestCase::drupalLogin and it's failing. Here is my simpletest callback:

$create_j_entity_type_user = $this->drupalCreateUser(array('create j-entity types'));
$this->drupalLogin($create_j_entity_type_user);

The output of the drupalLogin():

User created with name zPUkpgzN and pass 6NXRDGWy5k	Pass
GET http://www.example.com/user returned 200 (1 byte).	Pass
Valid HTML found on "http://www.example.com/user"	Pass
Failed to set field name to zPUkpgzN	Fail
Failed to set field pass to 6NXRDGWy5k	Fail
Found the Log in button	Fail
Found the requested form fields at user	Fail
User zPUkpgzN successfully logged in.   Fail

This is the entirity of my callback, I haven't even done anything else yet. I cannot understand why drupalLogin() is failing. I am executing the code on a non-language domain (though the site itself is multilingual), and have set $base_path in settings.php, but no matter what I do, this fails.

Comments

Jaypan’s picture

Merged with original post.

phl3tch’s picture

I've been hammering at this same issue myself for about three days, and I think I'm on the trail of a solution. It seems that when curlExec() calls curlInitialize to set up the necessary curlopts (/modules/simpletest/drupal_web_test_case.php, line 1608), the settings are getting overwritten or ignored later. Specifically, CURLOPT_RETURNTRANSFER, which must be set to TRUE, otherwise curl will return a Boolean instead of the data that Simpletest is trying to make assertions against.

I can't provide a patch because I'm not 100% sure what's going on here, but if I add:

$curl_options[CURLOPT_RETURNTRANSFER] = TRUE;

...right before line 1631, well, let's just say that things fail less spectacularly. At least on my system, it no longer complains that it can't set fields name and password. It still fails to log in, however.

Would love it if some other folks would take a look at this. I'm about to pull my hair out.

Albert Volkman’s picture

I too am having this issue. It almost appears that its not using the generated database, and instead using the main database. Try manually setting the test's username/password to your Drupal install's user 1.

Jaypan’s picture

Hi Albert

That makes sense, as one of the errors I'm getting is that the field on a user could not be set, but in a clean install, there should be no fields on the user, which has definitely been confusing me.

Can you give more information on what you mean by setting the test user to user 1? Thank you.

Jaypan’s picture

Priority: Normal » Major

I'm setting this to major, for while it doesn't prevent functionality on a site, it prevents testing for bugs, which could in turn allow for potentially serious bugs.

Jaypan’s picture

Issue summary: View changes

Incorrect messages

marcingy’s picture

Priority: Major » Normal

Core tests are not failing on d.o so I can't see how this is major.

Jaypan’s picture

Status: Active » Closed (cannot reproduce)

Ahh, so since it works on DO, our sites are irrelevant. Might as well close the bug then.

marcingy’s picture

Version: 7.15 » 8.x-dev
Status: Closed (cannot reproduce) » Active

Hmm no but it is not a major bug according to d.o bug classifications , but it is something that still needs to be looked at and fixed.

marcingy’s picture

Jaypan’s picture

I personally disagree, as a lack of testing can mean that a whole site can go down due to a bug, which fits the classifications.

Here is my entire test class:

class JEntityTestCase extends DrupalWebTestCase
{
	public static function getInfo()
	{
		return array
		(
			'name' => 'J-Entity CRUD Test', 
			'description' => 'Create a J-Entity type and bundle and run CRUD tests (CReate Update and Delete) to test users permissions.', 
			'group' => 'J-Entity',
		);
	}
	
	function setUp()
	{
		parent::setUp();
	}
	
	function testEntityCreateEntityType()
	{
		global $user;

		$create_user = $this->drupalCreateUser(array());
		$this->drupalLogin($create_user);
		$this->verbose('User: <pre>' . print_r($create_user, TRUE) . '</pre>');
	}
}

And here is the test result:

User created with name njEytfsl and pass 4LiHVbgsxB	User login	j_entity.test	22	JEntityTestCase->testEntityCreateEntityType()	Pass
GET http://www.example.com/user returned 200 (1 byte).	Browser	j_entity.test	23	JEntityTestCase->testEntityCreateEntityType()	Pass
Verbose message	Debug	j_entity.test	23	JEntityTestCase->testEntityCreateEntityType()	Debug
Valid HTML found on "http://www.example.com/user"	Browser	j_entity.test	23	JEntityTestCase->testEntityCreateEntityType()	Pass
Failed to set field name to njEytfsl	Other	j_entity.test	23	JEntityTestCase->testEntityCreateEntityType()	Fail
Failed to set field pass to 4LiHVbgsxB	Other	j_entity.test	23	JEntityTestCase->testEntityCreateEntityType()	Fail
Found the Log in button	Other	j_entity.test	23	JEntityTestCase->testEntityCreateEntityType()	Fail
Found the requested form fields at user	Other	j_entity.test	23	JEntityTestCase->testEntityCreateEntityType()	Fail
User njEytfsl successfully logged in.	User login	j_entity.test	23	JEntityTestCase->testEntityCreateEntityType()	Fail
Verbose message	Debug	j_entity.test	24	JEntityTestCase->testEntityCreateEntityType()	Debug

Edit: Looking more at the test results, the login page is returning a 200 status, but the returned value is a single byte, the integer '1', as can be seen in the verbose message:

GET request to: user
Ending URL: http://www.borsaarabia.com/user
1

This is in line with CrackWilding's comment in post #2:

Specifically, CURLOPT_RETURNTRANSFER, which must be set to TRUE, otherwise curl will return a Boolean instead of the data that Simpletest is trying to make assertions against.

It appears that a boolean is being returned instead of the page value. This also means that it's not likely my regular database is being used. As such, I edited this line of drupal_web_test_case.php:

$out = $this->curlExec(array(CURLOPT_HTTPGET => TRUE, CURLOPT_URL => url($path, $options), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => $headers));

To this:

    $out = $this->curlExec(array(CURLOPT_HTTPGET => TRUE, CURLOPT_URL => url($path, $options), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => $headers, CURLOPT_RETURNTRANSFER => TRUE));

And the login did succeed, although like CrackWilding, I am still seeing other errors.

Jaypan’s picture

Status: Active » Closed (duplicate)

Turns out this issue has already been fixed, and this thread is a duplicate of http://drupal.org/node/1671200

Umayal’s picture

Title: DrupalWebTestCase (simpletest) drupalLogin() fails » DrupalWebTestCase how to test drupalLogin() and Logout.

I have posted my code in http://drupal.org/node/1791220
anybody help me to complete the basic test operation.

kilogauss’s picture

Updating to Drupal 7.19 resolved this for me.

victor-shelepen’s picture

Status: Closed (duplicate) » Active

I am making tests for the module - locale, Drupal 8. I see the same problems. I've looked over duplicated task. I've not found the right solution.
This lines.

$this->admin_user = $this->drupalCreateUser(array('translate interface', 'access administration pages'));
$this->drupalLogin($this->admin_user);

Prints this:

Status    Group      Filename          Line Function                            
--------------------------------------------------------------------------------
Pass      Other      LocaleTranslation   34 Drupal\locale\Tests\LocaleTranslati
    Enabled modules: locale
Pass      Role       LocaleTranslation   36 Drupal\locale\Tests\LocaleTranslati
    Created role ID &#039;q4cid2db&#039; with name &#039;J[v0aC42&#039;.
Pass      Role       LocaleTranslation   36 Drupal\locale\Tests\LocaleTranslati
    Created permissions: translate interface, access administration pages
Pass      User login LocaleTranslation   36 Drupal\locale\Tests\LocaleTranslati
    User created with name sZDTdbqV and pass ui9prSRoT2
Pass      Browser    LocaleTranslation   51 Drupal\locale\Tests\LocaleTranslati
    GET http://localhost/core/install.php returned 200 (6.93 KB).
Pass      Browser    LocaleTranslation   51 Drupal\locale\Tests\LocaleTranslati
    Valid HTML found on "http://localhost/core/install.php"
Fail      Other      LocaleTranslation   51 Drupal\locale\Tests\LocaleTranslati
    Failed to set field name to sZDTdbqV
Fail      Other      LocaleTranslation   51 Drupal\locale\Tests\LocaleTranslati
    Failed to set field pass to ui9prSRoT2
Fail      Other      LocaleTranslation   51 Drupal\locale\Tests\LocaleTranslati
    Found the Log in button
Fail      Other      LocaleTranslation   51 Drupal\locale\Tests\LocaleTranslati
    Found the requested form fields at user
Fail      User login LocaleTranslation   51 Drupal\locale\Tests\LocaleTranslati
    User sZDTdbqV successfully logged in.

I understand that many people work with. But it strange for me why I have problems with.

victor-shelepen’s picture

I work on Ubuntu 13.04. Maybe I have differ curl default settings. Could I put this settings into php.ini?

$curl_options[CURLOPT_RETURNTRANSFER] = TRUE;
victor-shelepen’s picture

Issue summary: View changes

Removing unneeded and incorrect comment.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

kirankumar_k’s picture

Issue summary: View changes

I have run the test and I got 13 passes(In green color) where status is showing green tick mark and 3 failed(In red color) where status is showing in red X.

The 3 failed results are as follows

"Found the Save button"
"Found the requested form fields at admin/main/xxx/settings"
"Product created."

which are caused by the below code

$edit = array(
'textbox1' => $this->randomName(8),
'textbox2' => $this->randomName(8),
'select' => array_rand(array(
'opt1' => t('opt1'),
'opt2' => t('opt2'),
'opt3' => t('opt3'),
)),
);
$this->drupalPost('admin/main/xxx/settings',$edit,t('Save'));

Even I have given proper form permissions and when i opened the form in verbose it is opened properly, I am not able to understand what is the issue. Please help me in this asap.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Component: simpletest.module » phpunit

Triaging issues in simpletest.module as part of the Bug Smash Initiative to determine if they should be in the Simpletest Project or core.

This looks like it a Phpunit issue, changing component.

mondrake’s picture

Status: Active » Closed (outdated)

Simpletest is gone. Latest comments seem more request for support than addressing a bug, anyway. This issue is stale and obsolete. Closing, open support requests in case.