I am working on the implementation of test cases for our project, which will be included in our build script. This CakePHP 2.4 application is mainly based on REST and has been configured to parse json extensions in the routes.php file. Here is an example of a typical function in our application:
public function index() {
$this->paginate = array(
'fields' => array('User.username', 'User.first_name', 'User.last_name', 'UserGroup.name','Location.name','User.id'),
'conditions' => array(
'active'=>1
),
'link' => array('UserGroup','Location')
);
$this->set('response', $this->RestApi->getResponse());
$this->set('_serialize','response');
}
This will return the json structure:
{"sEcho":1,"iTotalRecords":16,"iTotalDisplayRecords":14,"aaData":[["admin","Administrative"],["salesman","Salesman"]]}
Therefore, I expected that when writing my test cases, when I call this URL, I get a JSON response, and one of my tests will be to decode it correctly and continue checking the data. The problem is that calling testAction returns nothing (I tried to tell it to return the view and contents). The only way to access the answer is to look at reverse vars.
Example - does not work:
$result = $this->testAction('/users/index.json',array(
'method' => 'GET',
'return' => 'contents'
));
var_dump($result);
- :
$result = $this->testAction('/users/index.json',array(
'method' => 'GET',
'return' => 'vars'
));
? , , , . , unit test , .
, !
EDIT: , testAction URL- non-rest, , HTML, . HTML ..