diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 6cc85d3..fca92bd 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -849,7 +849,7 @@ function drupal_installation_attempted() { * the installer or during unit tests. * * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0. - * Use \Drupal::installProfile() or the install.profile container parameter + * Use \Drupal::installProfile() or the install_profile container parameter * instead. */ function drupal_get_profile() { diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 08655a8..8b15cef 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -187,7 +187,7 @@ public static function root() { * The name of the any active install profile or distribution. */ public static function installProfile() { - return static::getContainer()->getParameter('install.profile'); + return static::getContainer()->getParameter('install_profile'); } /** diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 3ff9d42..ce5e7d8 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -1080,7 +1080,7 @@ protected function compileContainer() { $container = $this->getContainerBuilder(); $container->set('kernel', $this); $container->setParameter('container.modules', $this->getModulesParameter()); - $container->setParameter('install.profile', $this->getInstallProfile()); + $container->setParameter('install_profile', $this->getInstallProfile()); // Get a list of namespaces and put it onto the container. $namespaces = $this->getModuleNamespacesPsr4($this->getModuleFileNames()); diff --git a/core/modules/system/src/Tests/Installer/DistributionProfileExistingSettingsTest.php b/core/modules/system/src/Tests/Installer/DistributionProfileExistingSettingsTest.php new file mode 100644 index 0000000..f6548eb --- /dev/null +++ b/core/modules/system/src/Tests/Installer/DistributionProfileExistingSettingsTest.php @@ -0,0 +1,132 @@ +info = array( + 'type' => 'profile', + 'core' => \Drupal::CORE_COMPATIBILITY, + 'name' => 'Distribution profile', + 'distribution' => array( + 'name' => 'My Distribution', + 'install' => array( + 'theme' => 'bartik', + ), + ), + ); + // File API functions are not available yet. + $path = $this->siteDirectory . '/profiles/mydistro'; + mkdir($path, 0777, TRUE); + file_put_contents("$path/mydistro.info.yml", Yaml::encode($this->info)); + + // Pre-configure hash salt. + // Any string is valid, so simply use the class name of this test. + $this->settings['settings']['hash_salt'] = (object) array( + 'value' => __CLASS__, + 'required' => TRUE, + ); + + // Pre-configure database credentials. + $connection_info = Database::getConnectionInfo(); + unset($connection_info['default']['pdo']); + unset($connection_info['default']['init_commands']); + + $this->settings['databases']['default'] = (object) array( + 'value' => $connection_info, + 'required' => TRUE, + ); + + // Use the kernel to find the site path because the site.path service should + // not be available at this point in the install process. + $site_path = DrupalKernel::findSitePath(Request::createFromGlobals()); + // Pre-configure config directories. + $this->settings['config_directories'] = array( + CONFIG_ACTIVE_DIRECTORY => (object) array( + 'value' => $site_path . '/files/config_active', + 'required' => TRUE, + ), + CONFIG_STAGING_DIRECTORY => (object) array( + 'value' => $site_path . '/files/config_staging', + 'required' => TRUE, + ), + ); + mkdir($this->settings['config_directories'][CONFIG_ACTIVE_DIRECTORY]->value, 0777, TRUE); + mkdir($this->settings['config_directories'][CONFIG_STAGING_DIRECTORY]->value, 0777, TRUE); + parent::setUp(); + $filename = $this->siteDirectory . '/settings.php'; + // Make the settings file read-only. + // Not using File API; a potential error must trigger a PHP warning. + chmod($filename, 0444); + } + + /** + * Overrides InstallerTest::setUpLanguage(). + */ + protected function setUpLanguage() { + // Verify that the distribution name appears. + $this->assertRaw($this->info['distribution']['name']); + // Verify that the requested theme is used. + $this->assertRaw($this->info['distribution']['install']['theme']); + // Verify that the "Choose profile" step does not appear. + $this->assertNoText('profile'); + + parent::setUpLanguage(); + } + + /** + * {@inheritdoc} + */ + protected function setUpProfile() { + // This step is skipped, because there is a distribution profile. + } + + /** + * {@inheritdoc} + */ + protected function setUpSettings() { + // This step should not appear, since settings.php is fully configured + // already. + } + + /** + * Confirms that the installation succeeded. + */ + public function testInstalled() { + $this->assertUrl('user/1'); + $this->assertResponse(200); + // Confirm that we are logged-in after installation. + $this->assertText($this->rootUser->getUsername()); + + // Confirm that Drupal recognizes this distribution as the current profile. + $this->assertEqual(\Drupal::installProfile(), 'mydistro'); + $this->assertNull(Settings::get('install_profile'), 'The install profile has not been written to settings.php.'); + } + +} diff --git a/core/modules/system/src/Tests/Installer/DistributionProfileTest.php b/core/modules/system/src/Tests/Installer/DistributionProfileTest.php index 55d8d59..ca43d09 100644 --- a/core/modules/system/src/Tests/Installer/DistributionProfileTest.php +++ b/core/modules/system/src/Tests/Installer/DistributionProfileTest.php @@ -77,6 +77,7 @@ public function testInstalled() { // Confirm that Drupal recognizes this distribution as the current profile. $this->assertEqual(\Drupal::installProfile(), 'mydistro'); + $this->assertEqual(Settings::get('install_profile'), 'mydistro', 'The install profile has been written to settings.php.'); } }