InstallerExistingSettingsMismatchProfileTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace Drupal\FunctionalTests\Installer;
  3. use Drupal\Core\DrupalKernel;
  4. use Drupal\Core\Site\Settings;
  5. use Drupal\Core\Database\Database;
  6. use Symfony\Component\HttpFoundation\Request;
  7. /**
  8. * Tests install with existing settings.php and a mismatching install profile.
  9. *
  10. * @group Installer
  11. * @group legacy
  12. */
  13. class InstallerExistingSettingsMismatchProfileTest extends InstallerTestBase {
  14. /**
  15. * {@inheritdoc}
  16. *
  17. * Configures a preexisting settings.php file without an install_profile
  18. * setting before invoking the interactive installer.
  19. */
  20. protected function prepareEnvironment() {
  21. parent::prepareEnvironment();
  22. // Pre-configure hash salt.
  23. // Any string is valid, so simply use the class name of this test.
  24. $this->settings['settings']['hash_salt'] = (object) [
  25. 'value' => __CLASS__,
  26. 'required' => TRUE,
  27. ];
  28. // Pre-configure database credentials.
  29. $connection_info = Database::getConnectionInfo();
  30. unset($connection_info['default']['pdo']);
  31. unset($connection_info['default']['init_commands']);
  32. $this->settings['databases']['default'] = (object) [
  33. 'value' => $connection_info,
  34. 'required' => TRUE,
  35. ];
  36. // During interactive install we'll change this to a different profile and
  37. // this test will ensure that the new value is written to settings.php.
  38. $this->settings['settings']['install_profile'] = (object) [
  39. 'value' => 'minimal',
  40. 'required' => TRUE,
  41. ];
  42. // Pre-configure config directories.
  43. $this->settings['config_directories'] = [
  44. CONFIG_SYNC_DIRECTORY => (object) [
  45. 'value' => DrupalKernel::findSitePath(Request::createFromGlobals()) . '/files/config_sync',
  46. 'required' => TRUE,
  47. ],
  48. ];
  49. mkdir($this->settings['config_directories'][CONFIG_SYNC_DIRECTORY]->value, 0777, TRUE);
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. protected function visitInstaller() {
  55. // Provide profile and language in query string to skip these pages.
  56. $this->drupalGet($GLOBALS['base_url'] . '/core/install.php?langcode=en&profile=testing');
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. protected function setUpLanguage() {
  62. // This step is skipped, because there is a langcode as a query param.
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. protected function setUpProfile() {
  68. // This step is skipped, because there is a profile as a query param.
  69. }
  70. /**
  71. * {@inheritdoc}
  72. */
  73. protected function setUpSettings() {
  74. // This step should not appear, since settings.php is fully configured
  75. // already.
  76. }
  77. /**
  78. * Verifies that installation succeeded.
  79. *
  80. * @expectedDeprecation To access the install profile in Drupal 8 use \Drupal::installProfile() or inject the install_profile container parameter into your service. See https://www.drupal.org/node/2538996
  81. */
  82. public function testInstaller() {
  83. $this->assertUrl('user/1');
  84. $this->assertResponse(200);
  85. $this->assertEqual('testing', \Drupal::installProfile());
  86. $this->assertEqual('testing', Settings::get('install_profile'), 'Profile was correctly changed to testing in Settings.php');
  87. }
  88. }