testActionの第二引数でPOSTするデータを渡すとテストできます。
CommentsControllerTest.php
public function testAdd() {
$data = array(
'Comment' => array(
'body' => 'this is comment test'
)
);
$this->testAction('/comments/add', array('method' => 'post', 'data' => $data));
}
こんな感じ。
ファイルのアップロードを伴うPOSTをテストしたい場合は、ファイルをPOSTした時に$_FILESにセットされる想定のものをファイルの値に入れて渡せば良いようです。
CommentsControllerTest.php
public function testAdd() {
$data = array(
'Comment' => array(
'body' => 'this is comment test',
'img_file' => array(
'name' => 'picture.jpg',
'type' => 'image/jpg',
'tmp_name' => ROOT . DS . APP_DIR . DS . 'Test' . DS . 'Fixture' . DS . 'picture.jpg',
'error' => UPLOAD_ERR_OK,
'size' => 58915
)
)
);
$this->testAction('/comments/add', array('method' => 'post', 'data' => $data));
}
テスト用のファイルをFixtureディレクトリの下とかに置いておき、tmp_nameにその場所を書きます。