3 namespace Drupal\FunctionalTests\Installer;
5 use Drupal\Core\DrupalKernel;
6 use Drupal\Core\Database\Database;
7 use Drupal\Core\Site\Settings;
8 use Symfony\Component\HttpFoundation\Request;
11 * Tests installer breaks with a profile mismatch and a read-only settings.php.
16 class InstallerExistingSettingsReadOnlyMismatchProfileTest extends InstallerTestBase {
21 * Configures a preexisting settings.php file without an install_profile
22 * setting before invoking the interactive installer.
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) [
33 // Pre-configure database credentials.
34 $connection_info = Database::getConnectionInfo();
35 unset($connection_info['default']['pdo']);
36 unset($connection_info['default']['init_commands']);
38 $this->settings['databases']['default'] = (object) [
39 'value' => $connection_info,
43 // During interactive install we'll change this to a different profile and
44 // this test will ensure that the new value is written to settings.php.
45 $this->settings['settings']['install_profile'] = (object) [
50 // Pre-configure config directories.
51 $site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
52 $this->settings['config_directories'] = [
53 CONFIG_SYNC_DIRECTORY => (object) [
54 'value' => $site_path . '/files/config_staging',
58 mkdir($this->settings['config_directories'][CONFIG_SYNC_DIRECTORY]->value, 0777, TRUE);
64 protected function visitInstaller() {
65 // Make settings file not writable. This will break the installer.
66 $filename = $this->siteDirectory . '/settings.php';
67 // Make the settings file read-only.
68 // Not using File API; a potential error must trigger a PHP warning.
69 chmod($filename, 0444);
71 $this->drupalGet($GLOBALS['base_url'] . '/core/install.php?langcode=en&profile=testing');
77 protected function setUpLanguage() {
78 // This step is skipped, because there is a lagcode as a query param.
84 protected function setUpProfile() {
85 // This step is skipped, because there is a profile as a query param.
91 protected function setUpSettings() {
92 // This step should not appear, since settings.php is fully configured
97 * Verifies that installation succeeded.
99 * @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
101 public function testInstalled() {
102 $this->initBrowserOutputFile();
103 $this->htmlOutput(NULL);
104 $this->assertEquals('testing', \Drupal::installProfile());
105 $this->assertEquals('minimal', Settings::get('install_profile'));
106 $this->drupalGet('admin/reports/status');
107 $this->assertSession()->pageTextContains("Drupal 8 no longer uses the \$settings['install_profile'] value in settings.php and it can be removed.");