Chaity
Chaity

Reputation: 27

Functional testing issuse

I wrote a functional test as follows for my project.

<?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();
}


}

After running the test I got the following error:

# 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

I found out that for these facultyPosition method's edit action needs an input. For this reason it's give me this error.

Now I want to find the all actions for different method for which needs a input. How can I do that? Please help me.

Code of actions.class.php is:

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

}

Upvotes: 1

Views: 376

Answers (1)

Qoheleth-Tech
Qoheleth-Tech

Reputation: 201

The functional test call to $module/edit needs an $id parameter passed in the request.

Without $module/$id/edit there is no route object to get.

You can fix this test by getting an $id param, like this:

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

Then get the edit action out of your $actionArray and handle it with a distinguished call which holds the $id, like this:

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

Upvotes: 2

Related Questions