2013-03-22 52 views
3

我尝试使用Selenium为我的Yii应用运行测试。一个简单的测试,我打开入口页面并检查文本正在工作。Yii功能测试的正确路由

让我们下面的测试片段:

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

“管理员”是在我的应用程序的模块。第一个函数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, 
), 

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

回答

3
在你的config/test.php的,你必须告诉它显示脚本文件名(索引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, 
      ), 
     ), 
    ) 
); 
+0

非常感谢你,这是工作。对我感到羞耻,我没有想到这一点。 – Sisko78 2013-03-22 13:12:45