I’m performing a simple functional test with phpunit and selenium.
A variable is stored in the session using Yii::app()->user->setState()
This works well and it can be retrieve using getState(). Of course the user needs to be logged in to test this.
My problem start with testing this. I use phpunit and selenium to make a user log in. During login the mentioned variable is set in the siteController using setState.
When getState() is run next, it turns out the complete session is empty. Somehow the session is lost and I do not understand why.
Here is the test file
<?php
class SetAccountTest extends WebTestCase
{
protected $coverageScriptUrl = 'http://localhost/phpunit_coverage.php';
public $fixtures=array(
);
public function login()
{
$this->open("site/login");
$this->type("LoginForm_email", "test@mope.mobi");
$this->type("LoginForm_password", "test");
$this->click("LoginForm_rememberMe");
$this->click("SiteOk");
$this->waitForPageToLoad("30000");
}
public function testSetAccount_1()
{
$this->login();
$acId = Yii::app()->user->getState('acId');
$this->assertEquals(1, $acId);
// $acId is null
...
}
}
Does anyone of you guys have experienced this issue?
Thanks