diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php b/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php index 714dd2c89f0eef8b8d2cf22ac60e120ca46543dd..32c217b9853d94f6e3f649a3ba68c171997a88db 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php @@ -87,7 +87,9 @@ protected function connect() { */ public function getFormOptions(array $database) { $form = parent::getFormOptions($database); - $form['advanced_options']['port']['#default_value'] = '3306'; + if (empty($form['advanced_options']['port']['#default_value'])) { + $form['advanced_options']['port']['#default_value'] = '3306'; + } return $form; } diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php index 3f9c9a5530b546fe340c77a8a062a3c8149e1b92..641dd7d664a502ab23a1ca2b4db180eec5283023 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php @@ -253,8 +253,9 @@ function initializeDatabase() { */ public function getFormOptions(array $database) { $form = parent::getFormOptions($database); - $form['advanced_options']['port']['#default_value'] = '5432'; - + if (empty($form['advanced_options']['port']['#default_value'])) { + $form['advanced_options']['port']['#default_value'] = '5432'; + } return $form; } } diff --git a/core/lib/Drupal/Core/Database/Install/Tasks.php b/core/lib/Drupal/Core/Database/Install/Tasks.php index 35de9435e6f918421ae5305e109930f1b4acb1c8..c4d88d28d2cb833d942c182b2c0daa4df0cfbbf5 100644 --- a/core/lib/Drupal/Core/Database/Install/Tasks.php +++ b/core/lib/Drupal/Core/Database/Install/Tasks.php @@ -255,7 +255,7 @@ public function getFormOptions(array $database) { $form['advanced_options']['prefix'] = array( '#type' => 'textfield', '#title' => t('Table name prefix'), - '#default_value' => '', + '#default_value' => empty($database['prefix']) ? '' : $database['prefix'], '#size' => 45, '#description' => t('If more than one application will be sharing this database, a unique table name prefix–such as %prefix–will prevent collisions.', array('%prefix' => $db_prefix)), '#weight' => 10, diff --git a/core/modules/simpletest/lib/Drupal/simpletest/InstallerTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/InstallerTestBase.php index ffcef7a2bdaedc8e361dfd9621d0ff6b00a2f63f..899c7d8c09a2e27683c4af8a83d83e7345058b89 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/InstallerTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/InstallerTestBase.php @@ -83,7 +83,7 @@ protected function setUp() { if (!empty($this->settings)) { // Not using File API; a potential error must trigger a PHP warning. copy(DRUPAL_ROOT . '/sites/default/default.settings.php', DRUPAL_ROOT . '/' . $this->siteDirectory . '/settings.php'); - $this->writeSettings($settings); + $this->writeSettings($this->settings); } // Note that WebTestBase::installParameters() returns form input values diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index d934cd9d86e44fd2bf175abe743276965672c19d..5c57230a794483eab12d0e70363203c0e5b8da7c 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -174,6 +174,11 @@ abstract class WebTestBase extends TestBase { */ protected $kernel; + /** + * The config directories used in this test. + */ + protected $configDirectories = array(); + /** * Cookies to set on curl requests. * diff --git a/core/modules/system/lib/Drupal/system/Tests/Installer/InstallerExistingSettingsTest.php b/core/modules/system/lib/Drupal/system/Tests/Installer/InstallerExistingSettingsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..9b341bf647e308382bb760ced562846d7838efbf --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Installer/InstallerExistingSettingsTest.php @@ -0,0 +1,75 @@ +<?php + +/** + * @file + * Contains \Drupal\system\Tests\Installer\InstallerEmptySettingsTest. + */ + +namespace Drupal\system\Tests\Installer; + +use Drupal\simpletest\InstallerTestBase; +use Drupal\Core\Database\Database; + +/** + * Tests the installer to make sure existing values in settings.php appear. + */ +class InstallerExistingSettingsTest extends InstallerTestBase { + + /** + * {@inheritdoc} + */ + public static function getInfo() { + return array( + 'name' => 'Installer Existing Settings Test', + 'description' => 'Tests the installer with an existing settings file with database connection info.', + 'group' => 'Installer', + ); + } + + /** + * {@inheritdoc} + */ + protected function setUp() { + // Pre-configure database credentials in settings.php. + $connection_info = Database::getConnectionInfo(); + unset($connection_info['default']['pdo']); + unset($connection_info['default']['init_commands']); + + $this->settings['databases']['default'] = (object) array( + 'value' => $connection_info, + 'required' => TRUE, + ); + parent::setUp(); + } + + /** + * {@inheritdoc} + * + * @todo The database settings form is not supposed to appear if settings.php + * contains a valid database connection already (but e.g. no config + * directories yet). + */ + protected function setUpSettings() { + // All database settings should be pre-configured, except password. + $values = $this->parameters['forms']['install_settings_form']; + $driver = $values['driver']; + $edit = array(); + if (isset($values[$driver]['password']) && $values[$driver]['password'] !== '') { + $edit = $this->translatePostValues(array( + $driver => array( + 'password' => $values[$driver]['password'], + ), + )); + } + $this->drupalPostForm(NULL, $edit, $this->translations['Save and continue']); + } + + /** + * Verifies that installation succeeded. + */ + public function testInstaller() { + $this->assertUrl('user/1'); + $this->assertResponse(200); + } + +}