function ViewsAjaxTest::simpleAjaxPost

Perform a simple AJAX POST HTTP request.

Parameters

string $path: Drupal path where the request should be POSTed.

string $accept: The value for the "Accept" header. Usually either 'application/json' or 'application/vnd.drupal-ajax'.

array $post: The POST data. When making a 'application/vnd.drupal-ajax' request, the Ajax page state data should be included. Use getAjaxPageStatePostData() for that.

Return value

The content returned from the call to curl_exec().

1 call to ViewsAjaxTest::simpleAjaxPost()
ViewsAjaxTest::testAjaxView in tests/views_ajax.test
Tests an ajax and non-ajax view.

File

tests/views_ajax.test, line 50

Class

ViewsAjaxTest
Tests views ajax display.

Code

public function simpleAjaxPost($path, $accept, $post = array()) {
    $options['absolute'] = TRUE;
    foreach ($post as $key => $value) {
        // Encode according to application/x-www-form-urlencoded
        // Both names and values needs to be urlencoded, according to
        // http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1
        $post[$key] = urlencode($key) . '=' . urlencode($value);
    }
    $postfields = implode('&', $post);
    $headers = array(
        'Accept: ' . $accept,
        'Content-Type: application/x-www-form-urlencoded',
    );
    return $this->curlExec(array(
        CURLOPT_URL => url($path, $options),
        CURLOPT_POST => TRUE,
        CURLOPT_POSTFIELDS => $postfields,
        CURLOPT_HTTPHEADER => $headers,
    ));
}