Welcome to the Cookbook

loading...

4.7.6.2 The testAction method

The new thing here is the testAction method. The first argument of that method is the Cake url of the controller action to be tested, as in '/articles/index/short'.

The second argument is an array of parameters, consisting of:

return
Set to what you want returned.
Valid values are:
  • 'vars' - You get the view vars available after executing action
  • 'view' - You get The rendered view, without the layout
  • 'contents' - You get the rendered view's complete html, including the layout
  • 'result' - You get the returned value when action uses $this->params['requested'].
The default is 'result'.
fixturize
Set to true if you want your models auto-fixturized (so your application tables get copied, along with their records, to test tables so if you change data it does not affect your real application.) If you set 'fixturize' to an array of models, then only those models will be auto-fixturized while the other will remain with live tables. If you wish to use your fixture files with testAction() do not use fixturize, and instead just use fixtures as you normally would.
method
set to 'post' or 'get' if you want to pass data to the controller
data
the data to be passed. Set it to be an associative array consisting of fields => value. Take a look at function testIndexPostFixturized() in above test case to see how we emulate posting form data for a new article submission.