Index: modules/simpletest/tests/common.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v retrieving revision 1.4 diff -u -r1.4 common.test --- modules/simpletest/tests/common.test 29 Aug 2008 14:45:19 -0000 1.4 +++ modules/simpletest/tests/common.test 30 Aug 2008 23:48:04 -0000 @@ -129,6 +129,13 @@ ); } + /** + * Implementation of setUp(). + */ + function setUp() { + parent::setUp('drupal_http_request_test'); + } + function testDrupalHTTPRequest() { // Parse URL schema. $missing_scheme = drupal_http_request('example.com/path'); @@ -143,4 +150,30 @@ $this->drupalSetContent($result->data); $this->assertTitle(variable_get('site_name', 'Drupal'), t('Site title matches.')); } + + function testDrupalHTTPRequestBasicAuth() { + $username = $this->randomName(); + $password = $this->randomName(); + $url = url('drupal_http_request_test', array('absolute' => TRUE)); + + $auth = str_replace('http://', 'http://' . $username . ':' . $password .'@', $url); + $result = drupal_http_request($auth); + + // We use strpos directly. + // assertRaw() cannot be used because we are getting the data + // in a variable instead of $this->_content. + $this->assertTrue(strpos($result->data, $username) !== FALSE, t('$_SERVER[\'PHP_AUTH_USER\'] is passed correctly.')); + $this->assertTrue(strpos($result->data, $password) !== FALSE, t('$_SERVER[\'PHP_AUTH_PW\'] is passed correctly.')); + } + + function testDrupalHTTPRequestRedirect() { + $redirect_301 = drupal_http_request(url('drupal_http_request_test/301', array('absolute' => TRUE)), array(), 'GET', NULL, 1); + $this->assertEqual($redirect_301->redirect_code, 200, t('drupal_http_request follows the 301 redirect.')); + + $redirect_302 = drupal_http_request(url('drupal_http_request_test/302', array('absolute' => TRUE)), array(), 'GET', NULL, 1); + $this->assertEqual($redirect_302->redirect_code, 200, t('drupal_http_request follows the 302 redirect.')); + + $redirect_307 = drupal_http_request(url('drupal_http_request_test/307', array('absolute' => TRUE)), array(), 'GET', NULL, 1); + $this->assertEqual($redirect_307->redirect_code, 200, t('drupal_http_request follows the 307 redirect.')); + } } Index: modules/simpletest/tests/drupal_http_request_test.module =================================================================== RCS file: modules/simpletest/tests/drupal_http_request_test.module diff -N modules/simpletest/tests/drupal_http_request_test.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/simpletest/tests/drupal_http_request_test.module 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,64 @@ + 'drupal_http_request_test_basic_auth_page', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); + + $items['drupal_http_request_test/301'] = array( + 'title' => t('Redirect'), + 'page callback' => 'drupal_http_request_test_301', + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); + $items['drupal_http_request_test/302'] = array( + 'title' => t('Redirect'), + 'page callback' => 'drupal_http_request_test_302', + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); + $items['drupal_http_request_test/307'] = array( + 'title' => t('Redirect'), + 'page callback' => 'drupal_http_request_test_307', + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); + $items['drupal_http_request_test/200'] = array( + 'title' => t('Redirect'), + 'page callback' => 'drupal_http_request_test_200', + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); + + return $items; +} + +function drupal_http_request_test_basic_auth_page() { + $output = t('$_SERVER[\'PHP_AUTH_USER\'] is @username.', array('@username' => $_SERVER['PHP_AUTH_USER'])); + $output .= t('$_SERVER[\'PHP_AUTH_PW\'] is @password.', array('@password' => $_SERVER['PHP_AUTH_PW'])); + return $output; +} + +function drupal_http_request_test_301() { + header("Location: " . url('drupal_http_request_test/200', array('absolute' => TRUE)), TRUE, 301); +} + +function drupal_http_request_test_302() { + header("Location: " . url('drupal_http_request_test/200', array('absolute' => TRUE)), TRUE, 302); +} + +function drupal_http_request_test_307() { + header("Location: " . url('drupal_http_request_test/200', array('absolute' => TRUE)), TRUE, 307); +} + +function drupal_http_request_test_200() { + return ''; +} Index: modules/simpletest/tests/drupal_http_request_test.info =================================================================== RCS file: modules/simpletest/tests/drupal_http_request_test.info diff -N modules/simpletest/tests/drupal_http_request_test.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/simpletest/tests/drupal_http_request_test.info 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,8 @@ +; $Id$ +name = "drupal_http_request Test" +description = "Support module for drupal_http_request testing." +package = Testing +version = VERSION +core = 7.x +files[] = drupal_http_request_test.module +hidden = TRUE