Commit 13928d36 authored by webchick's avatar webchick

Issue #1921818 by chx: Modify drupal_rewrite_settings() to allow writing $settings values.

parent 279962e3
......@@ -1102,11 +1102,11 @@ function install_settings_form_submit($form, &$form_state) {
global $install_state;
// Update global settings array and save.
$settings['databases'] = array(
$settings['databases'] = (object) array(
'value' => array('default' => array('default' => $form_state['storage']['database'])),
'required' => TRUE,
);
$settings['drupal_hash_salt'] = array(
$settings['drupal_hash_salt'] = (object) array(
'value' => drupal_hash_base64(drupal_random_bytes(55)),
'required' => TRUE,
);
......
This diff is collapsed.
<?php
/**
* @file
* Contains Drupal\system\Tests\System\SettingsRewriteTest.
*/
namespace Drupal\system\Tests\System;
use Drupal\simpletest\UnitTestBase;
/**
* Tests the drupal_rewrite_settings() function.
*/
class SettingsRewriteTest extends UnitTestBase {
public static function getInfo() {
return array(
'name' => 'drupal_rewrite_settings()',
'description' => 'Tests the drupal_rewrite_settings() function.',
'group' => 'System',
);
}
/**
* Tests the drupal_rewrite_settings() function.
*/
function testDrupalRewriteSettings() {
include_once DRUPAL_ROOT . '/core/includes/install.inc';
$tests = array(
array(
'original' => '$no_index_value_scalar = TRUE;',
'settings' => array(
'no_index_value_scalar' => (object) array(
'value' => FALSE,
'comment' => 'comment',
),
),
'expected' => '$no_index_value_scalar = false; // comment',
),
array(
'original' => '$no_index_value_scalar = TRUE;',
'settings' => array(
'no_index_value_foo' => array(
'foo' => array(
'value' => (object) array(
'value' => NULL,
'required' => TRUE,
'comment' => 'comment',
),
),
),
),
'expected' => <<<'EXPECTED'
$no_index_value_scalar = TRUE;
$no_index_value_foo['foo']['value'] = NULL; // comment
EXPECTED
),
array(
'original' => '$no_index_value_array = array("old" => "value");',
'settings' => array(
'no_index_value_array' => (object) array(
'value' => FALSE,
'required' => TRUE,
'comment' => 'comment',
),
),
'expected' => '$no_index_value_array = array("old" => "value");
$no_index_value_array = false; // comment',
),
array(
'original' => '$has_index_value_scalar["foo"]["bar"] = NULL;',
'settings' => array(
'has_index_value_scalar' => array(
'foo' => array(
'bar' => (object) array(
'value' => FALSE,
'required' => TRUE,
'comment' => 'comment',
),
),
),
),
'expected' => '$has_index_value_scalar["foo"]["bar"] = false; // comment',
),
array(
'original' => '$has_index_value_scalar["foo"]["bar"] = "foo";',
'settings' => array(
'has_index_value_scalar' => array(
'foo' => array(
'value' => (object) array(
'value' => array('value' => 2),
'required' => TRUE,
'comment' => 'comment',
),
),
),
),
'expected' => <<<'EXPECTED'
$has_index_value_scalar["foo"]["bar"] = "foo";
$has_index_value_scalar['foo']['value'] = array (
'value' => 2,
); // comment
EXPECTED
),
);
foreach ($tests as $test) {
$filename = variable_get('file_public_path', conf_path() . '/files') . '/mock_settings.php';
file_put_contents(DRUPAL_ROOT . '/' . $filename, "<?php\n" . $test['original'] . "\n");
drupal_rewrite_settings($test['settings'], $filename);
$this->assertEqual(file_get_contents(DRUPAL_ROOT . '/' . $filename), "<?php\n" . $test['expected'] . "\n");
}
}
}
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