public function ConfigInstallWebTest::testIntegrationModuleReinstallation in Drupal 8
Same name and namespace in other branches
- 9 core/modules/config/tests/src/Functional/ConfigInstallWebTest.php \Drupal\Tests\config\Functional\ConfigInstallWebTest::testIntegrationModuleReinstallation()
- 10 core/modules/config/tests/src/Functional/ConfigInstallWebTest.php \Drupal\Tests\config\Functional\ConfigInstallWebTest::testIntegrationModuleReinstallation()
Tests module re-installation.
File
- core/
modules/ config/ tests/ src/ Functional/ ConfigInstallWebTest.php, line 51
Class
- ConfigInstallWebTest
- Tests installation and removal of configuration objects in install, disable and uninstall functionality.
Namespace
Drupal\Tests\config\FunctionalCode
public function testIntegrationModuleReinstallation() {
$default_config = 'config_integration_test.settings';
$default_configuration_entity = 'config_test.dynamic.config_integration_test';
// Install the config_test module we're integrating with.
\Drupal::service('module_installer')
->install([
'config_test',
]);
// Verify the configuration does not exist prior to installation.
$config_static = $this
->config($default_config);
$this
->assertIdentical($config_static
->isNew(), TRUE);
$config_entity = $this
->config($default_configuration_entity);
$this
->assertIdentical($config_entity
->isNew(), TRUE);
// Install the integration module.
\Drupal::service('module_installer')
->install([
'config_integration_test',
]);
$this
->resetAll();
// Verify that default module config exists.
\Drupal::configFactory()
->reset($default_config);
\Drupal::configFactory()
->reset($default_configuration_entity);
$config_static = $this
->config($default_config);
$this
->assertIdentical($config_static
->isNew(), FALSE);
$this
->assertIdentical($config_static
->get('foo'), 'default setting');
$config_entity = $this
->config($default_configuration_entity);
$this
->assertIdentical($config_entity
->isNew(), FALSE);
$this
->assertIdentical($config_entity
->get('label'), 'Default integration config label');
// Customize both configuration objects.
$config_static
->set('foo', 'customized setting')
->save();
$config_entity
->set('label', 'Customized integration config label')
->save();
// @todo FIXME: Setting config keys WITHOUT SAVING retains the changed config
// object in memory. Every new call to $this->config() MUST revert in-memory changes
// that haven't been saved!
// In other words: This test passes even without this reset, but it shouldn't.
$this->container
->get('config.factory')
->reset();
// Disable and uninstall the integration module.
$this->container
->get('module_installer')
->uninstall([
'config_integration_test',
]);
// Verify the integration module's config was uninstalled.
$config_static = $this
->config($default_config);
$this
->assertIdentical($config_static
->isNew(), TRUE);
// Verify the integration config still exists.
$config_entity = $this
->config($default_configuration_entity);
$this
->assertIdentical($config_entity
->isNew(), FALSE);
$this
->assertIdentical($config_entity
->get('label'), 'Customized integration config label');
// Reinstall the integration module.
try {
\Drupal::service('module_installer')
->install([
'config_integration_test',
]);
$this
->fail('Expected PreExistingConfigException not thrown.');
} catch (PreExistingConfigException $e) {
$this
->assertEquals('config_integration_test', $e
->getExtension());
$this
->assertEquals([
StorageInterface::DEFAULT_COLLECTION => [
'config_test.dynamic.config_integration_test',
],
], $e
->getConfigObjects());
$this
->assertEquals('Configuration objects (config_test.dynamic.config_integration_test) provided by config_integration_test already exist in active configuration', $e
->getMessage());
}
// Delete the configuration entity so that the install will work.
$config_entity
->delete();
\Drupal::service('module_installer')
->install([
'config_integration_test',
]);
// Verify the integration module's config was re-installed.
\Drupal::configFactory()
->reset($default_config);
\Drupal::configFactory()
->reset($default_configuration_entity);
$config_static = $this
->config($default_config);
$this
->assertIdentical($config_static
->isNew(), FALSE);
$this
->assertIdentical($config_static
->get('foo'), 'default setting');
// Verify the integration config is using the default.
$config_entity = \Drupal::config($default_configuration_entity);
$this
->assertIdentical($config_entity
->isNew(), FALSE);
$this
->assertIdentical($config_entity
->get('label'), 'Default integration config label');
}