You are here

public function ConfigOtherModuleTest::testInstallOtherModuleFirst in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/config/src/Tests/ConfigOtherModuleTest.php \Drupal\config\Tests\ConfigOtherModuleTest::testInstallOtherModuleFirst()

Tests enabling the provider of the default configuration first.

File

core/modules/config/src/Tests/ConfigOtherModuleTest.php, line 22
Contains \Drupal\config\Tests\ConfigOtherModuleTest.

Class

ConfigOtherModuleTest
Tests default configuration provided by a module that does not own it.

Namespace

Drupal\config\Tests

Code

public function testInstallOtherModuleFirst() {
  $this
    ->installModule('config_other_module_config_test');

  // Check that the config entity doesn't exist before the config_test module
  // is enabled. We cannot use the entity system because the config_test
  // entity type does not exist.
  $config = $this
    ->config('config_test.dynamic.other_module_test');
  $this
    ->assertTrue($config
    ->isNew(), 'Default configuration for other modules is not installed if that module is not enabled.');

  // Install the module that provides the entity type. This installs the
  // default configuration.
  $this
    ->installModule('config_test');
  $this
    ->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration has been installed.');

  // Uninstall the module that provides the entity type. This will remove the
  // default configuration.
  $this
    ->uninstallModule('config_test');
  $config = $this
    ->config('config_test.dynamic.other_module_test');
  $this
    ->assertTrue($config
    ->isNew(), 'Default configuration for other modules is removed when the config entity provider is disabled.');

  // Install the module that provides the entity type again. This installs the
  // default configuration.
  $this
    ->installModule('config_test');
  $other_module_config_entity = entity_load('config_test', 'other_module_test', TRUE);
  $this
    ->assertTrue($other_module_config_entity, "Default configuration has been recreated.");

  // Update the default configuration to test that the changes are preserved
  // if the module that provides the default configuration is uninstalled.
  $other_module_config_entity
    ->set('style', "The piano ain't got no wrong notes.");
  $other_module_config_entity
    ->save();

  // Uninstall the module that provides the default configuration.
  $this
    ->uninstallModule('config_other_module_config_test');
  $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.');

  // Default configuration provided by config_test should still exist.
  $this
    ->assertTrue(entity_load('config_test', 'dotted.default', TRUE), 'The configuration is not deleted.');

  // Re-enable module to test that pre-existing optional configuration does
  // not throw an error.
  $this
    ->installModule('config_other_module_config_test');
  $this
    ->assertTrue(\Drupal::moduleHandler()
    ->moduleExists('config_other_module_config_test'), 'The config_other_module_config_test module is installed.');

  // Ensure that optional configuration with unmet dependencies is only
  // installed once all the dependencies are met.
  $this
    ->assertNull(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration whose dependencies are met is not created.');
  $this
    ->installModule('config_install_dependency_test');
  $this
    ->assertTrue(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration whose dependencies are met is now created.');
}