InstallerExistingSettingsReadOnlyMismatchProfileTest.php 3.4 KB

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