diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php index e0d4e0d..26572aa 100644 --- a/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -725,6 +725,13 @@ protected function validate() { $this->logError($this->t('Rename operation for simple configuration. Existing configuration !old_name and staged configuration !new_name.', array('old_name' => $names['old_name'], 'new_name' => $names['new_name']))); } } + // Ensure that modules can be uninstalled. + if ($reasons = $this->moduleInstaller->validateUninstall($this->getExtensionChangelist('module', 'uninstall'))) { + foreach ($reasons as $module => $reason) { + $this->logError($this->t('Unable to uninstall the %module module because: !reason.', array('%module' => $this->moduleHandler->getName($module), '!reason' => implode(', ', $reason)))); + } + } + $this->eventDispatcher->dispatch(ConfigEvents::IMPORT_VALIDATE, new ConfigImporterEvent($this)); if (count($this->getErrors())) { throw new ConfigImporterException('There were errors validating the config synchronization.'); diff --git a/core/modules/config/src/Tests/ConfigImporterTest.php b/core/modules/config/src/Tests/ConfigImporterTest.php index e39baf6..89c7a6c 100644 --- a/core/modules/config/src/Tests/ConfigImporterTest.php +++ b/core/modules/config/src/Tests/ConfigImporterTest.php @@ -649,6 +649,29 @@ public function testMissingCoreExtension() { } /** + * Tests uninstall validators being called during synchronisation. + * + * @see \Drupal\Core\EventSubscriber\ConfigImportSubscriber + */ + public function testMissingExtensionValidation() { + $staging = $this->container->get('config.storage.staging'); + $extensions = $staging->read('core.extension'); + // Remove the config_test module. + unset($extensions['module']['system']); + $staging->write('core.extension', $extensions); + + try { + $this->configImporter->reset()->import(); + $this->fail('ConfigImporterException not thrown, invalid import was not stopped due to missing dependencies.'); + } + catch (ConfigImporterException $e) { + $this->assertEqual($e->getMessage(), 'There were errors validating the config synchronization.'); + $error_log = $this->configImporter->getErrors(); + $this->assertEqual(['Unable to uninstall the System module because: The System module is required.'], $error_log); + } + } + + /** * Tests install profile validation during configuration import. * * @see \Drupal\Core\EventSubscriber\ConfigImportSubscriber