Issue #2122693 by jayeshanandani, YesCT, sun, alexpott, BMDan: Installer does not work on a completely empty settings.php.
parent
7d7b24fedd
commit
cd7841b96e
|
@ -211,6 +211,10 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) {
|
||||||
}
|
}
|
||||||
$contents = file_get_contents(DRUPAL_ROOT . '/' . $settings_file);
|
$contents = file_get_contents(DRUPAL_ROOT . '/' . $settings_file);
|
||||||
if ($contents !== FALSE) {
|
if ($contents !== FALSE) {
|
||||||
|
// Initialize the contents for the settings.php file if it is empty.
|
||||||
|
if (trim($contents) === '') {
|
||||||
|
$contents = "<?php\n";
|
||||||
|
}
|
||||||
// Step through each token in settings.php and replace any variables that
|
// Step through each token in settings.php and replace any variables that
|
||||||
// are in the passed-in array.
|
// are in the passed-in array.
|
||||||
$buffer = '';
|
$buffer = '';
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Contains \Drupal\system\Tests\Installer\InstallerEmptySettingsTest.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Drupal\system\Tests\Installer;
|
||||||
|
|
||||||
|
use Drupal\simpletest\InstallerTestBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the installer with empty settings file.
|
||||||
|
*/
|
||||||
|
class InstallerEmptySettingsTest extends InstallerTestBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function getInfo() {
|
||||||
|
return array(
|
||||||
|
'name' => '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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -110,5 +110,26 @@ EXPECTED
|
||||||
drupal_rewrite_settings($test['settings'], $filename);
|
drupal_rewrite_settings($test['settings'], $filename);
|
||||||
$this->assertEqual(file_get_contents(DRUPAL_ROOT . '/' . $filename), "<?php\n" . $test['expected'] . "\n");
|
$this->assertEqual(file_get_contents(DRUPAL_ROOT . '/' . $filename), "<?php\n" . $test['expected'] . "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test that <?php gets added to the start of an empty settings file.
|
||||||
|
// Set the array of settings that will be written to the file.
|
||||||
|
$test = array(
|
||||||
|
'settings' => 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), "<?php\n" . $test['expected'] . "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue