Index: modules/simpletest/drupal_web_test_case.php =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v retrieving revision 1.25 diff -u -r1.25 drupal_web_test_case.php --- modules/simpletest/drupal_web_test_case.php 5 Jul 2008 07:19:31 -0000 1.25 +++ modules/simpletest/drupal_web_test_case.php 17 Jul 2008 17:22:42 -0000 @@ -18,6 +18,8 @@ protected $curl_options = array(); protected $db_prefix_original; protected $original_file_directory; + protected $test_profile; + protected $profile_checked = FALSE; var $_results = array('#pass' => 0, '#fail' => 0, '#exception' => 0); var $_assertions = array(); @@ -596,7 +598,7 @@ return $user; } - /* + /** * Logs a user out of the internal browser, then check the login page to confirm logout. */ function drupalLogout() { @@ -612,6 +614,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 + * 'default'). If an invalid profile name was set (the profile does not + * exist), the profile will be set to 'default'. + */ + function getInstallProfile() { + // Use the variable if no name was set,. + if (empty($this->test_profile)) { + $this->test_profile = variable_get('web_test_case_profile', 'default'); + } + // Check for this existance of the profile. + if (!$this->profile_checked) { + $profile = $this->test_profile; + if (!file_exists("./profiles/$profile/$profile.profile")) { + // Use the default profile if the specified one is missing. + $this->test_profile = 'default'; + } + $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 @@ -627,20 +676,21 @@ // Store necessary current values before switching to prefixed database. $this->db_prefix_original = $db_prefix; $clean_url_original = variable_get('clean_url', 0); + $profile = $this->getInstallProfile(); // Generate temporary prefixed database to ensure that tests have a clean starting point. $db_prefix = 'simpletest' . mt_rand(1000, 1000000); include_once './includes/install.inc'; drupal_install_system(); - // Add the specified modules to the list of modules in the default profile. + // Add the specified modules to the list of modules in the specified profile. $args = func_get_args(); - $modules = array_unique(array_merge(drupal_verify_profile('default', 'en'), $args)); + $modules = array_unique(array_merge(drupal_verify_profile($profile, 'en'), $args)); drupal_install_modules($modules); - // Run default profile tasks. + // Run the specified profile's tasks. $task = 'profile'; - default_profile_tasks($task, ''); + call_user_func($profile .'_profile_tasks', $task, ''); // Rebuild caches. menu_rebuild(); @@ -650,7 +700,7 @@ $this->checkPermissions(array(), TRUE); // Restore necessary variables. - variable_set('install_profile', 'default'); + variable_set('install_profile', $profile); variable_set('install_task', 'profile-finished'); variable_set('clean_url', $clean_url_original); @@ -707,7 +757,8 @@ // Rebuild caches. $this->refreshVariables(); - + // Reset the install profile to be used for tests. + $this->resetInstallProfile(); // Close the CURL handler. $this->curlClose(); restore_error_handler(); Index: includes/tests/install.test =================================================================== RCS file: includes/tests/install.test diff -N includes/tests/install.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ includes/tests/install.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,103 @@ +test_profile; + } + + $this->assertEqual($profile, $this->getInstallProfile(), t('The correct profile was used')); + + $installed_modules = module_list(FALSE, FALSE); + $profile_modules = drupal_verify_profile($profile, 'en'); + $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 default profile is reset correctly. + */ + function assertResetProfile() { + $this->setInstallProfile($this->randomName()); + $this->assertEqual('default', $this->getInstallProfile(), t("The profile 'default' is returned in place of an invalid profile name")); + } +} + +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 the node types defined. + $types = node_get_types(); + $this->assertTrue(empty($types), t('No node types are defined')); + + $this->assertResetProfile(); + } +} + +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(); + + // @todo: include other tests/assertions here. + + $this->assertResetProfile(); + } +}