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')

}
4

1 回答 1

2

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

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

您可以通过获取$id参数来修复此测试,如下所示:

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

然后从您的编辑操作中获取$actionArray并使用包含 的杰出调用来处理它$id,如下所示:

get("$module/$id/$action")->
于 2013-03-18T21:41:03.297 回答