InstallerExistingSettingsTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace Drupal\FunctionalTests\Installer;
  3. use Drupal\Core\Database\Database;
  4. use Drupal\Core\DrupalKernel;
  5. use Symfony\Component\HttpFoundation\Request;
  6. /**
  7. * Tests the installer with an existing settings file.
  8. *
  9. * @group Installer
  10. */
  11. class InstallerExistingSettingsTest extends InstallerTestBase {
  12. /**
  13. * {@inheritdoc}
  14. *
  15. * Fully configures a preexisting settings.php file before invoking the
  16. * interactive installer.
  17. */
  18. protected function prepareEnvironment() {
  19. parent::prepareEnvironment();
  20. // Pre-configure hash salt.
  21. // Any string is valid, so simply use the class name of this test.
  22. $this->settings['settings']['hash_salt'] = (object) [
  23. 'value' => __CLASS__,
  24. 'required' => TRUE,
  25. ];
  26. // Pre-configure database credentials.
  27. $connection_info = Database::getConnectionInfo();
  28. unset($connection_info['default']['pdo']);
  29. unset($connection_info['default']['init_commands']);
  30. $this->settings['databases']['default'] = (object) [
  31. 'value' => $connection_info,
  32. 'required' => TRUE,
  33. ];
  34. // Use the kernel to find the site path because the site.path service should
  35. // not be available at this point in the install process.
  36. $site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
  37. // Pre-configure config directories.
  38. $this->settings['config_directories'] = [
  39. CONFIG_SYNC_DIRECTORY => (object) [
  40. 'value' => $site_path . '/files/config_sync',
  41. 'required' => TRUE,
  42. ],
  43. ];
  44. mkdir($this->settings['config_directories'][CONFIG_SYNC_DIRECTORY]->value, 0777, TRUE);
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. protected function setUpSettings() {
  50. // This step should not appear, since settings.php is fully configured
  51. // already.
  52. }
  53. /**
  54. * Verifies that installation succeeded.
  55. */
  56. public function testInstaller() {
  57. $this->assertUrl('user/1');
  58. $this->assertResponse(200);
  59. $this->assertEqual('testing', \Drupal::installProfile());
  60. }
  61. }