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@18: $this->assertTrue($this->getStorage()->load('other_module_test'), '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@18: $other_module_config_entity = $this->getStorage()->load('other_module_test'); 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@18: $this->assertTrue($this->getStorage()->load('other_module_test'), '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@18: $this->assertTrue($this->getStorage()->load('dotted.default'), '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@18: $this->assertNull($this->getStorage()->load('other_module_test_unmet'), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are not met is not created.'); Chris@18: $this->assertNull($this->getStorage()->load('other_module_test_optional_entity_unmet'), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are not met is not created.'); $this->installModule('config_test_language'); Chris@18: $this->assertNull($this->getStorage()->load('other_module_test_optional_entity_unmet'), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is not created.'); Chris@0: $this->installModule('config_install_dependency_test'); Chris@18: $this->assertTrue($this->getStorage()->load('other_module_test_unmet'), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are met is now created.'); Chris@17: // The following configuration entity's dependencies are now met. It is Chris@17: // indirectly dependent on the config_install_dependency_test module because Chris@17: // it has a dependency on the config_test.dynamic.dependency_for_unmet2 Chris@17: // configuration provided by that module and, therefore, should be created. Chris@18: $this->assertTrue($this->getStorage()->load('other_module_test_optional_entity_unmet2'), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet2 whose dependencies are met is now created.'); Chris@17: Chris@17: // The following configuration entity's dependencies are now met even though Chris@17: // it has no direct dependency on the module. It is indirectly dependent on Chris@17: // the config_install_dependency_test module because it has a dependency on Chris@17: // the config_test.dynamic.other_module_test_unmet configuration that is Chris@17: // dependent on the config_install_dependency_test module and, therefore, Chris@17: // should be created. Chris@18: $entity = $this->getStorage()->load('other_module_test_optional_entity_unmet'); Chris@17: $this->assertTrue($entity, 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is created.'); Chris@17: $entity->delete(); Chris@17: Chris@17: // Install another module to ensure the configuration just deleted is not Chris@17: // recreated. Chris@17: $this->installModule('config'); Chris@18: $this->assertFalse($this->getStorage()->load('other_module_test_optional_entity_unmet'), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is not installed when an unrelated module is installed.'); 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@18: $this->assertFalse($this->getStorage()->load('other_module_test'), 'Default configuration provided by config_other_module_config_test does not exist.'); Chris@0: Chris@0: $this->installModule('config_other_module_config_test'); Chris@18: $this->assertTrue($this->getStorage()->load('other_module_test'), '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@18: $this->assertTrue($this->getStorage('view')->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@18: $this->assertTrue($this->getStorage('view')->load('frontpage') !== NULL, 'After installing Node, frontpage view which is dependant on the Node and Views modules exists.'); Chris@0: $this->uninstallModule('node'); Chris@18: $this->assertTrue($this->getStorage('view')->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@18: /** Chris@18: * Gets the provided entity type's storage. Chris@18: * Chris@18: * @param string $entity_type_id Chris@18: * (optional) The entity type ID to get a storage for. Defaults to Chris@18: * 'config_test'. Chris@18: * Chris@18: * @return \Drupal\Core\Entity\EntityStorageInterface Chris@18: * The entity type's storage. Chris@18: */ Chris@18: protected function getStorage($entity_type_id = 'config_test') { Chris@18: return \Drupal::entityTypeManager()->getStorage($entity_type_id); Chris@18: } Chris@18: Chris@0: }