DistributionProfileExistingSettingsTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace Drupal\FunctionalTests\Installer;
  3. use Drupal\Component\Serialization\Yaml;
  4. use Drupal\Core\Database\Database;
  5. use Drupal\Core\DrupalKernel;
  6. use Drupal\Core\Site\Settings;
  7. use Symfony\Component\HttpFoundation\Request;
  8. /**
  9. * Tests distribution profile support with existing settings.
  10. *
  11. * @group Installer
  12. */
  13. class DistributionProfileExistingSettingsTest extends InstallerTestBase {
  14. /**
  15. * The distribution profile info.
  16. *
  17. * @var array
  18. */
  19. protected $info;
  20. /**
  21. * {@inheritdoc}
  22. */
  23. protected function prepareEnvironment() {
  24. parent::prepareEnvironment();
  25. $this->info = [
  26. 'type' => 'profile',
  27. 'core' => \Drupal::CORE_COMPATIBILITY,
  28. 'name' => 'Distribution profile',
  29. 'distribution' => [
  30. 'name' => 'My Distribution',
  31. 'install' => [
  32. 'theme' => 'bartik',
  33. ],
  34. ],
  35. ];
  36. // File API functions are not available yet.
  37. $path = $this->siteDirectory . '/profiles/mydistro';
  38. mkdir($path, 0777, TRUE);
  39. file_put_contents("$path/mydistro.info.yml", Yaml::encode($this->info));
  40. // Pre-configure hash salt.
  41. // Any string is valid, so simply use the class name of this test.
  42. $this->settings['settings']['hash_salt'] = (object) [
  43. 'value' => __CLASS__,
  44. 'required' => TRUE,
  45. ];
  46. // Pre-configure database credentials.
  47. $connection_info = Database::getConnectionInfo();
  48. unset($connection_info['default']['pdo']);
  49. unset($connection_info['default']['init_commands']);
  50. $this->settings['databases']['default'] = (object) [
  51. 'value' => $connection_info,
  52. 'required' => TRUE,
  53. ];
  54. // Use the kernel to find the site path because the site.path service should
  55. // not be available at this point in the install process.
  56. $site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
  57. // Pre-configure config directories.
  58. $this->settings['config_directories'] = [
  59. CONFIG_SYNC_DIRECTORY => (object) [
  60. 'value' => $site_path . '/files/config_staging',
  61. 'required' => TRUE,
  62. ],
  63. ];
  64. mkdir($this->settings['config_directories'][CONFIG_SYNC_DIRECTORY]->value, 0777, TRUE);
  65. }
  66. /**
  67. * {@inheritdoc}
  68. */
  69. protected function setUpLanguage() {
  70. // Make settings file not writable.
  71. $filename = $this->siteDirectory . '/settings.php';
  72. // Make the settings file read-only.
  73. // Not using File API; a potential error must trigger a PHP warning.
  74. chmod($filename, 0444);
  75. // Verify that the distribution name appears.
  76. $this->assertRaw($this->info['distribution']['name']);
  77. // Verify that the requested theme is used.
  78. $this->assertRaw($this->info['distribution']['install']['theme']);
  79. // Verify that the "Choose profile" step does not appear.
  80. $this->assertNoText('profile');
  81. parent::setUpLanguage();
  82. }
  83. /**
  84. * {@inheritdoc}
  85. */
  86. protected function setUpProfile() {
  87. // This step is skipped, because there is a distribution profile.
  88. }
  89. /**
  90. * {@inheritdoc}
  91. */
  92. protected function setUpSettings() {
  93. // This step should not appear, since settings.php is fully configured
  94. // already.
  95. }
  96. /**
  97. * Confirms that the installation succeeded.
  98. */
  99. public function testInstalled() {
  100. $this->assertUrl('user/1');
  101. $this->assertResponse(200);
  102. // Confirm that we are logged-in after installation.
  103. $this->assertText($this->rootUser->getUsername());
  104. // Confirm that Drupal recognizes this distribution as the current profile.
  105. $this->assertEqual(\Drupal::installProfile(), 'mydistro');
  106. $this->assertArrayNotHasKey('install_profile', Settings::getAll(), 'The install profile has not been written to settings.php.');
  107. $this->assertEqual($this->config('core.extension')->get('profile'), 'mydistro', 'The install profile has been written to core.extension configuration.');
  108. $this->rebuildContainer();
  109. $this->pass('Container can be rebuilt even though distribution is not written to settings.php.');
  110. $this->assertEqual(\Drupal::installProfile(), 'mydistro');
  111. }
  112. }