You are here

protected function BetterStatisticsTest::betterStatisticsPost in Better Statistics 7

Execute a POST request against a Drupal path with a JSON payload.

Parameters

$path: Endpoint against which to POST. Either a Drupal path or an absolute path.

$data: Data in an associative array. This will be JSON encoded.

$options: Options to be forwarded to url().

$headers: An array containing additional HTTP request headers, each formatted as "name: value".

1 call to BetterStatisticsTest::betterStatisticsPost()
BetterStatisticsTest::testDataCollection in ./better_statistics.test
Test data collection functionality.

File

./better_statistics.test, line 473
Tests for the Better Statistics Module.

Class

BetterStatisticsTest
Functional tests for Better Statistics.

Code

protected function betterStatisticsPost($path, array $data = array(), array $options = array(), array $headers = array()) {
  $url = $this
    ->getAbsoluteUrl(url($path, $options));
  $post = drupal_json_encode($data);
  $headers[] = 'Content-Type: application/json; charset=utf-8';
  $headers[] = 'Content-Length: ' . strlen($post);
  $out = $this
    ->simpleCurlExec(array(
    CURLOPT_URL => $url,
    CURLOPT_POST => TRUE,
    CURLOPT_POSTFIELDS => $post,
    CURLOPT_HTTPHEADER => $headers,
  ));
  $this
    ->verbose('POST request to: ' . $url . '<hr />Data: ' . highlight_string('<?php ' . var_export($data, TRUE), TRUE) . '<hr />' . $out);
  return $out;
}