diff --git a/core/modules/system/src/Tests/Installer/InstallerConfigDirectorySetNoDirectoryErrorTest.php b/core/modules/system/src/Tests/Installer/InstallerConfigDirectorySetNoDirectoryErrorTest.php new file mode 100644 index 0000000..dbb15be --- /dev/null +++ b/core/modules/system/src/Tests/Installer/InstallerConfigDirectorySetNoDirectoryErrorTest.php @@ -0,0 +1,62 @@ +configDirectory = $this->publicFilesDirectory . '/config_' . Crypt::randomBytesBase64(); + $this->settings['config_directories'][CONFIG_SYNC_DIRECTORY] = (object) array( + 'value' => $this->configDirectory . '/sync', + 'required' => TRUE, + ); + // Create the files directory early so we can test the error case. + mkdir($this->publicFilesDirectory); + // Create a file so the directory can not be created. + file_put_contents($this->configDirectory, 'Test'); + parent::setUp(); + } + + /** + * Installer step: Configure settings. + */ + protected function setUpSettings() { + // This step should not appear as we had a failure prior to the settings + // screen. + } + + /** + * @{inheritdoc} + */ + protected function setUpSite() { + // This step should not appear as we had a failure prior to the settings + // screen. + } + + /** + * Verifies that installation failed. + */ + public function testError() { + $this->assertText("An automated attempt to create the directory {$this->configDirectory}/sync failed, possibly due to a permissions problem."); + $this->assertFalse(file_exists($this->configDirectory . '/sync') && is_dir($this->configDirectory . '/sync'), "The directory {$this->configDirectory}/sync does not exist."); + } + +} diff --git a/core/modules/system/src/Tests/Installer/InstallerConfigDirectorySetNoDirectoryTest.php b/core/modules/system/src/Tests/Installer/InstallerConfigDirectorySetNoDirectoryTest.php new file mode 100644 index 0000000..4daa45c --- /dev/null +++ b/core/modules/system/src/Tests/Installer/InstallerConfigDirectorySetNoDirectoryTest.php @@ -0,0 +1,49 @@ +syncDirectory = $this->publicFilesDirectory . '/config_' . Crypt::randomBytesBase64() . '/sync'; + $this->settings['config_directories'][CONFIG_SYNC_DIRECTORY] = (object) array( + 'value' => $this->syncDirectory, + 'required' => TRUE, + ); + // Other directories will be created too. + $this->settings['config_directories']['custom'] = (object) array( + 'value' => $this->publicFilesDirectory . '/config_custom', + 'required' => TRUE, + ); + parent::setUp(); + } + + /** + * Verifies that installation succeeded. + */ + public function testInstaller() { + $this->assertUrl('user/1'); + $this->assertResponse(200); + $this->assertTrue(file_exists($this->syncDirectory) && is_dir($this->syncDirectory), "The directory {$this->syncDirectory} exists."); + $this->assertTrue(file_exists($this->publicFilesDirectory . '/config_custom') && is_dir($this->publicFilesDirectory . '/config_custom'), "The directory {$this->publicFilesDirectory}/custom_config exists."); + } + +} diff --git a/core/modules/system/system.install b/core/modules/system/system.install index ed181f2..7f8bc24 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -551,10 +551,20 @@ function system_requirements($phase) { if (!empty($GLOBALS['config_directories'])) { foreach (array_keys(array_filter($GLOBALS['config_directories'])) as $type) { $directory = config_get_config_directory($type); + // If we're installing Drupal try and create the config sync directory. + if (!is_dir($directory) && $phase == 'install') { + file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); + } if (!is_dir($directory)) { + if ($phase == 'install') { + $description = t('An automated attempt to create the directory %directory failed, possibly due to a permissions problem. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see INSTALL.txt or the online handbook.', array('%directory' => $directory, ':handbook_url' => 'https://www.drupal.org/server-permissions')); + } + else { + $description = t('The directory %directory does not exist.', array('%directory' => $directory)); + } $requirements['config directory ' . $type] = array( 'title' => t('Configuration directory: %type', ['%type' => $type]), - 'description' => t('The directory %directory does not exist.', array('%directory' => $directory)), + 'description' => $description, 'severity' => REQUIREMENT_ERROR, ); }