annotate core/modules/config/tests/src/Functional/ConfigOtherModuleTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children af1871eacc83
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\config\Functional;
Chris@0 4
Chris@0 5 use Drupal\Tests\BrowserTestBase;
Chris@0 6
Chris@0 7 /**
Chris@0 8 * Tests default configuration provided by a module that does not own it.
Chris@0 9 *
Chris@0 10 * @group config
Chris@0 11 */
Chris@0 12 class ConfigOtherModuleTest extends BrowserTestBase {
Chris@0 13
Chris@0 14 /**
Chris@0 15 * Tests enabling the provider of the default configuration first.
Chris@0 16 */
Chris@0 17 public function testInstallOtherModuleFirst() {
Chris@0 18 $this->installModule('config_other_module_config_test');
Chris@0 19
Chris@0 20 // Check that the config entity doesn't exist before the config_test module
Chris@0 21 // is enabled. We cannot use the entity system because the config_test
Chris@0 22 // entity type does not exist.
Chris@0 23 $config = $this->config('config_test.dynamic.other_module_test');
Chris@0 24 $this->assertTrue($config->isNew(), 'Default configuration for other modules is not installed if that module is not enabled.');
Chris@0 25
Chris@0 26 // Install the module that provides the entity type. This installs the
Chris@0 27 // default configuration.
Chris@0 28 $this->installModule('config_test');
Chris@0 29 $this->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration has been installed.');
Chris@0 30
Chris@0 31 // Uninstall the module that provides the entity type. This will remove the
Chris@0 32 // default configuration.
Chris@0 33 $this->uninstallModule('config_test');
Chris@0 34 $config = $this->config('config_test.dynamic.other_module_test');
Chris@0 35 $this->assertTrue($config->isNew(), 'Default configuration for other modules is removed when the config entity provider is disabled.');
Chris@0 36
Chris@0 37 // Install the module that provides the entity type again. This installs the
Chris@0 38 // default configuration.
Chris@0 39 $this->installModule('config_test');
Chris@0 40 $other_module_config_entity = entity_load('config_test', 'other_module_test', TRUE);
Chris@0 41 $this->assertTrue($other_module_config_entity, "Default configuration has been recreated.");
Chris@0 42
Chris@0 43 // Update the default configuration to test that the changes are preserved
Chris@0 44 // if the module that provides the default configuration is uninstalled.
Chris@0 45 $other_module_config_entity->set('style', "The piano ain't got no wrong notes.");
Chris@0 46 $other_module_config_entity->save();
Chris@0 47
Chris@0 48 // Uninstall the module that provides the default configuration.
Chris@0 49 $this->uninstallModule('config_other_module_config_test');
Chris@0 50 $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 51
Chris@0 52 // Default configuration provided by config_test should still exist.
Chris@0 53 $this->assertTrue(entity_load('config_test', 'dotted.default', TRUE), 'The configuration is not deleted.');
Chris@0 54
Chris@0 55 // Re-enable module to test that pre-existing optional configuration does
Chris@0 56 // not throw an error.
Chris@0 57 $this->installModule('config_other_module_config_test');
Chris@0 58 $this->assertTrue(\Drupal::moduleHandler()->moduleExists('config_other_module_config_test'), 'The config_other_module_config_test module is installed.');
Chris@0 59
Chris@0 60 // Ensure that optional configuration with unmet dependencies is only
Chris@0 61 // installed once all the dependencies are met.
Chris@0 62 $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 63 $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 64 $this->installModule('config_test_language');
Chris@17 65 $this->assertNull(entity_load('config_test', 'other_module_test_optional_entity_unmet2', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet2 whose dependencies are not met is not created.');
Chris@0 66 $this->installModule('config_install_dependency_test');
Chris@0 67 $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@17 68 // The following configuration entity's dependencies are now met. It is
Chris@17 69 // indirectly dependent on the config_install_dependency_test module because
Chris@17 70 // it has a dependency on the config_test.dynamic.dependency_for_unmet2
Chris@17 71 // configuration provided by that module and, therefore, should be created.
Chris@17 72 $this->assertTrue(entity_load('config_test', 'other_module_test_optional_entity_unmet2', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet2 whose dependencies are met is now created.');
Chris@17 73
Chris@17 74 // The following configuration entity's dependencies are now met even though
Chris@17 75 // it has no direct dependency on the module. It is indirectly dependent on
Chris@17 76 // the config_install_dependency_test module because it has a dependency on
Chris@17 77 // the config_test.dynamic.other_module_test_unmet configuration that is
Chris@17 78 // dependent on the config_install_dependency_test module and, therefore,
Chris@17 79 // should be created.
Chris@17 80 $entity = entity_load('config_test', 'other_module_test_optional_entity_unmet', TRUE);
Chris@17 81 $this->assertTrue($entity, 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is created.');
Chris@17 82 $entity->delete();
Chris@17 83
Chris@17 84 // Install another module to ensure the configuration just deleted is not
Chris@17 85 // recreated.
Chris@17 86 $this->installModule('config');
Chris@17 87 $this->assertFalse(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 installed when an unrelated module is installed.');
Chris@0 88 }
Chris@0 89
Chris@0 90 /**
Chris@0 91 * Tests enabling the provider of the config entity type first.
Chris@0 92 */
Chris@0 93 public function testInstallConfigEntityModuleFirst() {
Chris@0 94 $this->installModule('config_test');
Chris@0 95 $this->assertFalse(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration provided by config_other_module_config_test does not exist.');
Chris@0 96
Chris@0 97 $this->installModule('config_other_module_config_test');
Chris@0 98 $this->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration provided by config_other_module_config_test has been installed.');
Chris@0 99 }
Chris@0 100
Chris@0 101 /**
Chris@0 102 * Tests uninstalling Node module removes views which are dependent on it.
Chris@0 103 */
Chris@0 104 public function testUninstall() {
Chris@0 105 $this->installModule('views');
Chris@0 106 $storage = $this->container->get('entity_type.manager')->getStorage('view');
Chris@0 107 $storage->resetCache(['frontpage']);
Chris@0 108 $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 109 $this->installModule('node');
Chris@0 110 $storage->resetCache(['frontpage']);
Chris@0 111 $this->assertTrue($storage->load('frontpage') !== NULL, 'After installing Node, frontpage view which is dependant on the Node and Views modules exists.');
Chris@0 112 $this->uninstallModule('node');
Chris@0 113 $storage = $this->container->get('entity_type.manager')->getStorage('view');
Chris@0 114 $storage->resetCache(['frontpage']);
Chris@0 115 $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 116 }
Chris@0 117
Chris@0 118 /**
Chris@0 119 * Installs a module.
Chris@0 120 *
Chris@0 121 * @param string $module
Chris@0 122 * The module name.
Chris@0 123 */
Chris@0 124 protected function installModule($module) {
Chris@0 125 $this->container->get('module_installer')->install([$module]);
Chris@0 126 $this->container = \Drupal::getContainer();
Chris@0 127 }
Chris@0 128
Chris@0 129 /**
Chris@0 130 * Uninstalls a module.
Chris@0 131 *
Chris@0 132 * @param string $module
Chris@0 133 * The module name.
Chris@0 134 */
Chris@0 135 protected function uninstallModule($module) {
Chris@0 136 $this->container->get('module_installer')->uninstall([$module]);
Chris@0 137 $this->container = \Drupal::getContainer();
Chris@0 138 }
Chris@0 139
Chris@0 140 }