InstallerExistingDatabaseSettingsTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Drupal\FunctionalTests\Installer;
  3. use Drupal\Core\Database\Database;
  4. /**
  5. * Tests the installer with an existing settings file with database connection
  6. * info.
  7. *
  8. * @group Installer
  9. */
  10. class InstallerExistingDatabaseSettingsTest extends InstallerTestBase {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. protected function prepareEnvironment() {
  15. parent::prepareEnvironment();
  16. // Pre-configure database credentials in settings.php.
  17. $connection_info = Database::getConnectionInfo();
  18. unset($connection_info['default']['pdo']);
  19. unset($connection_info['default']['init_commands']);
  20. $this->settings['databases']['default'] = (object) [
  21. 'value' => $connection_info,
  22. 'required' => TRUE,
  23. ];
  24. }
  25. /**
  26. * {@inheritdoc}
  27. *
  28. * @todo The database settings form is not supposed to appear if settings.php
  29. * contains a valid database connection already (but e.g. no config
  30. * directories yet).
  31. */
  32. protected function setUpSettings() {
  33. // All database settings should be pre-configured, except password.
  34. $values = $this->parameters['forms']['install_settings_form'];
  35. $driver = $values['driver'];
  36. $edit = [];
  37. if (isset($values[$driver]['password']) && $values[$driver]['password'] !== '') {
  38. $edit = $this->translatePostValues([
  39. $driver => [
  40. 'password' => $values[$driver]['password'],
  41. ],
  42. ]);
  43. }
  44. $this->drupalPostForm(NULL, $edit, $this->translations['Save and continue']);
  45. }
  46. /**
  47. * Verifies that installation succeeded.
  48. */
  49. public function testInstaller() {
  50. $this->assertUrl('user/1');
  51. $this->assertResponse(200);
  52. }
  53. }