我正在尝试与经过身份验证的用户在YII上使用硒运行功能测试。我写了以下内容
protected function _login(){
$id=new UserIdentity('admin','admin');
$id->authenticate();
if($id->errorCode===UserIdentity::ERROR_NONE)
{
Yii::app()->user->login($id);
return true;
}
return false;
}
public function testSpot(){
$this->assertTrue($this->_login());
ob_end_flush();
$this->open('production/request/create');
}
我在引导程序上添加了一个 ob_start(.php因为标头被发送了两次并在登录后刷新了它。当访问生产/请求/创建进入登录页面时,仍然是测试,因为即使登录有效,也不会计算登录名。
编辑:如果在 phpunit 上使用 --stderr 选项,则不需要ob_end_flush和ob_start。
这不起作用,因为您只对从命令行运行的会话进行身份验证。您需要对 Web 会话进行身份验证。
请参阅此评论:
http://www.yiiframework.com/doc/guide/1.1/en/test.functional#c10015