Chris@0: installModule('config_other_module_config_test'); Chris@0: Chris@0: // Check that the config entity doesn't exist before the config_test module Chris@0: // is enabled. We cannot use the entity system because the config_test Chris@0: // entity type does not exist. Chris@0: $config = $this->config('config_test.dynamic.other_module_test'); Chris@0: $this->assertTrue($config->isNew(), 'Default configuration for other modules is not installed if that module is not enabled.'); Chris@0: Chris@0: // Install the module that provides the entity type. This installs the Chris@0: // default configuration. Chris@0: $this->installModule('config_test'); Chris@0: $this->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration has been installed.'); Chris@0: Chris@0: // Uninstall the module that provides the entity type. This will remove the Chris@0: // default configuration. Chris@0: $this->uninstallModule('config_test'); Chris@0: $config = $this->config('config_test.dynamic.other_module_test'); Chris@0: $this->assertTrue($config->isNew(), 'Default configuration for other modules is removed when the config entity provider is disabled.'); Chris@0: Chris@0: // Install the module that provides the entity type again. This installs the Chris@0: // default configuration. Chris@0: $this->installModule('config_test'); Chris@0: $other_module_config_entity = entity_load('config_test', 'other_module_test', TRUE); Chris@0: $this->assertTrue($other_module_config_entity, "Default configuration has been recreated."); Chris@0: Chris@0: // Update the default configuration to test that the changes are preserved Chris@0: // if the module that provides the default configuration is uninstalled. Chris@0: $other_module_config_entity->set('style', "The piano ain't got no wrong notes."); Chris@0: $other_module_config_entity->save(); Chris@0: Chris@0: // Uninstall the module that provides the default configuration. Chris@0: $this->uninstallModule('config_other_module_config_test'); Chris@0: $this->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration for other modules is not removed when the module that provides it is uninstalled.'); Chris@0: Chris@0: // Default configuration provided by config_test should still exist. Chris@0: $this->assertTrue(entity_load('config_test', 'dotted.default', TRUE), 'The configuration is not deleted.'); Chris@0: Chris@0: // Re-enable module to test that pre-existing optional configuration does Chris@0: // not throw an error. Chris@0: $this->installModule('config_other_module_config_test'); Chris@0: $this->assertTrue(\Drupal::moduleHandler()->moduleExists('config_other_module_config_test'), 'The config_other_module_config_test module is installed.'); Chris@0: Chris@0: // Ensure that optional configuration with unmet dependencies is only Chris@0: // installed once all the dependencies are met. Chris@0: $this->assertNull(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are not met is not created.'); Chris@0: $this->assertNull(entity_load('config_test', 'other_module_test_optional_entity_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are not met is not created.'); Chris@0: $this->installModule('config_test_language'); Chris@0: $this->installModule('config_install_dependency_test'); Chris@0: $this->assertTrue(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are met is now created.'); Chris@0: // Although the following configuration entity's are now met it is not Chris@0: // installed because it does not have a direct dependency on the Chris@0: // config_install_dependency_test module. Chris@0: $this->assertNull(entity_load('config_test', 'other_module_test_optional_entity_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is not created.'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests enabling the provider of the config entity type first. Chris@0: */ Chris@0: public function testInstallConfigEntityModuleFirst() { Chris@0: $this->installModule('config_test'); Chris@0: $this->assertFalse(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration provided by config_other_module_config_test does not exist.'); Chris@0: Chris@0: $this->installModule('config_other_module_config_test'); Chris@0: $this->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration provided by config_other_module_config_test has been installed.'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests uninstalling Node module removes views which are dependent on it. Chris@0: */ Chris@0: public function testUninstall() { Chris@0: $this->installModule('views'); Chris@0: $storage = $this->container->get('entity_type.manager')->getStorage('view'); Chris@0: $storage->resetCache(['frontpage']); Chris@0: $this->assertTrue($storage->load('frontpage') === NULL, 'After installing Views, frontpage view which is dependant on the Node and Views modules does not exist.'); Chris@0: $this->installModule('node'); Chris@0: $storage->resetCache(['frontpage']); Chris@0: $this->assertTrue($storage->load('frontpage') !== NULL, 'After installing Node, frontpage view which is dependant on the Node and Views modules exists.'); Chris@0: $this->uninstallModule('node'); Chris@0: $storage = $this->container->get('entity_type.manager')->getStorage('view'); Chris@0: $storage->resetCache(['frontpage']); Chris@0: $this->assertTrue($storage->load('frontpage') === NULL, 'After uninstalling Node, frontpage view which is dependant on the Node and Views modules does not exist.'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Installs a module. Chris@0: * Chris@0: * @param string $module Chris@0: * The module name. Chris@0: */ Chris@0: protected function installModule($module) { Chris@0: $this->container->get('module_installer')->install([$module]); Chris@0: $this->container = \Drupal::getContainer(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Uninstalls a module. Chris@0: * Chris@0: * @param string $module Chris@0: * The module name. Chris@0: */ Chris@0: protected function uninstallModule($module) { Chris@0: $this->container->get('module_installer')->uninstall([$module]); Chris@0: $this->container = \Drupal::getContainer(); Chris@0: } Chris@0: Chris@0: }