=== added file 'includes/tests/install.test'
--- includes/tests/install.test	1970-01-01 00:00:00 +0000
+++ includes/tests/install.test	2010-04-20 04:11:41 +0000
@@ -0,0 +1,141 @@
+<?php
+// $Id$
+
+class InstallProfileTestCase extends DrupalWebTestCase {
+  
+  /**
+   * Assert that the required modules are installed and active.
+   */
+  function assertInstalledModules($profile = NULL, $locale = 'en') {
+    if (empty($profile)) {
+      $profile = $this->getInstallProfile();
+    }
+    
+    $profile_file = "./profiles/$profile/$profile.profile";
+    
+    if (!file_exists($profile_file)) {
+      $this->fail(t('Install profile file found.'), t('Profile)'));
+    }
+    else {
+      require_once($profile_file);
+      
+      // Get a list of modules required by this profile.
+      $function = $profile . '_profile_modules';
+      $profile_modules = array_merge(drupal_required_modules(), $function(), ($locale != 'en' ? array('locale') : array()));
+
+      $this->assertEqual($profile, $this->getInstallProfile(), t('The correct profile was used'));
+     
+      $installed_modules = module_list(FALSE, FALSE);
+      $this->assertEqual(count($installed_modules), count($profile_modules), t('Expected number of modules are active'));
+      
+      // Test that the modules are active.
+      foreach ($profile_modules as $name) {
+        $this->assertTrue(isset($installed_modules[$name]), t('%name module is active', array('%name' => $name)));
+      }
+    }
+  }
+  
+  /**
+   * Assert that the expected node types were defined.
+   *
+   * @param
+   *  Each type expected to be created should be passed as a parameter.
+   */  
+  function assertNodeTypesCreated() {
+    $expected_types = func_get_args();
+    $types = node_get_types();
+    $diff = array_diff(array_keys($types), $expected_types);
+    $this->assertTrue(empty($diff), t('Node types defined correctly.'));
+  }
+}
+
+class DefaultProfileTestCase extends InstallProfileTestCase {
+
+  /**
+   * Implementation of getInfo().
+   */
+  function getInfo() {
+    return array(
+      'name' => t('Default install profile tests'),
+      'description' => t('Check that the default install profile works as expected.'),
+      'group' => t('Install profiles')
+    );
+  }
+
+  /**
+   * Implementation of setUp().
+   */
+  function setUp() {
+    $this->setInstallProfile('default');
+    parent::setUp();
+  }
+
+  /**
+   * Test the default profile.
+   */
+  function testDefaultProfile() {
+    $this->assertInstalledModules();
+    
+    // Test that the expected node types are defined.
+    $this->assertNodeTypesCreated('page', 'article');
+    
+    // Test if a default vocabulary named "Tags" is enabled for the 'article' content type.
+    $vocabularies = module_invoke('taxonomy', 'get_vocabularies');
+    $count = count($vocabularies);
+    $this->assertEqual(1, $count, t('1 vocabulary expected, !count found', array('!count' => $count)));
+    if ($count) {
+      $voc = array_shift($vocabularies);
+      $values = taxonomy_vocabulary_load($voc->vid);
+      $default_values = array(
+        'name' => 'Tags',
+        'relations' => 0, 'hierarchy' => 0, 'multiple' => 0, 'required' => 0, 'tags' => 1,
+        'module' => 'taxonomy',               
+        'weight' => 0,
+      );
+      foreach($default_values as $key => $value) {
+        $this->assertEqual($value, $values->$key, t('Checking vocabulary value of %key.', array('%key' => $key)));
+      }
+      $this->assertEqual(array('article' => 'article'), $voc->nodes, t('Default vocabulary node types are correct.'));
+    }
+
+    $this->setInstallProfile($this->randomName());
+    $this->assertEqual('default', $this->getInstallProfile(), t("The profile 'default' is returned in place of an invalid profile name"));
+    // @todo: include other tests/assertions here.
+  }
+}
+
+
+class ExpertProfileTestCase extends InstallProfileTestCase {
+
+  /**
+   * Implementation of getInfo().
+   */
+  function getInfo() {
+    return array(
+      'name' => t('Expert install profile tests'),
+      'description' => t('Check that the expert install profile works as expected.'),
+      'group' => t('Install profiles')
+    );
+  }
+
+  /**
+   * Implementation of setUp().
+   */
+  function setUp() {
+    $this->setInstallProfile('expert');
+    parent::setUp();
+  }
+
+  /**
+   * Test the expert profile.
+   */
+  function testExpertProfile() {
+    $this->assertInstalledModules();
+    
+    $this->assertFalse(module_exists('locale'), t('Locale module was disabled'));
+    
+    // Test that no node types are defined.
+    $this->assertNodeTypesCreated();
+  }
+}
+

=== modified file 'modules/simpletest/drupal_web_test_case.php'
--- modules/simpletest/drupal_web_test_case.php	2010-04-20 04:41:19 +0000
+++ modules/simpletest/drupal_web_test_case.php	2010-04-20 04:41:55 +0000
@@ -712,6 +712,16 @@ class DrupalWebTestCase extends DrupalTe
   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 @@ class DrupalWebTestCase extends DrupalTe
     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 @@ class DrupalWebTestCase extends DrupalTe
   }
 
   /**
+   * 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 @@ class DrupalWebTestCase extends DrupalTe
     $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 @@ class DrupalWebTestCase extends DrupalTe
 
     $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 @@ class DrupalWebTestCase extends DrupalTe
       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 @@ class DrupalWebTestCase extends DrupalTe
     $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 @@ class DrupalWebTestCase extends DrupalTe
     $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');

