diff --git a/core/includes/install.inc b/core/includes/install.inc index 2a0fd97ea963..6f61503eeea8 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -211,6 +211,10 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) { } $contents = file_get_contents(DRUPAL_ROOT . '/' . $settings_file); if ($contents !== FALSE) { + // Initialize the contents for the settings.php file if it is empty. + if (trim($contents) === '') { + $contents = " 'Installer Empty Settings Test', + 'description' => 'Tests the installer with empty settings file.', + 'group' => 'Installer', + ); + } + + /** + * {@inheritdoc} + */ + protected function setUp() { + // Create an empty settings.php file. + touch($this->siteDirectory . '/settings.php'); + parent::setUp(); + } + + /** + * Verifies that installation succeeded. + */ + public function testInstaller() { + $this->assertUrl('user/1'); + $this->assertResponse(200); + } + +} diff --git a/core/modules/system/lib/Drupal/system/Tests/System/SettingsRewriteTest.php b/core/modules/system/lib/Drupal/system/Tests/System/SettingsRewriteTest.php index dcbed32db041..6b9ee6889fb6 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/SettingsRewriteTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/SettingsRewriteTest.php @@ -110,5 +110,26 @@ EXPECTED drupal_rewrite_settings($test['settings'], $filename); $this->assertEqual(file_get_contents(DRUPAL_ROOT . '/' . $filename), " array( + 'no_index' => (object) array( + 'value' => TRUE, + 'required' => TRUE, + ), + ), + 'expected' => '$no_index = true;' + ); + // Make an empty file. + $filename = settings()->get('file_public_path', conf_path() . '/files') . '/mock_settings.php'; + file_put_contents(DRUPAL_ROOT . '/' . $filename, ""); + + // Write the setting to the file. + drupal_rewrite_settings($test['settings'], $filename); + + // Check that the result is just the php opening tag and the settings. + $this->assertEqual(file_get_contents(DRUPAL_ROOT . '/' . $filename), "