You are here

protected function DrupalWebTestCase::curlInitialize in SimpleTest 7

Same name and namespace in other branches
  1. 6.2 drupal_web_test_case.php \DrupalWebTestCase::curlInitialize()
  2. 7.2 drupal_web_test_case.php \DrupalWebTestCase::curlInitialize()

Initializes the cURL connection.

If the simpletest_httpauth_credentials variable is set, this function will add HTTP authentication headers. This is necessary for testing sites that are protected by login credentials from public access. See the description of $curl_options for other options.

1 call to DrupalWebTestCase::curlInitialize()
DrupalWebTestCase::curlExec in ./drupal_web_test_case.php
Performs a cURL exec with the specified options after calling curlConnect().

File

./drupal_web_test_case.php, line 1226

Class

DrupalWebTestCase
Test case for typical Drupal tests.

Code

protected function curlInitialize() {
  global $base_url, $db_prefix;
  if (!isset($this->curlHandle)) {
    $this->curlHandle = curl_init();
    $curl_options = $this->additionalCurlOptions + array(
      CURLOPT_COOKIEJAR => $this->cookieFile,
      CURLOPT_URL => $base_url,
      CURLOPT_FOLLOWLOCATION => TRUE,
      CURLOPT_MAXREDIRS => 5,
      CURLOPT_RETURNTRANSFER => TRUE,
      CURLOPT_SSL_VERIFYPEER => FALSE,
      // Required to make the tests run on https.
      CURLOPT_SSL_VERIFYHOST => FALSE,
      // Required to make the tests run on https.
      CURLOPT_HEADERFUNCTION => array(
        &$this,
        'curlHeaderCallback',
      ),
    );
    if (isset($this->httpauth_credentials)) {
      $curl_options[CURLOPT_USERPWD] = $this->httpauth_credentials;
    }
    curl_setopt_array($this->curlHandle, $this->additionalCurlOptions + $curl_options);

    // By default, the child session name should be the same as the parent.
    $this->session_name = session_name();
  }

  // We set the user agent header on each request so as to use the current
  // time and a new uniqid.
  if (preg_match('/simpletest\\d+/', $db_prefix, $matches)) {
    curl_setopt($this->curlHandle, CURLOPT_USERAGENT, drupal_generate_test_ua($matches[0]));
  }
}