diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 1568f45..05afefd 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -10,6 +10,7 @@ use Drupal\Core\DrupalKernel; use Drupal\Core\Database\Database; use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\Config\GlobalConfig; use Drupal\Core\Utility\Title; use Symfony\Component\ClassLoader\ApcClassLoader; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -567,15 +568,22 @@ function drupal_settings_initialize() { // Export these settings.php variables to the global namespace. global $databases, $cookie_domain, $conf, $db_prefix, $drupal_hash_salt, $base_secure_url, $base_insecure_url, $config_directories; $conf = array(); + $settings = array(); + $config = array(); // Make conf_path() available as local variable in settings.php. $conf_path = conf_path(); if (is_readable(DRUPAL_ROOT . '/' . $conf_path . '/settings.php')) { include_once DRUPAL_ROOT . '/' . $conf_path . '/settings.php'; } - require_once __DIR__ . '../../lib/Drupal/Component/Utility/Settings.php'; + // Initialize Settings. + require_once __DIR__ . '/../lib/Drupal/Component/Utility/Settings.php'; + new Settings($settings); + + // Initialize global Config overrides. + require_once __DIR__ . '/../lib/Drupal/Core/Config/GlobalConfig.php'; + GlobalConfig::getInstance()->setConfig($config); - new Settings(isset($settings) ? $settings : array()); $is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on'; if (isset($base_url)) { @@ -2251,8 +2259,8 @@ function drupal_valid_test_ua($new_prefix = NULL) { * Very strictly for internal use only. * * Loads settings.php from the simpletest public files directory. These files - * can change the global $conf, the global $config_directories, the return - * value of conf_path(), and settings(). + * can change the global $config_directories, the return value of conf_path(), + * settings(), and $config overrides. * * @param string $test_prefix * The simpletest prefix. @@ -2272,13 +2280,16 @@ function _drupal_load_test_overrides($test_prefix) { $filename = conf_path() . '/files/' . $path_prefix . '/settings.php'; if (file_exists($filename)) { $settings = settings()->getAll(); + $config = GlobalConfig::getInstance()->getAll(); $conf_path = &drupal_static('conf_path'); - // This can override $conf, $conf_path, $settings, and $config_directories. + // This can override $config, $conf_path, $settings, and $config_directories. include $filename; // Keep the overriden $conf_path alive across drupal_static_reset() calls. // @see conf_path() $settings['simpletest_conf_path'] = $conf_path; new Settings($settings); + // Apply $config overrides. + GlobalConfig::getInstance()->setConfig($config); } } diff --git a/core/lib/Drupal/Core/Config/GlobalConfig.php b/core/lib/Drupal/Core/Config/GlobalConfig.php new file mode 100644 index 0000000..9d29ed6 --- /dev/null +++ b/core/lib/Drupal/Core/Config/GlobalConfig.php @@ -0,0 +1,159 @@ +get($config_name). + * + * A singleton is used because this class is used before the container (and the + * class loader) is available. Additionally, the global override configuration + * cannot be altered at runtime; except within a test environment. + * + * @see drupal_settings_initialize() + */ +final class GlobalConfig { + + /** + * Array holding the overridden configuration values, keyed by config name. + * + * @var array + */ + private $storage; + + /** + * Singleton instance. + * + * @var \Drupal\Core\Config\GlobalConfig + */ + private static $instance; + + /** + * Returns the settings instance. + * + * @return \Drupal\Core\Config\GlobalConfig + */ + public static function getInstance() { + if (!isset(self::$instance)) { + self::$instance = new self(); + } + return self::$instance; + } + + /** + * Constructor. + */ + private function __construct() { + self::$instance = $this; + } + + /** + * Sets the global override configuration values. + * + * @param array $config + * An associative array containing all configuration values to override, + * keyed by configuration object name. + */ + public function setConfig(array $config) { + if (isset($this->storage) && !drupal_valid_test_ua()) { + throw new \BadMethodCallException('GlobalConfig is read-only.'); + } + $this->storage = $config; + } + + /** + * Overrides a value for a configuration object. Available for tests only. + * + * @param string $config_name + * The configuration object name for which to set a value. + * @param string $keys + * The key within the configuration object to set; sub-keys delimited by + * dots. + * @param mixed $value + * The value to set. + */ + public function set($config_name, $keys, $value) { + if (!isset($this->storage) || !drupal_valid_test_ua()) { + throw new \BadMethodCallException('GlobalConfig is read-only.'); + } + // Inlined NestedArray::setValue(), because this class is used before the + // class loader is available. + $ref = &$this->storage; + foreach (array_merge(array($config_name), explode('.', $keys)) as $key) { + $ref = &$ref[$key]; + } + $ref = $value; + } + + /** + * Overrides a value for a configuration object. Available for tests only. + * + * @param string $config_name + * The configuration object name for which to set a value. + * @param string $keys + * The key within the configuration object to set; sub-keys delimited by + * dots. + * @param mixed $value + * The value to set. + */ + public function del($config_name, $keys = NULL) { + if (!isset($this->storage) || !drupal_valid_test_ua()) { + throw new \BadMethodCallException('GlobalConfig is read-only.'); + } + if (!isset($keys)) { + unset($this->storage[$config_name]); + } + else { + // Inlined NestedArray::unsetValue(), because this class is used before + // the class loader is available. + $parents = array_merge(array($config_name), explode('.', $keys)); + $unset_key = array_pop($parents); + $ref = &$this->storage; + foreach ($parents as $key) { + $ref = &$ref[$key]; + } + unset($ref[$unset_key]); + } + } + + /** + * Returns whether overridden values exist for a given configuration object name. + * + * @return bool + */ + public function has($config_name) { + return isset($this->storage[$config_name]); + } + + /** + * Returns override values for a configuration object name, if any. + * + * @param string $name + * The name of the setting to return. + * + * @return mixed|null + * The overriden values for the configuration object or NULL if none. + */ + public function get($config_name) { + if ($this->has($config_name)) { + return $this->storage[$config_name]; + } + } + + /** + * Returns all configuration override values. + * + * @return array + */ + public function getAll() { + return $this->storage; + } + +} diff --git a/core/lib/Drupal/Core/EventSubscriber/ConfigGlobalOverrideSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ConfigGlobalOverrideSubscriber.php index 02bf2cb..462d37a 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ConfigGlobalOverrideSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ConfigGlobalOverrideSubscriber.php @@ -9,6 +9,7 @@ use Drupal\Core\Config\Config; use Drupal\Core\Config\ConfigEvent; +use Drupal\Core\Config\GlobalConfig; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -17,24 +18,24 @@ class ConfigGlobalOverrideSubscriber implements EventSubscriberInterface { /** - * Overrides configuration values with values in global $conf variable. + * Overrides configuration values with values from settings.php. * * @param \Drupal\Core\Config\ConfigEvent $event * The Event to process. */ public function configInit(ConfigEvent $event) { - global $conf; - $config = $event->getConfig(); - if (isset($conf[$config->getName()])) { - $config->setOverride($conf[$config->getName()]); + $name = $config->getName(); + $global_config = GlobalConfig::getInstance(); + if ($global_config->has($name)) { + $config->setOverride($global_config->get($name)); } } /** * Implements EventSubscriberInterface::getSubscribedEvents(). */ - static function getSubscribedEvents() { + public static function getSubscribedEvents() { $events['config.init'][] = array('configInit', 30); return $events; } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigOverrideTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigOverrideTest.php index a6016c3..311bb84 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigOverrideTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigOverrideTest.php @@ -10,7 +10,7 @@ use Drupal\simpletest\DrupalUnitTestBase; /** - * Tests configuration overrides via $conf in settings.php. + * Tests configuration overrides via $config in settings.php. */ class ConfigOverrideTest extends DrupalUnitTestBase { @@ -24,7 +24,7 @@ class ConfigOverrideTest extends DrupalUnitTestBase { public static function getInfo() { return array( 'name' => 'Configuration overrides', - 'description' => 'Tests configuration overrides via $conf in settings.php.', + 'description' => 'Tests configuration overrides via $config in settings.php.', 'group' => 'Configuration', ); } @@ -38,7 +38,6 @@ public function setUp() { * Tests configuration override. */ function testConfOverride() { - global $conf; $expected_original_data = array( 'foo' => 'bar', 'baz' => NULL, @@ -47,9 +46,10 @@ function testConfOverride() { // Set globals before installing to prove that the installed file does not // contain these values. - $conf['config_test.system']['foo'] = 'overridden'; - $conf['config_test.system']['baz'] = 'injected'; - $conf['config_test.system']['404'] = 'derp'; + $overrides['config_test.system']['foo'] = 'overridden'; + $overrides['config_test.system']['baz'] = 'injected'; + $overrides['config_test.system']['404'] = 'derp'; + $this->globalConfig->setConfig($overrides); config_install_default_config('module', 'config_test'); @@ -73,10 +73,10 @@ function testConfOverride() { // default). $config = \Drupal::config('config_test.system'); - // Verify that it contains the overridden data from $conf. - $this->assertIdentical($config->get('foo'), $conf['config_test.system']['foo']); - $this->assertIdentical($config->get('baz'), $conf['config_test.system']['baz']); - $this->assertIdentical($config->get('404'), $conf['config_test.system']['404']); + // Verify that it contains the overridden data from $config. + $this->assertIdentical($config->get('foo'), $overrides['config_test.system']['foo']); + $this->assertIdentical($config->get('baz'), $overrides['config_test.system']['baz']); + $this->assertIdentical($config->get('404'), $overrides['config_test.system']['404']); // Set the value for 'baz' (on the original data). $expected_original_data['baz'] = 'original baz'; @@ -86,19 +86,19 @@ function testConfOverride() { $expected_original_data['404'] = 'original 404'; $config->set('404', $expected_original_data['404']); - // Verify that it still contains the overridden data from $conf. - $this->assertIdentical($config->get('foo'), $conf['config_test.system']['foo']); - $this->assertIdentical($config->get('baz'), $conf['config_test.system']['baz']); - $this->assertIdentical($config->get('404'), $conf['config_test.system']['404']); + // Verify that it still contains the overridden data from $config. + $this->assertIdentical($config->get('foo'), $overrides['config_test.system']['foo']); + $this->assertIdentical($config->get('baz'), $overrides['config_test.system']['baz']); + $this->assertIdentical($config->get('404'), $overrides['config_test.system']['404']); // Save the configuration object (having overrides applied). $config->save(); - // Reload it and verify that it still contains overridden data from $conf. + // Reload it and verify that it still contains overridden data from $config. $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), $conf['config_test.system']['foo']); - $this->assertIdentical($config->get('baz'), $conf['config_test.system']['baz']); - $this->assertIdentical($config->get('404'), $conf['config_test.system']['404']); + $this->assertIdentical($config->get('foo'), $overrides['config_test.system']['foo']); + $this->assertIdentical($config->get('baz'), $overrides['config_test.system']['baz']); + $this->assertIdentical($config->get('404'), $overrides['config_test.system']['404']); // Enter an override-free context to ensure the original data remains saved. config_context_enter('config.context.free'); @@ -128,9 +128,9 @@ function testConfOverride() { // Verifiy the overrides are still working. $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), $conf['config_test.system']['foo']); - $this->assertIdentical($config->get('baz'), $conf['config_test.system']['baz']); - $this->assertIdentical($config->get('404'), $conf['config_test.system']['404']); + $this->assertIdentical($config->get('foo'), $overrides['config_test.system']['foo']); + $this->assertIdentical($config->get('baz'), $overrides['config_test.system']['baz']); + $this->assertIdentical($config->get('404'), $overrides['config_test.system']['404']); } } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php index 879ca80..0e9327e 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -142,7 +142,6 @@ protected function tearDown() { * @see \DrupalUnitTestBase::disableModules() */ public function containerBuild(ContainerBuilder $container) { - global $conf; // Keep the container object around for tests. $this->container = $container; diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index 9e7b6b2..d1bb1e3 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -11,6 +11,7 @@ use Drupal\Core\Database\Database; use Drupal\Component\Utility\Settings; use Drupal\Core\Config\ConfigImporter; +use Drupal\Core\Config\GlobalConfig; use Drupal\Core\Config\StorageComparer; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Database\ConnectionNotDefinedException; @@ -99,6 +100,18 @@ protected $setupEnvironment = FALSE; /** + * Test-specific global configuration override values. + * + * @var array + */ + protected $configOverrides = array(); + + /** + * @var \Drupal\Core\Config\GlobalConfig + */ + protected $globalConfig; + + /** * TRUE if verbose debugging is enabled. * * @var boolean @@ -216,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 @@ -898,7 +906,7 @@ protected function changeDatabasePrefix() { * @see TestBase::tearDown() */ protected function prepareEnvironment() { - global $user, $conf; + global $user; $language_interface = language(Language::TYPE_INTERFACE); // When running the test runner within a test, back up the original database @@ -910,7 +918,7 @@ protected function prepareEnvironment() { // Backup current in-memory configuration. $this->originalSettings = settings()->getAll(); - $this->originalConf = $conf; + $this->originalConfig = $this->globalConfig->getAll(); // Backup statics and globals. $this->originalContainer = clone \Drupal::getContainer(); @@ -961,6 +969,8 @@ protected function prepareEnvironment() { // Create and set new configuration directories. $this->prepareConfigDirectories(); + $this->globalConfig = GlobalConfig::getInstance(); + // Reset statics before the old container is replaced so that objects with a // __destruct() method still have access to it. // @todo: Remove once they have been converted to services. @@ -1054,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. @@ -1065,7 +1114,7 @@ protected function rebuildContainer() { * @see TestBase::prepareEnvironment() */ protected function tearDown() { - global $user, $conf; + global $user; // Reset all static variables. // Unsetting static variables will potentially invoke destruct methods, @@ -1128,7 +1177,7 @@ protected function tearDown() { drupal_static_reset(); // Restore original in-memory configuration. - $conf = $this->originalConf; + $this->globalConfig->setConfig($this->originalConfig); new Settings($this->originalSettings); // Restore original statics and globals. diff --git a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php index 5510aa4..7f20fed 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php @@ -41,32 +41,8 @@ function __construct($test_id = NULL) { * setUp() method. */ protected function setUp() { - global $conf; - - // 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 and variables to perform tests in a clean environment. - $conf = array(); - 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 265012e..90bb51b 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -717,8 +717,6 @@ protected function drupalLogout() { * @see \Drupal\simpletest\WebTestBase::prepareEnvironment() */ protected function setUp() { - global $conf; - // When running tests through the Simpletest UI (vs. on the command line), // Simpletest's batch conflicts with the installer's batch. Batch API does // not support the concept of nested batches (in which the nested is not @@ -726,32 +724,11 @@ 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 and variables to perform tests in a clean environment. - $conf = array(); - drupal_static_reset(); + parent::setUp(); - // 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; - } - - // Set the 'simpletest_parent_profile' variable to add the parent profile's - // search path to the child site's search paths. + // Add the parent profile's search path to the child site's search paths. // @see drupal_system_listing() - $conf['simpletest_parent_profile'] = $this->originalProfile; + $this->globalConfig->set('simpletest.settings', 'parent_profile', $this->originalProfile); // Define information about the user 1 account. $this->root_user = new UserSession(array( @@ -764,21 +741,12 @@ protected function setUp() { // Reset the static batch to remove Simpletest's batch operations. $batch = &batch_get(); $batch = array(); - $variable_groups = array( - 'system.file' => array( - 'path.private' => $this->private_files_directory, - 'path.temporary' => $this->temp_files_directory, - ), - 'locale.settings' => array( - 'translation.path' => $this->translation_files_directory, - ), - ); - foreach ($variable_groups as $config_base => $variables) { - foreach ($variables as $name => $value) { - NestedArray::setValue($GLOBALS['conf'], array_merge(array($config_base), explode('.', $name)), $value); - } - } + $this->settingsSet('file_public_path', $this->public_files_directory); + $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); + // Execute the non-interactive installer. require_once DRUPAL_ROOT . '/core/includes/install.core.inc'; $this->settingsSet('cache', array('default' => 'cache.backend.memory')); @@ -787,13 +755,9 @@ protected function setUp() { // Set the install_profile so that web requests to the requests to the child // site have the correct profile. - $settings = array( - 'settings' => array( - 'install_profile' => (object) array( - 'value' => $this->profile, - 'required' => TRUE, - ), - ), + $settings['settings']['install_profile'] = (object) array( + 'value' => $this->profile, + 'required' => TRUE, ); $this->writeSettings($settings); // Override install profile in Settings to so the correct profile is used by @@ -835,13 +799,13 @@ protected function setUp() { // Now make sure that the file path configurations are saved. This is done // after we install the modules to override default values. - foreach ($variable_groups as $config_base => $variables) { - $config = \Drupal::config($config_base); - foreach ($variables as $name => $value) { - $config->set($name, $value); - } - $config->save(); - } + \Drupal::config('system.file') + ->set('path.private', $this->private_files_directory) + ->set('path.temporary', $this->temp_files_directory) + ->save(); + \Drupal::config('locale.settings') + ->set('translation.path', $this->translation_files_directory) + ->save(); // Use the test mail class instead of the default mail handler class. \Drupal::config('system.mail')->set('interface.default', 'Drupal\Core\Mail\TestMailCollector')->save(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Installer/InstallerLanguageTest.php b/core/modules/system/lib/Drupal/system/Tests/Installer/InstallerLanguageTest.php index c3308f7..f489ddb 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Installer/InstallerLanguageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Installer/InstallerLanguageTest.php @@ -24,11 +24,10 @@ public static function getInfo() { } function setUp() { + // Override the installation translations directory path. + $this->configOverrides['locale.settings']['translation.path'] = drupal_get_path('module', 'simpletest') . '/files/translations'; + parent::setUp(); - // The database is not available during this part of install. Use global - // $conf to override the installation translations directory path. - global $conf; - $conf['locale.settings']['translation.path'] = drupal_get_path('module', 'simpletest') . '/files/translations'; } /** @@ -44,7 +43,7 @@ function testInstallerTranslationFiles() { 'it' => array(), ); - $file_translation = new FileTranslation($GLOBALS['conf']['locale.settings']['translation.path']); + $file_translation = new FileTranslation($this->configOverrides['locale.settings']['translation.path']); foreach ($expected_translation_files as $langcode => $files_expected) { $files_found = $file_translation->findTranslationFiles($langcode); $this->assertTrue(count($files_found) == count($files_expected), format_string('@count installer languages found.', array('@count' => count($files_expected)))); diff --git a/core/modules/system/lib/Drupal/system/Tests/InstallerTest.php b/core/modules/system/lib/Drupal/system/Tests/InstallerTest.php index 5bbaab8..2ae1f78 100644 --- a/core/modules/system/lib/Drupal/system/Tests/InstallerTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/InstallerTest.php @@ -24,8 +24,6 @@ public static function getInfo() { } protected function setUp() { - global $conf; - // When running tests through the SimpleTest UI (vs. on the command line), // SimpleTest's batch conflicts with the installer's batch. Batch API does // not support the concept of nested batches (in which the nested is not @@ -39,35 +37,29 @@ 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 and variables to perform tests in a clean environment. - $conf = array(); - 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; - } - $variable_groups = array( - 'system.file' => array( - 'path.private' => $this->private_files_directory, - 'path.temporary' => $this->temp_files_directory, - ), - 'locale.settings' => array( - 'translation.path' => $this->translation_files_directory, - ), - ); - foreach ($variable_groups as $config_base => $variables) { - foreach ($variables as $name => $value) { - NestedArray::setValue($GLOBALS['conf'], array_merge(array($config_base), explode('.', $name)), $value); - } + 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); + $settings['conf_path'] = (object) array( 'value' => $this->public_files_directory, 'required' => TRUE, @@ -76,6 +68,23 @@ protected function setUp() { 'value' => array(), 'required' => TRUE, ); + $settings['config']['system.file'] = (object) array( + 'value' => array( + 'path' => array( + 'private' => $this->private_files_directory, + 'temporary' => $this->temp_files_directory, + ), + ), + 'required' => TRUE, + ); + $settings['config']['locale.settings'] = (object) array( + 'value' => array( + 'translation' => array( + 'path' => $this->translation_files_directory, + ), + ), + 'required' => TRUE, + ); $this->writeSettings($settings); $this->drupalGet($GLOBALS['base_url'] . '/core/install.php?langcode=en&profile=minimal'); @@ -87,13 +96,13 @@ protected function setUp() { } $this->rebuildContainer(); - foreach ($variable_groups as $config_base => $variables) { - $config = \Drupal::config($config_base); - foreach ($variables as $name => $value) { - $config->set($name, $value); - } - $config->save(); - } + \Drupal::config('system.file') + ->set('path.private', $this->private_files_directory) + ->set('path.temporary', $this->temp_files_directory) + ->save(); + \Drupal::config('locale.settings') + ->set('translation.path', $this->translation_files_directory) + ->save(); // Use the test mail class instead of the default mail handler class. \Drupal::config('system.mail')->set('interface.default', 'Drupal\Core\Mail\TestMailCollector')->save(); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 34d8dde..29b8f34 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -320,7 +320,6 @@ function system_requirements($phase) { // During an install we need to make assumptions about the file system // unless overrides are provided in settings.php. if ($phase == 'install') { - global $conf; $directories = array(); if ($file_public_path = settings()->get('file_public_path')) { $directories[] = $file_public_path; @@ -331,11 +330,12 @@ function system_requirements($phase) { // conf_path() cache must also be reset in this case. $directories[] = conf_path(FALSE, TRUE) . '/files'; } - if (!empty($conf['system.file']['path.private'])) { - $directories[] = $conf['system.file']['path.private']; + $config = \Drupal::config('system.file'); + if ($config->get('path.private')) { + $directories[] = $config->get('path.private'); } - if (!empty($conf['system.file']['path.temporary'])) { - $directories[] = $conf['system.file']['path.temporary']; + if ($config->get('path.temporary')) { + $directories[] = $config->get('path.temporary'); } else { // If the temporary directory is not overridden use an appropriate diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index e9f0ffe..9538c96 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -6,6 +6,7 @@ require_once __DIR__ . '/../vendor/autoload.php'; +use Drupal\Core\Config\GlobalConfig; use Drupal\Core\StreamWrapper\PublicStream; const SIMPLETEST_SCRIPT_COLOR_PASS = 32; // Green. @@ -484,7 +485,7 @@ function simpletest_script_run_phpunit($test_id, $class) { * Bootstrap Drupal and run a single test. */ function simpletest_script_run_one_test($test_id, $test_class) { - global $args, $conf; + global $args; try { // Bootstrap Drupal. @@ -496,8 +497,9 @@ function simpletest_script_run_one_test($test_id, $test_class) { $container->set('request', $request); // Override configuration according to command line parameters. - $conf['simpletest.settings']['verbose'] = $args['verbose']; - $conf['simpletest.settings']['clear_results'] = !$args['keep-results']; + $config = GlobalConfig::getInstance(); + $config->set('simpletest.settings', 'verbose', $args['verbose']); + $config->set('simpletest.settings', 'clear_results', !$args['keep-results']); $test = new $test_class($test_id); $test->dieOnFail = (bool) $args['die-on-fail']; diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php index 5a46b12..2160376 100644 --- a/sites/default/default.settings.php +++ b/sites/default/default.settings.php @@ -586,25 +586,19 @@ # $cookie_domain = '.example.com'; /** - * Variable overrides: + * Configuration overrides. * - * To override specific entries in the 'variable' table for this site, + * To globally override specific configuration values for this site, * set them here. You usually don't need to use this feature. This is * useful in a configuration file for a vhost or directory, rather than - * the default settings.php. Any configuration setting from the 'variable' - * table can be given a new value. Note that any values you provide in - * these variable overrides will not be modifiable from the Drupal - * administration interface. - * - * The following overrides are examples: - * - site_name: Defines the site's name. - * - $conf['system.theme']['default']: Defines the default theme for this site. - * - anonymous: Defines the human-readable name of anonymous users. - * Remove the leading hash signs to enable. + * the default settings.php. + * + * Note that any values you provide in these variable overrides will not be + * modifiable from the Drupal administration interface. */ -# $conf['system.site']['name'] = 'My Drupal site'; -# $conf['system.theme']['default'] = 'stark'; -# $conf['anonymous'] = 'Visitor'; +# $config['system.site']['name'] = 'My Drupal site'; +# $config['system.theme']['default'] = 'stark'; +# $config['user.settings']['anonymous'] = 'Visitor'; /** * CSS/JS aggregated file gzip compression: @@ -618,8 +612,8 @@ * configured to cache and compress these files itself you may want to uncomment * one or both of the below lines, which will prevent gzip files being stored. */ -# $conf['system.performance']['css']['gzip'] = FALSE; -# $conf['system.performance']['js']['gzip'] = FALSE; +# $config['system.performance']['css']['gzip'] = FALSE; +# $config['system.performance']['js']['gzip'] = FALSE; /** * Fast 404 pages: @@ -643,9 +637,9 @@ * * Remove the leading hash signs if you would like to alter this functionality. */ -#$conf['system.performance']['fast_404']['exclude_paths'] = '/\/(?:styles)\//'; -#$conf['system.performance']['fast_404']['paths'] = '/\.(?:txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i'; -#$conf['system.performance']['fast_404']['html'] = '404 Not Found

Not Found

The requested URL "@path" was not found on this server.

'; +# $config['system.performance']['fast_404']['exclude_paths'] = '/\/(?:styles)\//'; +# $config['system.performance']['fast_404']['paths'] = '/\.(?:txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i'; +# $config['system.performance']['fast_404']['html'] = '404 Not Found

Not Found

The requested URL "@path" was not found on this server.

'; /** * Load local development override configuration, if available.