반응형
Symfony2에서 작동하는 AJAX/XMLHttpRequest 페이지 테스트
symfony2 테스트에서 XMLHttpRequest 요청(ajax)을 시뮬레이션/실행할 수 있습니까?
문제가 있는 답변으로 검색한 후 올바른 구문은 다음과 같습니다.
$crawler = $client->request('GET', '/foo/', array(), array(), array(
'HTTP_X-Requested-With' => 'XMLHttpRequest',
));
그Request#isXmlHttpRequest()
방법은 단순히 확인합니다.X-Requested-With
헤더는 다음과 같습니다.XMLHttpRequest
요청이 Ajax 호출인지 확인하기 위해 사용하는 방법인 경우 요청에 적절한 헤더를 추가하여 테스트 클라이언트의 동작을 시뮬레이션할 수 있습니다.
class FooFunctionalTest extends WebTestCase
{
$client = static::CreateClient();
$crawler = $client->request('GET', '/foo/', array(), array(), array(
'X-Requested-With' => 'XMLHttpRequest',
));
// ...
}
요청 개체에 대한 자세한 내용은 소스 코드에서 확인할 수 있습니다.
위해서POST
,PUT
:
$crawler = $client->request('POST', '/foo/', array('param' => 'value'), array(),
array(
'HTTP_X-Requested-With' => 'XMLHttpRequest',
));
위해서POST
,PUT
생으로JSON
본문:
$crawler = $client->request('POST', '/foo/', array(), array(), array(
'HTTP_X-Requested-With' => 'XMLHttpRequest',
'CONTENT_TYPE' => 'application/json',
), '{"param": "value"}');
Symfony 3.x 또는 4.x로 작업하는 경우 이 방법이 POST 방법을 사용하는 올바른 방법입니다.
$data = ['some' => 'value'];
$client = static::createClient();
$client->request('POST', '/some_uri', ['data' => $data], [],; [
'HTTP_X-Requested-With' => 'XMLHttpRequest',
]);
언급URL : https://stackoverflow.com/questions/9400233/testing-ajax-xmlhttprequest-pages-functionally-in-symfony2
반응형
'sourcecode' 카테고리의 다른 글
MariaDB 쿼리가 작동하지 않습니다. 옵티마이저 버그? (0) | 2023.08.16 |
---|---|
Angular2/4에서 "ng-reflect-*" 속성은 무엇을 합니까? (0) | 2023.08.16 |
확인란을 반복하여 선택 또는 선택 해제된 각 항목 수를 계산합니다. (0) | 2023.08.16 |
PowerShell을 통해 Windows Server에서 IE 보안 사용 안 함 (0) | 2023.08.16 |
구조 포인터 내부의 포인터 참조 취소 (0) | 2023.08.16 |