2011-04-21 7 views
1

JSON 형식의 데이터가 포함 된 POST 메서드를받는 작업에 대한 기능 테스트를 만들고 싶습니다.기능 테스트 : POST 메서드에서 JSON 데이터를 설정하는 방법은 무엇입니까?

이 내가 무엇을 가지고 :

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 내가받은 JSON 데이터를 설정해야합니까? 김포 1.4

감사

하비

답변

2

는 Jobeet 튜토리얼에서 page을 확인 했습니까?

첫 번째 예는 그것은 당신이 모든 질문을 이해하지 않았다고 할 수있다

$browser = new sfBrowser(); 

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

입니다. 내가 틀렸다면 나를 바로 잡습니다.

+0

을 전달하여 당신은 당신이 원하는 것을 테스트 할 수 있도록해야

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 } 

감사합니다. 그러나 액션에서 $ request-> getContent()를 통해 JSON 날짜를 가져옵니다. 그래서 붙여 넣은 post() 함수에서 JSON 데이터를 작성하면 테스트를 실행할 때 $ request-> getContent() 호출에서 'NULL'이 표시됩니다. 물론 일반 브라우저를 사용하면 FF, $ request-> getContent() JSON 데이터를 올바르게 반환합니다. 그래서, 당신의 충고는 무엇입니까? – ziiweb

+0

잘 "JSON 날짜"대신 "JSON 데이터"를 의미합니다. – ziiweb

+0

$ request-> getParameter ('data')를 시도 했습니까? 또는 $ request-> getPostParameter ('data'). 분명히 데이터 = {여기서 JSON}을 가져야합니다. 그것은 작동해야합니다. – maectpo

0

해결의 더 ...

이 같은 액션의 콘텐츠를 얻을 경우

post('search', array('content' => 'whatever my content is')); 
관련 문제