diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index 5725ed8..77c0b4d 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -86,6 +86,10 @@ abstract class TestBase { */ protected $setup = FALSE; + protected $setupDatabasePrefix = FALSE; + + protected $setupEnvironment = FALSE; + /** * Constructor for Test. * @@ -593,6 +597,8 @@ abstract class TestBase { ); } Database::addConnectionInfo('default', 'default', $connection_info['default']); + + $this->setupDatabasePrefix = TRUE; } /** @@ -661,6 +667,8 @@ abstract class TestBase { $test_info = &$GLOBALS['drupal_test_info']; $test_info['test_run_id'] = $this->databasePrefix; $test_info['in_child_site'] = FALSE; + + $this->setupEnvironment = TRUE; } /** @@ -687,9 +695,15 @@ abstract class TestBase { } // Delete temporary files directory. + if (!$this->setupEnvironment) { + return FALSE; + } file_unmanaged_delete_recursive($this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10)); // Restore original database connection. + if (!$this->setupDatabasePrefix) { + return FALSE; + } Database::removeConnection('default'); Database::renameConnection('simpletest_original_default', 'default'); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php index a871639..d54912a 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php @@ -43,6 +43,9 @@ abstract class UnitTestBase extends TestBase { // Prepare the environment for running tests. $this->prepareEnvironment(); + if (!$this->setupEnvironment) { + return FALSE; + } $this->originalThemeRegistry = theme_get_registry(FALSE); // Reset all statics and variables to perform tests in a clean environment. @@ -65,6 +68,9 @@ abstract class UnitTestBase extends TestBase { // changed, since Drupal\Core\Utility\CacheArray implementations attempt to // write back to persistent caches when they are destructed. $this->changeDatabasePrefix(); + if (!$this->setupDatabasePrefix) { + return FALSE; + } // Set user agent to be consistent with WebTestBase. $_SERVER['HTTP_USER_AGENT'] = $this->databasePrefix; diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 0856611..b74a00c 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -586,6 +586,9 @@ abstract class WebTestBase extends TestBase { // 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(); @@ -596,6 +599,9 @@ abstract class WebTestBase extends TestBase { // changed, since Drupal\Core\Utility\CacheArray 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 @@ -754,6 +760,9 @@ abstract class WebTestBase extends TestBase { */ protected function tearDown() { // Remove all prefixed tables. + if (!$this->setupDatabasePrefix) { + return FALSE; + } $connection_info = Database::getConnectionInfo('default'); $tables = db_find_tables($connection_info['default']['prefix']['default'] . '%'); if (empty($tables)) {