Hi there!
Which is the best practice to unit test with a logged in user? I do it this way:
class TestUserIdentity extends CUserIdentity
public function authenticate() {
$this->_id=1;
return $this->errorCode=self::ERROR_NONE;
}
}
class TestUserIdentityTest extends CTestCase {
function testLogin() {
$identity = new TestUserIdentity('testuser','');
$identity->authenticate();
Yii::app()->user->login($identity);
$this->assertEquals(1, Yii::app()->user->id);
}
}
This way, if I need a logged in user, I can do a @depends testLogin on the unit test. But is this the best way?