InstallerExistingDatabaseSettingsTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 $defaultTheme = 'stark';
  15. /**
  16. * {@inheritdoc}
  17. */
  18. protected function prepareEnvironment() {
  19. parent::prepareEnvironment();
  20. // Pre-configure database credentials in settings.php.
  21. $connection_info = Database::getConnectionInfo();
  22. unset($connection_info['default']['pdo']);
  23. unset($connection_info['default']['init_commands']);
  24. $this->settings['databases']['default'] = (object) [
  25. 'value' => $connection_info,
  26. 'required' => TRUE,
  27. ];
  28. }
  29. /**
  30. * {@inheritdoc}
  31. *
  32. * @todo The database settings form is not supposed to appear if settings.php
  33. * contains a valid database connection already (but e.g. no config
  34. * directories yet).
  35. */
  36. protected function setUpSettings() {
  37. // All database settings should be pre-configured, except password.
  38. $values = $this->parameters['forms']['install_settings_form'];
  39. $driver = $values['driver'];
  40. $edit = [];
  41. if (isset($values[$driver]['password']) && $values[$driver]['password'] !== '') {
  42. $edit = $this->translatePostValues([
  43. $driver => [
  44. 'password' => $values[$driver]['password'],
  45. ],
  46. ]);
  47. }
  48. $this->drupalPostForm(NULL, $edit, $this->translations['Save and continue']);
  49. }
  50. /**
  51. * Verifies that installation succeeded.
  52. */
  53. public function testInstaller() {
  54. $this->assertUrl('user/1');
  55. $this->assertSession()->statusCodeEquals(200);
  56. }
  57. }