2012-06-17 63 views
1

我为我的项目编写了如下功能测试。功能测试问题

<?php 

include(dirname(__FILE__).'/../../bootstrap/functional.php'); 

    $baseFolder = '/root/nsuhr/apps/backend/modules'; 
    //$browser = new sfTestFunctional(new sfBrowser()); 
    $methodArray = SecurityTest::getRoutes(); 
    $actionVar = new securityReport(); 
foreach ($methodArray as $module) 
{ 

$username='012001011';                  $credential = 'financeAdmin'; 
$password='123';                     
$f = $baseFolder . DIRECTORY_SEPARATOR . trim($module['module']) . DIRECTORY_SEPARATOR . 'actions'; 
$actionArray = $actionVar->parseActionFile($f . DIRECTORY_SEPARATOR . 'actions.class.php'); 
$module = trim($module['module']); 

foreach ($actionArray as $action) 
{ 
// if(trim($action) == 'custom') 
// throw new exception(' custommmmm ') ; 
    $browser = new sfTestFunctional(new sfBrowser()); 


       $browser-> 
       post('/sfGuardAuth/signin', array('signin' => array('username' =>  $username, 'password' => $password)))-> 
       with('form')->begin()-> 
       hasErrors(false)-> 
       end()-> 



       get($module.'/'.$action)-> 

       with('request')->begin()-> 
       isParameter('module', $module)-> 
       isParameter('action', $action)-> 
       end()-> 

       with('user')->begin()->                    
       isAuthenticated(true)->                   
       hasCredential(array($credential))->              
       end()-> 

       with('response')->begin()-> 
       isStatusCode(200)-> 
       checkElement('body', '!/This is a temporary page/')-> 
       end(); 
} 


} 

运行测试后,我得到了以下错误:

# get FacultyPosition/new 
ok 100 - request parameter module is FacultyPosition 
ok 101 - request parameter action is new 
ok 102 - user is authenticated 
ok 103 - user has the right credentials 
ok 104 - status code is 200 
ok 105 - response selector body does not match regex /This is a temporary page/ 

# post /sfGuardAuth/signin 
ok 106 - the submitted form is valid. 

# get FacultyPosition/edit 

PHP Fatal error: Call to undefined method sfRoute::getObject() in  /root/nsuhr/apps/backend/modules/FacultyPosition/actions/actions.class.php on line 83 

Fatal error: Call to undefined method sfRoute::getObject() in /root/nsuhr/apps/backend/modules/FacultyPosition/actions/actions.class.php on line 83 

我发现这些facultyPosition方法的编辑操作需要的输入。出于这个原因,它给了我这个错误。

现在我想找到需要输入的不同方法的所有操作。我怎样才能做到这一点?请帮帮我。的actions.class.php的

代码是:

public function executeEdit(sfWebRequest $request) 
    { 
    $this->faculty_position = $this->getRoute()->getObject(); 

    $this->employee_id = $this->faculty_position->getEmployeeId(); 
    $this->employeeType = Employee::getEmployeeTypeByEmployeeId($this->employee_id) ; 


    $this->form = $this->configuration->getForm($this->faculty_position); 

    $this->organoNode = $this->faculty_position->getOrganoNode() ; 
    //throw new Exception($this->organoNode->getType()."".$this->organoNode->getId()); 
    $this->form->setDefault('organo_node_type',$this->organoNode->getType()); 


    $this->form->setDefault('organo_node_id',$this->organoNode->getId()); 


    $this->positionNode = $this->faculty_position->getPositionNode() ; 
    $this->form->setDefault('organo_position_id',$this->positionNode->getId()); 


    $this->empId = $this->getUser()->getAttribute('employee_id') 

} 
+0

你能发布你的动作代码吗? –

+0

是的,我和我发布行动代码 – Chaity

回答

2

功能测试呼叫到$module/edit需要一个$id参数在请求中传递。

没有$module/$id/edit没有路由对象可以获得。

你可以得到一个$id PARAM,这样解决这个测试:

$id = $objectQuery::create()->select('id')->findOne(); 

然后得到编辑操作你的$actionArray,并与持有$id,这样一位杰出的呼叫处理:

get("$module/$id/$action")->