You are here

protected function DrupalWebTestCase::curlHeaderCallback in SimpleTest 6.2

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

Reads headers and registers errors received from the tested site.

Parameters

$curlHandler: The cURL handler.

$header: An header.

See also

_drupal_log_error().

File

./drupal_web_test_case.php, line 1543

Class

DrupalWebTestCase
Test case for typical Drupal tests.

Code

protected function curlHeaderCallback($curlHandler, $header) {
  $this->headers[] = $header;

  // Errors are being sent via X-Drupal-Assertion-* headers,
  // generated by _drupal_log_error() in the exact form required
  // by DrupalWebTestCase::error().
  if (preg_match('/^X-Drupal-Assertion-[0-9]+: (.*)$/', $header, $matches)) {

    // Call DrupalWebTestCase::error() with the parameters from the header.
    call_user_func_array(array(
      &$this,
      'error',
    ), unserialize(urldecode($matches[1])));
  }

  // Save cookies.
  if (preg_match('/^Set-Cookie: ' . preg_quote($this->session_name) . '=([a-z90-9]+)/', $header, $matches)) {
    if ($matches[1] != 'deleted') {
      $this->session_id = $matches[1];
    }
    else {
      $this->session_id = NULL;
    }
  }

  // This is required by cURL.
  return strlen($header);
}