Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.210
diff -u -F '^f' -u -F '^f' -r1.210 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	11 Apr 2010 18:33:44 -0000	1.210
+++ modules/simpletest/drupal_web_test_case.php	20 Apr 2010 04:33:09 -0000
@@ -712,6 +712,16 @@
   protected $redirect_count;
 
   /**
+   * The short project name of the profile to use for the test.
+   */
+  protected $test_profile;
+
+  /**
+   * Boolean indicating if the selected profile has been checked for existence.
+   */
+  protected $profile_checked;
+
+  /**
    * Constructor for DrupalWebTestCase.
    */
   function __construct($test_id = NULL) {
@@ -1075,7 +1085,7 @@
     return md5($this->session_id . $value . $private_key);
   }
 
-  /*
+  /**
    * Logs a user out of the internal browser, then check the login page to confirm logout.
    */
   protected function drupalLogout() {
@@ -1092,6 +1102,53 @@
   }
 
   /**
+   * Set the install profile to be used during the test.
+   *
+   * This method is primarily for use in testing install profiles, and should be
+   * called in the class's setUp() function before calling parent::setUp().
+   *
+   * @param $profile
+   *   The name of an install profile.
+   */
+  function setInstallProfile($profile) {
+    $this->test_profile = $profile;
+    $this->profile_checked = FALSE;
+  }
+
+  /**
+   * Reset the install profile to be used during the test.
+   */
+  function resetInstallProfile() {
+    unset($this->test_profile);
+    $this->profile_checked = FALSE;
+  }
+
+  /**
+   * Get the install profile to be used during the test.
+   *
+   *  The most recently set name will be returned, or by default the value from
+   *  the variable 'web_test_case_profile' will be returned (defaults to 
+   *  'standard'). If an invalid profile name was set (the profile does not
+   *  exist), the profile will be set to 'standard'.
+   */
+  function getInstallProfile() {
+    // Use the variable if no name was set,.
+    if (empty($this->test_profile)) {
+      $this->test_profile = variable_get('web_test_case_profile', 'standard');
+    }
+    // Check for this existence of the profile.
+    if (!$this->profile_checked) {
+      $profile = $this->test_profile;
+      if (!file_exists("./profiles/$profile/$profile.profile")) {
+        // Use the standard profile if the specified one is missing.
+        $this->test_profile = 'standard';
+      }
+      $this->profile_checked = TRUE;
+    }
+    return $this->test_profile;
+  }
+
+  /**
    * Generates a random database prefix, runs the install scripts on the
    * prefixed database and enable the specified modules. After installation
    * many caches are flushed and the internal browser is setup so that the
@@ -1121,6 +1178,9 @@
     $this->originalShutdownCallbacks = $callbacks;
     $callbacks = array();
 
+    // Get the specified install profile.
+    $profile = $this->getInstallProfile();
+
     // Generate temporary prefixed database to ensure that tests have a clean starting point.
     $db_prefix_new = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}');
     db_update('simpletest_test_id')
@@ -1155,11 +1215,11 @@
 
     $this->preloadRegistry();
 
-    // Include the default profile.
-    variable_set('install_profile', 'standard');
-    $profile_details = install_profile_info('standard', 'en');
+    // Include the specified profile.
+    variable_set('install_profile', $profile);
+    $profile_details = install_profile_info($profile, 'en');
 
-    // Install the modules specified by the default profile.
+    // Install the modules specified by the profile.
     module_enable($profile_details['dependencies'], FALSE);
 
     // Install modules needed for this test. This could have been passed in as
@@ -1174,8 +1234,8 @@
       module_enable($modules, TRUE);
     }
 
-    // Run default profile tasks.
-    module_enable(array('standard'), FALSE);
+    // Run profile tasks.
+    module_enable(array($profile), FALSE);
 
     // Rebuild caches.
     drupal_static_reset();
@@ -1188,6 +1248,9 @@
     $this->refreshVariables();
     $this->checkPermissions(array(), TRUE);
 
+    // Reset the install profile to be used for tests.
+    $this->resetInstallProfile();
+
     // Reset statically cached schema for new database prefix.
     drupal_get_schema(NULL, TRUE);
 
@@ -1201,6 +1264,7 @@
     $user = user_load(1);
 
     // Restore necessary variables.
+    variable_set('install_profile', $this->originalProfile);
     variable_set('install_task', 'done');
     variable_set('clean_url', $clean_url_original);
     variable_set('site_mail', 'simpletest@example.com');
