我为我的项目编写了如下功能测试。
<?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')
}