diff --git a/core/lib/Drupal/Core/Config/GlobalConfig.php b/core/lib/Drupal/Core/Config/GlobalConfig.php index 204697e..9d29ed6 100644 --- a/core/lib/Drupal/Core/Config/GlobalConfig.php +++ b/core/lib/Drupal/Core/Config/GlobalConfig.php @@ -86,7 +86,7 @@ public function set($config_name, $keys, $value) { // Inlined NestedArray::setValue(), because this class is used before the // class loader is available. $ref = &$this->storage; - foreach (array_merge($config_name, explode('.', $keys)) as $key) { + foreach (array_merge(array($config_name), explode('.', $keys)) as $key) { $ref = &$ref[$key]; } $ref = $value; @@ -113,7 +113,7 @@ public function del($config_name, $keys = NULL) { else { // Inlined NestedArray::unsetValue(), because this class is used before // the class loader is available. - $parents = array_merge($config_name, explode('.', $keys)); + $parents = array_merge(array($config_name), explode('.', $keys)); $unset_key = array_pop($parents); $ref = &$this->storage; foreach ($parents as $key) { diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index e8f72a4..d1bb1e3 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -229,11 +229,6 @@ public static function getInfo() { } /** - * Performs setup tasks before each individual test method is run. - */ - abstract protected function setUp(); - - /** * Checks the matching requirements for Test. * * @return @@ -920,7 +915,6 @@ protected function prepareEnvironment() { $this->originalPrefix = drupal_valid_test_ua(); drupal_valid_test_ua($this->databasePrefix); } - $this->globalConfig = GlobalConfig::getInstance(); // Backup current in-memory configuration. $this->originalSettings = settings()->getAll(); @@ -942,9 +936,6 @@ protected function prepareEnvironment() { $this->originalProfile = drupal_get_profile(); $this->originalUser = isset($user) ? clone $user : NULL; - // Remove all configuration overrides. - $this->globalConfig->setConfig(array()); - // Ensure that the current session is not changed by the new environment. require_once DRUPAL_ROOT . '/' . settings()->get('session_inc', 'core/includes/session.inc'); drupal_save_session(FALSE); @@ -978,12 +969,7 @@ protected function prepareEnvironment() { // Create and set new configuration directories. $this->prepareConfigDirectories(); - // Apply global configuration override values. - foreach ($this->configOverrides as $config_name => $config_values) { - foreach ($config_values as $key => $value) { - $this->globalConfig->set($config_name, $key, $value); - } - } + $this->globalConfig = GlobalConfig::getInstance(); // Reset statics before the old container is replaced so that objects with a // __destruct() method still have access to it. @@ -1078,6 +1064,45 @@ protected function rebuildContainer() { } /** + * Performs setup tasks before each individual test method is run. + */ + protected function setUp() { + // Create the database prefix for this test. + $this->prepareDatabasePrefix(); + + // Prepare the environment for running tests. + $this->prepareEnvironment(); + if (!$this->setupEnvironment) { + throw new \RuntimeException('Failed to set up test environment.'); + } + + // Change the database prefix. + // All static variables need to be reset before the database prefix is + // changed, since \Drupal\Core\Utility\CacheArray implementations attempt to + // write back to persistent caches when they are destructed. + $this->changeDatabasePrefix(); + if (!$this->setupDatabasePrefix) { + throw new \RuntimeException('Failed to set up database prefix.'); + } + + // After preparing the environment and changing the database prefix, we are + // in a valid test environment. + drupal_valid_test_ua($this->databasePrefix); + + // Remove all configuration overrides. + $this->globalConfig->setConfig(array()); + + // Apply global configuration override values. + foreach ($this->configOverrides as $config_name => $config_values) { + foreach ($config_values as $key => $value) { + $this->globalConfig->set($config_name, $key, $value); + } + } + + $this->setup = TRUE; + } + + /** * Performs cleanup tasks after each individual test method has been run. * * Deletes created files, database tables, and reverts environment changes. diff --git a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php index f2bad12..7f20fed 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php @@ -41,29 +41,8 @@ function __construct($test_id = NULL) { * setUp() method. */ protected function setUp() { - // Create the database prefix for this test. - $this->prepareDatabasePrefix(); - - // Prepare the environment for running tests. - $this->prepareEnvironment(); - if (!$this->setupEnvironment) { - return FALSE; - } - - // Reset all statics to perform tests in a clean environment. - drupal_static_reset(); + parent::setUp(); $this->settingsSet('file_public_path', $this->public_files_directory); - - // Change the database prefix. - // All static variables need to be reset before the database prefix is - // 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; - } - - $this->setup = TRUE; } } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index ef2d396..90bb51b 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -724,26 +724,7 @@ protected function setUp() { // Backup the currently running Simpletest batch. $this->originalBatch = batch_get(); - // Create the database prefix for this test. - $this->prepareDatabasePrefix(); - - // Prepare the environment for running tests. - $this->prepareEnvironment(); - if (!$this->setupEnvironment) { - return FALSE; - } - - // Reset all statics to perform tests in a clean environment. - drupal_static_reset(); - - // Change the database prefix. - // All static variables need to be reset before the database prefix is - // 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; - } + parent::setUp(); // Add the parent profile's search path to the child site's search paths. // @see drupal_system_listing() diff --git a/core/modules/system/lib/Drupal/system/Tests/InstallerTest.php b/core/modules/system/lib/Drupal/system/Tests/InstallerTest.php index 6edabe0..2ae1f78 100644 --- a/core/modules/system/lib/Drupal/system/Tests/InstallerTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/InstallerTest.php @@ -37,21 +37,25 @@ protected function setUp() { // Prepare the environment for running tests. $this->prepareEnvironment(); if (!$this->setupEnvironment) { - return FALSE; + throw new \RuntimeException('Failed to set up test environment.'); } - // Reset all statics to perform tests in a clean environment. - drupal_static_reset(); - // Change the database prefix. // All static variables need to be reset before the database prefix is // 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; + throw new \RuntimeException('Failed to set up database prefix.'); } + // After preparing the environment and changing the database prefix, we are + // in a valid test environment. + drupal_valid_test_ua($this->databasePrefix); + + // Remove all configuration overrides. + $this->globalConfig->setConfig(array()); + $this->globalConfig->set('system.file', 'path.private', $this->private_files_directory); $this->globalConfig->set('system.file', 'path.temporary', $this->temp_files_directory); $this->globalConfig->set('locale.settings', 'translation.path', $this->translation_files_directory);