### Eclipse Workspace Patch 1.0
#P simpletest
Index: simpletest.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/simpletest.module,v
retrieving revision 1.37
diff -u -r1.37 simpletest.module
--- simpletest.module	23 Mar 2008 03:35:38 -0000	1.37
+++ simpletest.module	23 Mar 2008 21:20:20 -0000
@@ -83,11 +83,22 @@
  * Menu callback for both running tests and listing possible tests
  */
 function simpletest_entrypoint() {
+  global $simpletest_ua_handling;
   if (!simpletest_load()) {
      // @TODO - Find a better way for this return.  It is currently needed to show error,
      // and returning true leads to page not found
     return '&nbsp;';
   }
+  if (!$simpletest_ua_handling) {
+    $output = t('Please add the following code to the bottom of settings.php');
+    $output .=
+'<p><code><pre>$GLOBALS["simpletest_ua_handling"] = TRUE;
+$GLOBALS["simpletest_ua_key"] = '. mt_rand(1000, 1000000) .';
+if (preg_match("/(simpletest\d+),(\d+)/", $_SERVER["HTTP_USER_AGENT"], $matches) && $GLOBALS["simpletest_ua_key"] == $matches[2]) {
+  $db_prefix = $matches[1];
+}</pre></code></p>';
+    return $output;
+  }
   drupal_add_js(drupal_get_path('module', 'simpletest') .'/simpletest.js', 'module');
   $output = drupal_get_form('simpletest_overview_form');
 
Index: drupal_test_case.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/drupal_test_case.php,v
retrieving revision 1.63
diff -u -r1.63 drupal_test_case.php
--- drupal_test_case.php	23 Mar 2008 03:35:38 -0000	1.63
+++ drupal_test_case.php	23 Mar 2008 21:20:20 -0000
@@ -357,10 +357,40 @@
       $this->assertField("pass");
   }
 
+  function setUp() {
+    global $db_prefix, $simpletest_ua_handling;
+    if ($simpletest_ua_handling) {
+      $this->db_prefix_original = $db_prefix;
+      $db_prefix = 'simpletest'. mt_rand(1000, 1000000);
+      include_once './includes/install.inc';
+      drupal_install_system();
+      $module_list = drupal_verify_profile('default', 'en');
+      drupal_install_modules($module_list);
+      $task = 'profile';
+      default_profile_tasks($task, '');
+      menu_rebuild();
+      actions_synchronize();
+      _drupal_flush_css_js();
+      variable_set('install_profile', 'default');
+      variable_set('install_task', 'profile-finished');
+    }
+    parent::setUp();
+  }
+
   /**
    * tearDown implementation, setting back switched modules etc
    */
   function tearDown() {
+    global $db_prefix;
+    if (preg_match('/simpletest\d+/', $db_prefix)) {
+      $schema = drupal_get_schema(NULL, TRUE);
+      $ret = array();
+      foreach ($schema as $name => $table) {
+        db_drop_table($ret, $name);
+      }
+      $db_prefix = $this->db_prefix_original;
+      return;
+    }
     if ($this->_modules != $this->_originalModules) {
       $form_state['values'] = array('status' => $this->_originalModules, 'op' => t('Save configuration'));
       drupal_execute('system_modules', $form_state);
@@ -446,7 +476,7 @@
    * Also, see the description of $curl_options among the properties.
    */
   protected function curlConnect() {
-    global $base_url;
+    global $base_url, $db_prefix, $simpletest_ua_key;
     if (!isset($this->ch)) {
       $this->ch = curl_init();
       $curl_options = $this->curl_options + array(
@@ -455,6 +485,9 @@
         CURLOPT_FOLLOWLOCATION => TRUE,
         CURLOPT_RETURNTRANSFER => TRUE,
       );
+      if (preg_match('/simpletest\d+/', $db_prefix)) {
+        $curl_options[CURLOPT_USERAGENT] = $db_prefix .','. $simpletest_ua_key;
+      }
       if (!isset($curl_options[CURLOPT_USERPWD]) && ($auth = variable_get('simpletest_httpauth_username', ''))) {
         if ($pass = variable_get('simpletest_httpauth_pass', '')) {
           $auth .= ':'. $pass;
