diff -u b/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php --- b/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -85,6 +85,10 @@ */ protected $setup = FALSE; + protected $setupDatabasePrefix = FALSE; + + protected $setupEnvironment = FALSE; + /** * Constructor for DrupalTestCase. * @@ -1284,6 +1288,12 @@ protected function changeDatabasePrefix() { if (empty($this->databasePrefix)) { $this->prepareDatabasePrefix(); + // If $this->prepareDatabasePrefix() failed to work, return without + // setting $this->setupDatabasePrefix to TRUE, so setUp() methods will + // know to bail out. + if (empty($this->databasePrefix)) { + return; + } } // Clone the current connection and replace the current prefix. @@ -1295,6 +1305,9 @@ ); } Database::addConnectionInfo('default', 'default', $connection_info['default']); + + // Indicate the database prefix was set up correctly. + $this->setupDatabasePrefix = TRUE; } /** @@ -1355,6 +1368,9 @@ $test_info = &$GLOBALS['drupal_test_info']; $test_info['test_run_id'] = $this->databasePrefix; $test_info['in_child_site'] = FALSE; + + // Indicate the environment was set up correctly. + $this->setupEnvironment = TRUE; } /** @@ -1386,6 +1402,9 @@ // Prepare the environment for running tests. $this->prepareEnvironment(); + if (!$this->setupEnvironment) { + return FALSE; + } // Reset all statics and variables to perform tests in a clean environment. $conf = array(); @@ -1396,6 +1415,9 @@ // changed, since DrupalCacheArray implementations attempt to // write back to persistent caches when they are destructed. $this->changeDatabasePrefix(); + if (!$this->setupDatabasePrefix) { + return FALSE; + } // Preset the 'install_profile' system variable, so the first call into // system_rebuild_module_data() (in drupal_install_system()) will register diff -u b/modules/simpletest/tests/upgrade/upgrade.test b/modules/simpletest/tests/upgrade/upgrade.test --- b/modules/simpletest/tests/upgrade/upgrade.test +++ b/modules/simpletest/tests/upgrade/upgrade.test @@ -102,6 +102,9 @@ // Prepare the environment for running tests. $this->prepareEnvironment(); + if (!$this->setupEnvironment) { + return FALSE; + } // Reset all statics and variables to perform tests in a clean environment. $conf = array(); @@ -112,6 +115,9 @@ // changed, since DrupalCacheArray implementations attempt to // write back to persistent caches when they are destructed. $this->changeDatabasePrefix(); + if (!$this->setupDatabasePrefix) { + return FALSE; + } // Unregister the registry. // This is required to make sure that the database layer works properly.