InstallerExistingSettingsMismatchProfileTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. protected $defaultTheme = 'stark';
  18. /**
  19. * {@inheritdoc}
  20. *
  21. * Configures a preexisting settings.php file without an install_profile
  22. * setting before invoking the interactive installer.
  23. */
  24. protected function prepareEnvironment() {
  25. parent::prepareEnvironment();
  26. // Pre-configure hash salt.
  27. // Any string is valid, so simply use the class name of this test.
  28. $this->settings['settings']['hash_salt'] = (object) [
  29. 'value' => __CLASS__,
  30. 'required' => TRUE,
  31. ];
  32. // Pre-configure database credentials.
  33. $connection_info = Database::getConnectionInfo();
  34. unset($connection_info['default']['pdo']);
  35. unset($connection_info['default']['init_commands']);
  36. $this->settings['databases']['default'] = (object) [
  37. 'value' => $connection_info,
  38. 'required' => TRUE,
  39. ];
  40. // During interactive install we'll change this to a different profile and
  41. // this test will ensure that the new value is written to settings.php.
  42. $this->settings['settings']['install_profile'] = (object) [
  43. 'value' => 'minimal',
  44. 'required' => TRUE,
  45. ];
  46. // Pre-configure config directories.
  47. $this->settings['settings']['config_sync_directory'] = (object) [
  48. 'value' => DrupalKernel::findSitePath(Request::createFromGlobals()) . '/files/config_sync',
  49. 'required' => TRUE,
  50. ];
  51. mkdir($this->settings['settings']['config_sync_directory']->value, 0777, TRUE);
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. protected function visitInstaller() {
  57. // Provide profile and language in query string to skip these pages.
  58. $this->drupalGet($GLOBALS['base_url'] . '/core/install.php?langcode=en&profile=testing');
  59. }
  60. /**
  61. * {@inheritdoc}
  62. */
  63. protected function setUpLanguage() {
  64. // This step is skipped, because there is a langcode as a query param.
  65. }
  66. /**
  67. * {@inheritdoc}
  68. */
  69. protected function setUpProfile() {
  70. // This step is skipped, because there is a profile as a query param.
  71. }
  72. /**
  73. * {@inheritdoc}
  74. */
  75. protected function setUpSettings() {
  76. // This step should not appear, since settings.php is fully configured
  77. // already.
  78. }
  79. /**
  80. * Verifies that installation succeeded.
  81. *
  82. * @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
  83. */
  84. public function testInstaller() {
  85. $this->assertUrl('user/1');
  86. $this->assertResponse(200);
  87. $this->assertEqual('testing', \Drupal::installProfile());
  88. $this->assertEqual('testing', Settings::get('install_profile'), 'Profile was correctly changed to testing in Settings.php');
  89. }
  90. }