function HttpRequestTest::testDrupalHTTPRequestBasicAuth

Tests HTTP basic authorization.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Common/HttpRequestTest.php, line 82
Definition of Drupal\system\Tests\Common\HttpRequestTest.

Class

HttpRequestTest
Tests drupal_http_request().

Namespace

Drupal\system\Tests\Common

Code

function testDrupalHTTPRequestBasicAuth() {
  $username = $this
    ->randomName();
  $password = $this
    ->randomName();
  $url = url('system-test/auth', array(
    'absolute' => TRUE,
  ));
  $auth = str_replace('://', '://' . $username . ':' . $password . '@', $url);
  $result = drupal_http_request($auth);
  $this
    ->drupalSetContent($result->data);
  $this
    ->assertRaw($username, '$_SERVER["PHP_AUTH_USER"] is passed correctly.');
  $this
    ->assertRaw($password, '$_SERVER["PHP_AUTH_PW"] is passed correctly.');
}