正确路由Yii功能测试

时间:2013-03-22 09:08:50

标签: selenium yii

我尝试使用Selenium为我的Yii应用程序运行测试。我打开入口页面并检查文本的简单测试正在运行。

我们来看下面的测试片段:

class ItemTest extends WebTestCase
{
    public function testCreateItem()
    {
        $this->open('admin/item');
        $this->click("link=create item...");
              ...
    }
}

“admin”是我应用中的模块。第一个函数open()正在运行。调用带有index-test.php的正确url。

但第二个函数click()以某种方式路由到主index.php而不是index-test.php。我想这与我的网址管理器配置有关吗?

'urlManager'=>array(
    'urlFormat'=>'path',
'rules'=>array(
    ''=>'site/index',
    '<controller:\w+>/<id:\d+>'=>'<controller>/view',
    '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    '<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>'=>'<module>/<controller>/<action>',
    '<module:\w+>/<controller:\w+>/<action:\w+>'=>'<module>/<controller>/<action>',
),
'showScriptName'=>false,
),

如果你能给我一些提示如何处理这个问题,我会很高兴。

1 个答案:

答案 0 :(得分:3)

你的config / test.php中的

你必须告诉它显示脚本文件名(index-test.php):

return CMap::mergeArray(
    require(dirname(__FILE__).'/main.php'),
    array(
        'components'=>array(
            'fixture'=>array(
                'class'=>'system.test.CDbFixtureManager',
            ),
            /* uncomment the following to provide test database connection
            'db'=>array(
                'connectionString'=>'mysql:host=localhost;dbname=db-test',
            ),
            */
            'urlManager' => array(
                'showScriptName' => true,
            ),
        ),
    )
);