Functional test login not working

I am trying to run an authenticated user functional test with the following code:

protected function _login(){

	$model=new LoginForm;


	// validate user input and redirect to the previous page if valid

	if($model->validate() && $model->login())

		return true;

	return false;


that i call on the test that i want to run. But when i use $this->open(‘url’) on my functional test i keep going to the login page.

Any thoughts ?

The stuff can be password encryption?

First thing: by functional tests do you mean testing full application stack with Selenium or something like that?

In such case - you must login such user in the context of all browser requests, not in xUnit file with test definition. Functional test run like this:

  • xUnit file connects with Selenium,

  • xUnit send command to selenium

  • selenium runs browser and this browser makes call to test site…

at this point - there is another context created connected to the browser with session cookie. The user must be logged in this context (some values set in this session) to be visible for other requests. This context (session) is not the same as created for xUnit test, so calling Yii::app()->user->login() in xUnit is not same as calling it from action run by browser controller by Selenium…

What you should do:

add commands to request login page through Selenium, fill login/password fields and call "submit" button. Then follow other equests of your test.

Is this clear and answers your problem?