Commit bcc57baf authored by catch's avatar catch

Issue #1881582 by sun: Change configuration overrides to use $config instead of $conf.

parent 4b1d3103
......@@ -537,16 +537,18 @@ function drupal_settings_initialize() {
global $base_url, $base_path, $base_root, $script_path;
// 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();
global $databases, $cookie_domain, $db_prefix, $drupal_hash_salt, $base_secure_url, $base_insecure_url, $config_directories, $config;
$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';
}
// Initialize Settings.
new Settings($settings);
new Settings(isset($settings) ? $settings : array());
$is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on';
if (isset($base_url)) {
......@@ -2078,14 +2080,14 @@ 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.
*/
function _drupal_load_test_overrides($test_prefix) {
global $conf, $config_directories;
global $config_directories, $config;
// Do not use the parent site's config directories. Use only the child site's.
// @see \Drupal\simpletest\TestBase::prepareConfigDirectories()
......@@ -2100,7 +2102,7 @@ function _drupal_load_test_overrides($test_prefix) {
if (file_exists($filename)) {
$settings = settings()->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()
......
......@@ -105,8 +105,6 @@ public function getOverrideState() {
* {@inheritdoc}
*/
public function get($name) {
global $conf;
if ($config = $this->loadMultiple(array($name))) {
return $config[$name];
}
......@@ -139,8 +137,8 @@ public function get($name) {
$this->cache[$cache_key]->setModuleOverride($module_overrides[$name]);
}
// Apply any settings.php overrides.
if (isset($conf[$name])) {
$this->cache[$cache_key]->setSettingsOverride($conf[$name]);
if (isset($GLOBALS['config'][$name])) {
$this->cache[$cache_key]->setSettingsOverride($GLOBALS['config'][$name]);
}
}
}
......@@ -152,8 +150,6 @@ public function get($name) {
* {@inheritdoc}
*/
public function loadMultiple(array $names) {
global $conf;
$list = array();
foreach ($names as $key => $name) {
......@@ -205,8 +201,8 @@ public function loadMultiple(array $names) {
if (isset($module_overrides[$name])) {
$this->cache[$cache_key]->setModuleOverride($module_overrides[$name]);
}
if (isset($conf[$name])) {
$this->cache[$cache_key]->setSettingsOverride($conf[$name]);
if (isset($GLOBALS['config'][$name])) {
$this->cache[$cache_key]->setSettingsOverride($GLOBALS['config'][$name]);
}
}
$list[$name] = $this->cache[$cache_key];
......
......@@ -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';
$GLOBALS['config'] = $overrides;
$this->installConfig(array('config_test'));
......@@ -64,10 +64,10 @@ function testConfOverride() {
// Get the configuration object in with overrides.
$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';
......@@ -77,19 +77,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']);
// Write file to staging.
$staging = $this->container->get('config.storage.staging');
......@@ -111,14 +111,14 @@ 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']);
// Test overrides of completely new configuration objects. In normal runtime
// this should only happen for configuration entities as we should not be
// creating simple configuration objects on the fly.
$conf['config_test.new']['key'] = 'override';
$GLOBALS['config']['config_test.new']['key'] = 'override';
$config = \Drupal::config('config_test.new');
$this->assertTrue($config->isNew(), 'The configuration object config_test.new is new');
$this->assertIdentical($config->get('key'), 'override');
......
......@@ -26,7 +26,6 @@ public static function getInfo() {
}
public function testOverridePriorities() {
global $conf;
$GLOBALS['config_test_run_module_overrides'] = FALSE;
$non_overridden_mail = 'site@example.com';
......@@ -85,7 +84,7 @@ public function testOverridePriorities() {
// Configure a global override to simulate overriding using settings.php. Do
// not override system.site:mail or system.site:slogan to prove that the
// language and module overrides still apply.
$conf['system.site']['name'] = 'Site name global conf override';
$GLOBALS['config']['system.site']['name'] = 'Site name global conf override';
$config_factory->reset('system.site');
$this->assertEqual('Site name global conf override', $config_factory->get('system.site')->get('name'));
$this->assertEqual($module_overridden_slogan, $config_factory->get('system.site')->get('slogan'));
......
......@@ -89,7 +89,7 @@ abstract class TestBase {
*
* @var boolean
*/
protected $verbose = FALSE;
public $verbose = FALSE;
/**
* Incrementing identifier for verbose output filenames.
......@@ -724,7 +724,7 @@ public function run(array $methods = array()) {
$simpletest_config = \Drupal::config('simpletest.settings');
$class = get_class($this);
if ($simpletest_config->get('verbose')) {
if ($this->verbose || $simpletest_config->get('verbose')) {
// Initialize verbose debugging.
$this->verbose = TRUE;
$this->verboseDirectory = PublicStream::basePath() . '/simpletest/verbose';
......@@ -923,7 +923,7 @@ protected function beforePrepareEnvironment() {
* @see TestBase::beforePrepareEnvironment()
*/
private function prepareEnvironment() {
global $user, $conf;
global $user;
// Allow (base) test classes to backup global state information.
$this->beforePrepareEnvironment();
......@@ -942,7 +942,7 @@ private function prepareEnvironment() {
// Backup current in-memory configuration.
$this->originalSettings = settings()->getAll();
$this->originalConf = $conf;
$this->originalConfig = $GLOBALS['config'];
// Backup statics and globals.
$this->originalContainer = clone \Drupal::getContainer();
......@@ -1051,8 +1051,8 @@ private function prepareEnvironment() {
// Change the database prefix.
$this->changeDatabasePrefix();
// Reset all variables to perform tests in a clean environment.
$conf = array();
// Remove all configuration overrides.
$GLOBALS['config'] = array();
drupal_set_time_limit($this->timeLimit);
}
......@@ -1131,7 +1131,7 @@ protected function tearDown() {
* @see TestBase::prepareEnvironment()
*/
private function restoreEnvironment() {
global $user, $conf;
global $user;
// Reset all static variables.
// Unsetting static variables will potentially invoke destruct methods,
......@@ -1188,7 +1188,7 @@ private function restoreEnvironment() {
drupal_static_reset();
// Restore original in-memory configuration.
$conf = $this->originalConf;
$GLOBALS['config'] = $this->originalConfig;
new Settings($this->originalSettings);
// Restore original statics and globals.
......
......@@ -766,21 +766,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);
$GLOBALS['config']['system.file']['path']['private'] = $this->private_files_directory;
$GLOBALS['config']['system.file']['path']['temporary'] = $this->temp_files_directory;
$GLOBALS['config']['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'));
......@@ -837,13 +828,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();
......
......@@ -23,14 +23,6 @@ public static function getInfo() {
);
}
function setUp() {
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';
}
/**
* Tests that the installer can find translation files.
*/
......@@ -44,7 +36,7 @@ function testInstallerTranslationFiles() {
'it' => array(),
);
$file_translation = new FileTranslation($GLOBALS['conf']['locale.settings']['translation.path']);
$file_translation = new FileTranslation(drupal_get_path('module', 'simpletest') . '/files/translations');
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))));
......
......@@ -33,20 +33,7 @@ public static function getInfo() {
protected function setUp() {
$this->isInstalled = 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);
}
}
$settings['conf_path'] = (object) array(
'value' => $this->public_files_directory,
'required' => TRUE,
......@@ -55,10 +42,31 @@ 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,
);
// Add the translations directory so we can retrieve German translations.
$settings['config']['locale.settings'] = (object) array(
'value' => array(
'translation' => array(
'path' => drupal_get_path('module', 'simpletest') . '/files/translations',
),
),
'required' => TRUE,
);
$this->writeSettings($settings);
// Submit the installer with German language.
$this->drupalPostForm($GLOBALS['base_url'] . '/core/install.php', array('langcode' => 'de'), 'Save and continue');
$edit = array(
'langcode' => 'de',
);
$this->drupalPostForm($GLOBALS['base_url'] . '/core/install.php', $edit, 'Save and continue');
// On the following page where installation profile is being selected the
// interface should be already translated, so there is no "Set up database"
......@@ -73,9 +81,13 @@ protected function setUp() {
// Get the "Save and continue" submit button translated value from the
// translated interface.
$submit_value = (string) current($this->xpath('//input[@type="submit"]/@value'));
$this->assertNotEqual($submit_value, 'Save and continue');
// Submit the standard profile installation.
$this->drupalPostForm(NULL, array('profile' => 'standard'), $submit_value);
// Submit the Standard profile installation.
$edit = array(
'profile' => 'standard',
);
$this->drupalPostForm(NULL, $edit, $submit_value);
// Submit the next step.
$this->drupalPostForm(NULL, array(), $submit_value);
......@@ -87,13 +99,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();
// Submit site configuration form.
$this->drupalPostForm(NULL, array(
......
......@@ -33,20 +33,8 @@ public static function getInfo() {
protected function setUp() {
$this->isInstalled = 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);
}
}
$settings['conf_path'] = (object) array(
'value' => $this->public_files_directory,
'required' => TRUE,
......@@ -55,6 +43,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');
......@@ -66,13 +71,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();
......
......@@ -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,11 @@ 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'];
if (!empty($GLOBALS['config']['system.file']['path']['private'])) {
$directories[] = $GLOBALS['config']['system.file']['path']['private'];
}
if (!empty($conf['system.file']['path.temporary'])) {
$directories[] = $conf['system.file']['path.temporary'];
if (!empty($GLOBALS['config']['system.file']['path']['temporary'])) {
$directories[] = $GLOBALS['config']['system.file']['path']['temporary'];
}
else {
// If the temporary directory is not overridden use an appropriate
......
......@@ -496,12 +496,9 @@ function simpletest_script_run_one_test($test_id, $test_class) {
$container = \Drupal::getContainer();
$container->set('request', $request);
// Override configuration according to command line parameters.
$GLOBALS['conf']['simpletest.settings']['verbose'] = $args['verbose'];
$GLOBALS['conf']['simpletest.settings']['clear_results'] = !$args['keep-results'];
$test = new $test_class($test_id);
$test->dieOnFail = (bool) $args['die-on-fail'];
$test->verbose = (bool) $args['verbose'];
$test->run();
$info = $test->getInfo();
......
......@@ -592,25 +592,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:
......@@ -624,8 +618,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:
......@@ -649,9 +643,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'] = '<!DOCTYPE html><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "@path" was not found on this server.</p></body></html>';
# $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'] = '<!DOCTYPE html><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "@path" was not found on this server.</p></body></html>';
/**
* Load local development override configuration, if available.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment