diff -u b/core/modules/config/lib/Drupal/config/Tests/ConfigSnapshotTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigSnapshotTest.php --- b/core/modules/config/lib/Drupal/config/Tests/ConfigSnapshotTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigSnapshotTest.php @@ -33,6 +33,9 @@ public function setUp() { parent::setUp(); $this->installSchema('system', 'config_snapshot'); + // Update the config snapshot. This allows the parent::setUp() to write + // configuration files. + config_import_create_snapshot(\Drupal::service('config.storage'), \Drupal::service('config.storage.snapshot')); } /** diff -u b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php --- b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -103,11 +103,11 @@ $this->kernel->boot(); // Create a minimal system.module configuration file so that the list of - // enabled modules can be maintained enabling - // \Drupal\Core\Config\ConfigInstaller::installDefaultConfig() to work. - \Drupal::config('system.module') - ->set('enabled', array()) - ->save(); + // enabled modules can be maintained allowing + // \Drupal\Core\Config\ConfigInstaller::installDefaultConfig() to work. Not + // using configuration factory ensures that events registered by modules + // during self::enableModules are registered. + \Drupal::service('config.cachedstorage.storage')->write('system.module', array('enabled' => array())); // Collect and set a fixed module list. $class = get_class($this); @@ -275,12 +275,16 @@ // Set the list of modules in the extension handler. $module_handler = $this->container->get('module_handler'); $module_filenames = $module_handler->getModuleList(); - $system_config = $this->container->get('config.factory')->get('system.module'); + // Write directly to active storage to avoid early instantiation of + // services which can prevent modules from registering events. + $active_storage = \Drupal::service('config.cachedstorage.storage'); + $system_config = $active_storage->read('system.module'); foreach ($modules as $module) { $module_filenames[$module] = drupal_get_filename('module', $module); // Maintain the list of enabled modules in configuration. - $system_config->set('enabled.' . $module, 0); + $system_config['enabled'][$module] = 0; } + $active_storage->write('system.module', $system_config); $module_handler->setModuleList($module_filenames); $module_handler->resetImplementations(); // Update the kernel to make their services available. @@ -294,7 +298,6 @@ $this->pass(format_string('Enabled modules: %modules.', array( '%modules' => implode(', ', $modules), ))); - $system_config->save(); } /** @@ -310,9 +313,12 @@ // Unset the list of modules in the extension handler. $module_handler = $this->container->get('module_handler'); $module_filenames = $module_handler->getModuleList(); + $system_config = $this->container->get('config.factory')->get('system.module'); foreach ($modules as $module) { unset($module_filenames[$module]); + $system_config->clear('enabled.' . $module); } + $system_config->save(); $module_handler->setModuleList($module_filenames); $module_handler->resetImplementations(); // Update the kernel to remove their services. only in patch2: unchanged: --- a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php @@ -173,6 +173,11 @@ function testInstancePrepare() { * Test that instances on disabled entity types are filtered out. */ function testInstanceDisabledEntityType() { + // Disabling the comment module invokes user_modules_uninstalled() and calls + // drupal_flush_all_caches(). Install the necessary schema to support this. + $this->installSchema('user', array('users_data')); + $this->installSchema('system', array('router')); + // For this test the field type and the entity type must be exposed by // different modules. $this->enableModules(array('node', 'comment')); @@ -187,9 +192,10 @@ function testInstanceDisabledEntityType() { 'entity_type' => 'comment', 'bundle' => 'comment_node_article', ); - entity_create('field_instance', $instance_definition); + entity_create('field_instance', $instance_definition)->save(); - // Disable coment module. This clears field_info cache. + $this->assertNotNull(field_info_instance('comment', 'field', 'comment_node_article'), 'Instance is returned on enabled entity types.'); + // Disable comment module. This clears field_info cache. module_uninstall(array('comment')); $this->assertNull(field_info_instance('comment', 'field', 'comment_node_article'), 'No instances are returned on disabled entity types.'); }