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@18
|
29 $this->assertTrue($this->getStorage()->load('other_module_test'), '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@18
|
40 $other_module_config_entity = $this->getStorage()->load('other_module_test');
|
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@18
|
50 $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
|
51
|
Chris@0
|
52 // Default configuration provided by config_test should still exist.
|
Chris@18
|
53 $this->assertTrue($this->getStorage()->load('dotted.default'), '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@18
|
62 $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
|
63 $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
|
64 $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
|
65 $this->installModule('config_install_dependency_test');
|
Chris@18
|
66 $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
|
67 // The following configuration entity's dependencies are now met. It is
|
Chris@17
|
68 // indirectly dependent on the config_install_dependency_test module because
|
Chris@17
|
69 // it has a dependency on the config_test.dynamic.dependency_for_unmet2
|
Chris@17
|
70 // configuration provided by that module and, therefore, should be created.
|
Chris@18
|
71 $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
|
72
|
Chris@17
|
73 // The following configuration entity's dependencies are now met even though
|
Chris@17
|
74 // it has no direct dependency on the module. It is indirectly dependent on
|
Chris@17
|
75 // the config_install_dependency_test module because it has a dependency on
|
Chris@17
|
76 // the config_test.dynamic.other_module_test_unmet configuration that is
|
Chris@17
|
77 // dependent on the config_install_dependency_test module and, therefore,
|
Chris@17
|
78 // should be created.
|
Chris@18
|
79 $entity = $this->getStorage()->load('other_module_test_optional_entity_unmet');
|
Chris@17
|
80 $this->assertTrue($entity, 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is created.');
|
Chris@17
|
81 $entity->delete();
|
Chris@17
|
82
|
Chris@17
|
83 // Install another module to ensure the configuration just deleted is not
|
Chris@17
|
84 // recreated.
|
Chris@17
|
85 $this->installModule('config');
|
Chris@18
|
86 $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
|
87 }
|
Chris@0
|
88
|
Chris@0
|
89 /**
|
Chris@0
|
90 * Tests enabling the provider of the config entity type first.
|
Chris@0
|
91 */
|
Chris@0
|
92 public function testInstallConfigEntityModuleFirst() {
|
Chris@0
|
93 $this->installModule('config_test');
|
Chris@18
|
94 $this->assertFalse($this->getStorage()->load('other_module_test'), 'Default configuration provided by config_other_module_config_test does not exist.');
|
Chris@0
|
95
|
Chris@0
|
96 $this->installModule('config_other_module_config_test');
|
Chris@18
|
97 $this->assertTrue($this->getStorage()->load('other_module_test'), 'Default configuration provided by config_other_module_config_test has been installed.');
|
Chris@0
|
98 }
|
Chris@0
|
99
|
Chris@0
|
100 /**
|
Chris@0
|
101 * Tests uninstalling Node module removes views which are dependent on it.
|
Chris@0
|
102 */
|
Chris@0
|
103 public function testUninstall() {
|
Chris@0
|
104 $this->installModule('views');
|
Chris@18
|
105 $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
|
106 $this->installModule('node');
|
Chris@18
|
107 $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
|
108 $this->uninstallModule('node');
|
Chris@18
|
109 $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
|
110 }
|
Chris@0
|
111
|
Chris@0
|
112 /**
|
Chris@0
|
113 * Installs a module.
|
Chris@0
|
114 *
|
Chris@0
|
115 * @param string $module
|
Chris@0
|
116 * The module name.
|
Chris@0
|
117 */
|
Chris@0
|
118 protected function installModule($module) {
|
Chris@0
|
119 $this->container->get('module_installer')->install([$module]);
|
Chris@0
|
120 $this->container = \Drupal::getContainer();
|
Chris@0
|
121 }
|
Chris@0
|
122
|
Chris@0
|
123 /**
|
Chris@0
|
124 * Uninstalls a module.
|
Chris@0
|
125 *
|
Chris@0
|
126 * @param string $module
|
Chris@0
|
127 * The module name.
|
Chris@0
|
128 */
|
Chris@0
|
129 protected function uninstallModule($module) {
|
Chris@0
|
130 $this->container->get('module_installer')->uninstall([$module]);
|
Chris@0
|
131 $this->container = \Drupal::getContainer();
|
Chris@0
|
132 }
|
Chris@0
|
133
|
Chris@18
|
134 /**
|
Chris@18
|
135 * Gets the provided entity type's storage.
|
Chris@18
|
136 *
|
Chris@18
|
137 * @param string $entity_type_id
|
Chris@18
|
138 * (optional) The entity type ID to get a storage for. Defaults to
|
Chris@18
|
139 * 'config_test'.
|
Chris@18
|
140 *
|
Chris@18
|
141 * @return \Drupal\Core\Entity\EntityStorageInterface
|
Chris@18
|
142 * The entity type's storage.
|
Chris@18
|
143 */
|
Chris@18
|
144 protected function getStorage($entity_type_id = 'config_test') {
|
Chris@18
|
145 return \Drupal::entityTypeManager()->getStorage($entity_type_id);
|
Chris@18
|
146 }
|
Chris@18
|
147
|
Chris@0
|
148 }
|