From b431efaf369b32297d45e8771176ec78c9c3678d Mon Sep 17 00:00:00 2001 From: webchick <webchick@24967.no-reply.drupal.org> Date: Fri, 11 Apr 2014 13:45:19 -0400 Subject: [PATCH] Issue #2212947 by sun, pwolanin, dmitry_bezer | ianthomas_uk: Installer doesn't pick up database port or table prefix from settings.php. --- .../Database/Driver/mysql/Install/Tasks.php | 4 +- .../Database/Driver/pgsql/Install/Tasks.php | 5 +- .../Drupal/Core/Database/Install/Tasks.php | 2 +- .../Drupal/simpletest/InstallerTestBase.php | 2 +- .../lib/Drupal/simpletest/WebTestBase.php | 5 ++ .../InstallerExistingSettingsTest.php | 75 +++++++++++++++++++ 6 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 core/modules/system/lib/Drupal/system/Tests/Installer/InstallerExistingSettingsTest.php 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 714dd2c89f0e..32c217b9853d 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 3f9c9a5530b5..641dd7d664a5 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 35de9435e6f9..c4d88d28d2cb 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 ffcef7a2bdae..899c7d8c09a2 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 d934cd9d86e4..5c57230a7944 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 000000000000..9b341bf647e3 --- /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); + } + +} -- GitLab