Index: modules/simpletest/drupal_web_test_case.php =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v retrieving revision 1.139 diff -u -r1.139 drupal_web_test_case.php --- modules/simpletest/drupal_web_test_case.php 20 Aug 2009 03:16:06 -0000 1.139 +++ modules/simpletest/drupal_web_test_case.php 21 Aug 2009 03:54:32 -0000 @@ -398,7 +398,8 @@ $username = variable_get('simpletest_username', NULL); $password = variable_get('simpletest_password', NULL); if ($username && $password) { - $this->httpauth_credentials = $username . ':' . $password; + $this->httpauth_username = $username; + $this->httpauth_password = $password; } set_error_handler(array($this, 'errorHandler')); @@ -571,6 +572,14 @@ * Test case for typical Drupal tests. */ class DrupalWebTestCase extends DrupalTestCase { + + /** + * Browser instance. + * + * @var object + */ + protected $browser; + /** * The URL currently loaded in the internal browser. * @@ -662,6 +671,7 @@ */ function __construct($test_id = NULL) { parent::__construct($test_id); + $this->skipClasses[__CLASS__] = TRUE; } @@ -1260,6 +1270,50 @@ } /** + * Initialize browser. + */ + protected function browserInitialize() { + global $db_prefix; + + if (!isset($this->browser)) { + $this->browser = new Browser(); + $this->browser->setPageListener(array($this, 'browserPageListener')); + + // Generate a user agent based on the db prefix. + if (preg_match('/simpletest\d+/', $db_prefix, $matches)) { + $this->browser->setUserAgent(drupal_generate_test_ua($matches[0])); + } + + if (isset($this->httpauth_username)) { + $this->browser->setHttpAuthentication($this->httpauth_username, $this->httpauth_password); + } + + // By default, the child session name should be the same as the parent. + $this->session_name = session_name(); // TODO + } + } + + protected function browserExecute() { + $this->browserInitialize(); + + $message_vars = array( + '!method' => !empty($curl_options[CURLOPT_NOBODY]) ? 'HEAD' : (empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST'), + '@url' => $url, + '@status' => curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE), + '!length' => format_size(strlen($this->content)) + ); + $message = t('!method @url returned @status (!length).', $message_vars); + $this->assertTrue($this->content !== FALSE, $message, t('Browser')); + } + + /** + * Browser page callback. + */ + public function browserPageListener(array $state) { + + } + + /** * Performs a cURL exec with the specified options after calling curlConnect(). * * @param $curl_options @@ -1380,18 +1434,15 @@ * The retrieved HTML string, also available as $this->drupalGetContent() */ protected function drupalGet($path, array $options = array(), array $headers = array()) { + // The browser requires the URL to be absolute. $options['absolute'] = TRUE; - // We re-using a CURL connection here. If that connection still has certain - // options set, it might change the GET into a POST. Make sure we clear out - // previous options. - $out = $this->curlExec(array(CURLOPT_HTTPGET => TRUE, CURLOPT_URL => url($path, $options), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => $headers)); - $this->refreshVariables(); // Ensure that any changes to variables in the other thread are picked up. + // Make the GET request. + $state = $this->browser->get(url($path, $options)); + + // Ensure that any changes to variables in the other thread are picked up. + $this->refreshVariables(); - // Replace original page output with new output from redirected page(s). - if (($new = $this->checkForMetaRefresh())) { - $out = $new; - } $this->verbose('GET request to: ' . $path . '
Ending URL: ' . $this->getUrl() . '
' . $out);