InstallerExistingSettingsTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. protected $defaultTheme = 'stark';
  16. /**
  17. * {@inheritdoc}
  18. *
  19. * Fully configures a preexisting settings.php file before invoking the
  20. * interactive installer.
  21. */
  22. protected function prepareEnvironment() {
  23. parent::prepareEnvironment();
  24. // Pre-configure hash salt.
  25. // Any string is valid, so simply use the class name of this test.
  26. $this->settings['settings']['hash_salt'] = (object) [
  27. 'value' => __CLASS__,
  28. 'required' => TRUE,
  29. ];
  30. // Pre-configure database credentials.
  31. $connection_info = Database::getConnectionInfo();
  32. unset($connection_info['default']['pdo']);
  33. unset($connection_info['default']['init_commands']);
  34. $this->settings['databases']['default'] = (object) [
  35. 'value' => $connection_info,
  36. 'required' => TRUE,
  37. ];
  38. // Use the kernel to find the site path because the site.path service should
  39. // not be available at this point in the install process.
  40. $site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
  41. // Pre-configure config directories.
  42. $this->settings['settings']['config_sync_directory'] = (object) [
  43. 'value' => $site_path . '/files/config_sync',
  44. 'required' => TRUE,
  45. ];
  46. mkdir($this->settings['settings']['config_sync_directory']->value, 0777, TRUE);
  47. }
  48. /**
  49. * Visits the interactive installer.
  50. */
  51. protected function visitInstaller() {
  52. // Should redirect to the installer.
  53. $this->drupalGet($GLOBALS['base_url']);
  54. // Ensure no database tables have been created yet.
  55. $this->assertSame([], Database::getConnection()->schema()->findTables('%'));
  56. $this->assertSession()->addressEquals($GLOBALS['base_url'] . '/core/install.php');
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. protected function setUpSettings() {
  62. // This step should not appear, since settings.php is fully configured
  63. // already.
  64. }
  65. /**
  66. * Verifies that installation succeeded.
  67. */
  68. public function testInstaller() {
  69. $this->assertUrl('user/1');
  70. $this->assertSession()->statusCodeEquals(200);
  71. $this->assertEqual('testing', \Drupal::installProfile());
  72. }
  73. }