InstallerExistingSettingsReadOnlyMismatchProfileTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace Drupal\FunctionalTests\Installer;
  3. use Drupal\Core\DrupalKernel;
  4. use Drupal\Core\Database\Database;
  5. use Drupal\Core\Site\Settings;
  6. use Symfony\Component\HttpFoundation\Request;
  7. /**
  8. * Tests installer breaks with a profile mismatch and a read-only settings.php.
  9. *
  10. * @group Installer
  11. * @group legacy
  12. */
  13. class InstallerExistingSettingsReadOnlyMismatchProfileTest 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. $site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
  48. $this->settings['settings']['config_sync_directory'] = (object) [
  49. 'value' => $site_path . '/files/config_staging',
  50. 'required' => TRUE,
  51. ];
  52. mkdir($this->settings['settings']['config_sync_directory']->value, 0777, TRUE);
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. protected function visitInstaller() {
  58. // Make settings file not writable. This will break the installer.
  59. $filename = $this->siteDirectory . '/settings.php';
  60. // Make the settings file read-only.
  61. // Not using File API; a potential error must trigger a PHP warning.
  62. chmod($filename, 0444);
  63. $this->drupalGet($GLOBALS['base_url'] . '/core/install.php?langcode=en&profile=testing');
  64. }
  65. /**
  66. * {@inheritdoc}
  67. */
  68. protected function setUpLanguage() {
  69. // This step is skipped, because there is a lagcode as a query param.
  70. }
  71. /**
  72. * {@inheritdoc}
  73. */
  74. protected function setUpProfile() {
  75. // This step is skipped, because there is a profile as a query param.
  76. }
  77. /**
  78. * {@inheritdoc}
  79. */
  80. protected function setUpSettings() {
  81. // This step should not appear, since settings.php is fully configured
  82. // already.
  83. }
  84. /**
  85. * Verifies that installation succeeded.
  86. *
  87. * @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
  88. */
  89. public function testInstalled() {
  90. $this->initBrowserOutputFile();
  91. $this->htmlOutput(NULL);
  92. $this->assertEquals('testing', \Drupal::installProfile());
  93. $this->assertEquals('minimal', Settings::get('install_profile'));
  94. $this->drupalGet('admin/reports/status');
  95. $this->assertSession()->pageTextContains("Drupal 8 no longer uses the \$settings['install_profile'] value in settings.php and it can be removed.");
  96. }
  97. }