3 namespace Drupal\system\Tests\Installer;
5 use Drupal\Core\DrupalKernel;
6 use Drupal\simpletest\InstallerTestBase;
7 use Drupal\Core\Database\Database;
8 use Symfony\Component\HttpFoundation\Request;
11 * Tests installer breaks with a profile mismatch and a read-only settings.php.
15 class InstallerExistingSettingsMismatchProfileBrokenTest extends InstallerTestBase {
20 * Configures a preexisting settings.php file without an install_profile
21 * setting before invoking the interactive installer.
23 protected function setUp() {
24 // Pre-configure hash salt.
25 // Any string is valid, so simply use the class name of this test.
26 $this->settings['settings']['hash_salt'] = (object) [
31 // Pre-configure database credentials.
32 $connection_info = Database::getConnectionInfo();
33 unset($connection_info['default']['pdo']);
34 unset($connection_info['default']['init_commands']);
36 $this->settings['databases']['default'] = (object) [
37 'value' => $connection_info,
41 // During interactive install we'll change this to a different profile and
42 // this test will ensure that the new value is written to settings.php.
43 $this->settings['settings']['install_profile'] = (object) [
48 // Pre-configure config directories.
49 $site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
50 $this->settings['config_directories'] = [
51 CONFIG_SYNC_DIRECTORY => (object) [
52 'value' => $site_path . '/files/config_staging',
56 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
96 protected function setUpSite() {
97 // This step should not appear, since settings.php could not be written.
101 * Verifies that installation did not succeed.
103 public function testBrokenInstaller() {
104 $this->assertTitle('Install profile mismatch | Drupal');
105 $this->assertText("The selected profile testing does not match the install_profile setting, which is minimal. Cannot write updated setting to {$this->siteDirectory}/settings.php.");