开发者

Functional test: how to set JSON data in a POST method?

I want to create a functional test for an action th开发者_StackOverflowat receives a POST method with data in JSON format.

This is what I have:

  info('set car')->
  post('/user/'.$user->getId().'/set-car/'.$car->getId()'->

  with('request')->ifFormat('json')->begin()->
    isParameter('module', 'myModule')->
    isParameter('action', 'myAction')->
  end()->

But..where should I set the receiving json data?

sf 1.4

Regards

Javi


Did you checked out the page from Jobeet tutorial?

The first example is

$browser = new sfBrowser();

$browser->
  get('/')->
  click('Design')->
  get('/category/programming?page=2')->
  get('/category/programming', array('page' => 2))->
  post('search', array('keywords' => 'php'))
;

It may be that I didn't understand you question at all. Correct me if I'm wrong.


More of a workaround...

If you get the content in your action like this:

protected function getContent() {
    $content = $this->request->getParameter('content'); 
    if(!$content) $content = $this->request->getContent(); 
    return $content;
}

public function executeIndex(sfWebRequest $request) {
    $content = $this->getContent();
    //do something with your content :D
}

that should allow you to test what you want by passing

post('search', array('content' => 'whatever my content is')); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜