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@0
|
65 $this->installModule('config_install_dependency_test');
|
Chris@0
|
66 $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@0
|
67 // Although the following configuration entity's are now met it is not
|
Chris@0
|
68 // installed because it does not have a direct dependency on the
|
Chris@0
|
69 // config_install_dependency_test module.
|
Chris@0
|
70 $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 met is not created.');
|
Chris@0
|
71 }
|
Chris@0
|
72
|
Chris@0
|
73 /**
|
Chris@0
|
74 * Tests enabling the provider of the config entity type first.
|
Chris@0
|
75 */
|
Chris@0
|
76 public function testInstallConfigEntityModuleFirst() {
|
Chris@0
|
77 $this->installModule('config_test');
|
Chris@0
|
78 $this->assertFalse(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration provided by config_other_module_config_test does not exist.');
|
Chris@0
|
79
|
Chris@0
|
80 $this->installModule('config_other_module_config_test');
|
Chris@0
|
81 $this->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration provided by config_other_module_config_test has been installed.');
|
Chris@0
|
82 }
|
Chris@0
|
83
|
Chris@0
|
84 /**
|
Chris@0
|
85 * Tests uninstalling Node module removes views which are dependent on it.
|
Chris@0
|
86 */
|
Chris@0
|
87 public function testUninstall() {
|
Chris@0
|
88 $this->installModule('views');
|
Chris@0
|
89 $storage = $this->container->get('entity_type.manager')->getStorage('view');
|
Chris@0
|
90 $storage->resetCache(['frontpage']);
|
Chris@0
|
91 $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
|
92 $this->installModule('node');
|
Chris@0
|
93 $storage->resetCache(['frontpage']);
|
Chris@0
|
94 $this->assertTrue($storage->load('frontpage') !== NULL, 'After installing Node, frontpage view which is dependant on the Node and Views modules exists.');
|
Chris@0
|
95 $this->uninstallModule('node');
|
Chris@0
|
96 $storage = $this->container->get('entity_type.manager')->getStorage('view');
|
Chris@0
|
97 $storage->resetCache(['frontpage']);
|
Chris@0
|
98 $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
|
99 }
|
Chris@0
|
100
|
Chris@0
|
101 /**
|
Chris@0
|
102 * Installs a module.
|
Chris@0
|
103 *
|
Chris@0
|
104 * @param string $module
|
Chris@0
|
105 * The module name.
|
Chris@0
|
106 */
|
Chris@0
|
107 protected function installModule($module) {
|
Chris@0
|
108 $this->container->get('module_installer')->install([$module]);
|
Chris@0
|
109 $this->container = \Drupal::getContainer();
|
Chris@0
|
110 }
|
Chris@0
|
111
|
Chris@0
|
112 /**
|
Chris@0
|
113 * Uninstalls 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 uninstallModule($module) {
|
Chris@0
|
119 $this->container->get('module_installer')->uninstall([$module]);
|
Chris@0
|
120 $this->container = \Drupal::getContainer();
|
Chris@0
|
121 }
|
Chris@0
|
122
|
Chris@0
|
123 }
|