Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/config/tests/src/Functional/ConfigOtherModuleTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
24 $this->assertTrue($config->isNew(), 'Default configuration for other modules is not installed if that module is not enabled.'); | 24 $this->assertTrue($config->isNew(), 'Default configuration for other modules is not installed if that module is not enabled.'); |
25 | 25 |
26 // Install the module that provides the entity type. This installs the | 26 // Install the module that provides the entity type. This installs the |
27 // default configuration. | 27 // default configuration. |
28 $this->installModule('config_test'); | 28 $this->installModule('config_test'); |
29 $this->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration has been installed.'); | 29 $this->assertTrue($this->getStorage()->load('other_module_test'), 'Default configuration has been installed.'); |
30 | 30 |
31 // Uninstall the module that provides the entity type. This will remove the | 31 // Uninstall the module that provides the entity type. This will remove the |
32 // default configuration. | 32 // default configuration. |
33 $this->uninstallModule('config_test'); | 33 $this->uninstallModule('config_test'); |
34 $config = $this->config('config_test.dynamic.other_module_test'); | 34 $config = $this->config('config_test.dynamic.other_module_test'); |
35 $this->assertTrue($config->isNew(), 'Default configuration for other modules is removed when the config entity provider is disabled.'); | 35 $this->assertTrue($config->isNew(), 'Default configuration for other modules is removed when the config entity provider is disabled.'); |
36 | 36 |
37 // Install the module that provides the entity type again. This installs the | 37 // Install the module that provides the entity type again. This installs the |
38 // default configuration. | 38 // default configuration. |
39 $this->installModule('config_test'); | 39 $this->installModule('config_test'); |
40 $other_module_config_entity = entity_load('config_test', 'other_module_test', TRUE); | 40 $other_module_config_entity = $this->getStorage()->load('other_module_test'); |
41 $this->assertTrue($other_module_config_entity, "Default configuration has been recreated."); | 41 $this->assertTrue($other_module_config_entity, "Default configuration has been recreated."); |
42 | 42 |
43 // Update the default configuration to test that the changes are preserved | 43 // Update the default configuration to test that the changes are preserved |
44 // if the module that provides the default configuration is uninstalled. | 44 // if the module that provides the default configuration is uninstalled. |
45 $other_module_config_entity->set('style', "The piano ain't got no wrong notes."); | 45 $other_module_config_entity->set('style', "The piano ain't got no wrong notes."); |
46 $other_module_config_entity->save(); | 46 $other_module_config_entity->save(); |
47 | 47 |
48 // Uninstall the module that provides the default configuration. | 48 // Uninstall the module that provides the default configuration. |
49 $this->uninstallModule('config_other_module_config_test'); | 49 $this->uninstallModule('config_other_module_config_test'); |
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.'); | 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.'); |
51 | 51 |
52 // Default configuration provided by config_test should still exist. | 52 // Default configuration provided by config_test should still exist. |
53 $this->assertTrue(entity_load('config_test', 'dotted.default', TRUE), 'The configuration is not deleted.'); | 53 $this->assertTrue($this->getStorage()->load('dotted.default'), 'The configuration is not deleted.'); |
54 | 54 |
55 // Re-enable module to test that pre-existing optional configuration does | 55 // Re-enable module to test that pre-existing optional configuration does |
56 // not throw an error. | 56 // not throw an error. |
57 $this->installModule('config_other_module_config_test'); | 57 $this->installModule('config_other_module_config_test'); |
58 $this->assertTrue(\Drupal::moduleHandler()->moduleExists('config_other_module_config_test'), 'The config_other_module_config_test module is installed.'); | 58 $this->assertTrue(\Drupal::moduleHandler()->moduleExists('config_other_module_config_test'), 'The config_other_module_config_test module is installed.'); |
59 | 59 |
60 // Ensure that optional configuration with unmet dependencies is only | 60 // Ensure that optional configuration with unmet dependencies is only |
61 // installed once all the dependencies are met. | 61 // installed once all the dependencies are met. |
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.'); | 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.'); |
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.'); | 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'); |
64 $this->installModule('config_test_language'); | 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.'); |
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.'); | |
66 $this->installModule('config_install_dependency_test'); | 65 $this->installModule('config_install_dependency_test'); |
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.'); | 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.'); |
68 // The following configuration entity's dependencies are now met. It is | 67 // The following configuration entity's dependencies are now met. It is |
69 // indirectly dependent on the config_install_dependency_test module because | 68 // indirectly dependent on the config_install_dependency_test module because |
70 // it has a dependency on the config_test.dynamic.dependency_for_unmet2 | 69 // it has a dependency on the config_test.dynamic.dependency_for_unmet2 |
71 // configuration provided by that module and, therefore, should be created. | 70 // configuration provided by that module and, therefore, should be created. |
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.'); | 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.'); |
73 | 72 |
74 // The following configuration entity's dependencies are now met even though | 73 // The following configuration entity's dependencies are now met even though |
75 // it has no direct dependency on the module. It is indirectly dependent on | 74 // it has no direct dependency on the module. It is indirectly dependent on |
76 // the config_install_dependency_test module because it has a dependency on | 75 // the config_install_dependency_test module because it has a dependency on |
77 // the config_test.dynamic.other_module_test_unmet configuration that is | 76 // the config_test.dynamic.other_module_test_unmet configuration that is |
78 // dependent on the config_install_dependency_test module and, therefore, | 77 // dependent on the config_install_dependency_test module and, therefore, |
79 // should be created. | 78 // should be created. |
80 $entity = entity_load('config_test', 'other_module_test_optional_entity_unmet', TRUE); | 79 $entity = $this->getStorage()->load('other_module_test_optional_entity_unmet'); |
81 $this->assertTrue($entity, 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is created.'); | 80 $this->assertTrue($entity, 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is created.'); |
82 $entity->delete(); | 81 $entity->delete(); |
83 | 82 |
84 // Install another module to ensure the configuration just deleted is not | 83 // Install another module to ensure the configuration just deleted is not |
85 // recreated. | 84 // recreated. |
86 $this->installModule('config'); | 85 $this->installModule('config'); |
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.'); | 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.'); |
88 } | 87 } |
89 | 88 |
90 /** | 89 /** |
91 * Tests enabling the provider of the config entity type first. | 90 * Tests enabling the provider of the config entity type first. |
92 */ | 91 */ |
93 public function testInstallConfigEntityModuleFirst() { | 92 public function testInstallConfigEntityModuleFirst() { |
94 $this->installModule('config_test'); | 93 $this->installModule('config_test'); |
95 $this->assertFalse(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration provided by config_other_module_config_test does not exist.'); | 94 $this->assertFalse($this->getStorage()->load('other_module_test'), 'Default configuration provided by config_other_module_config_test does not exist.'); |
96 | 95 |
97 $this->installModule('config_other_module_config_test'); | 96 $this->installModule('config_other_module_config_test'); |
98 $this->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration provided by config_other_module_config_test has been installed.'); | 97 $this->assertTrue($this->getStorage()->load('other_module_test'), 'Default configuration provided by config_other_module_config_test has been installed.'); |
99 } | 98 } |
100 | 99 |
101 /** | 100 /** |
102 * Tests uninstalling Node module removes views which are dependent on it. | 101 * Tests uninstalling Node module removes views which are dependent on it. |
103 */ | 102 */ |
104 public function testUninstall() { | 103 public function testUninstall() { |
105 $this->installModule('views'); | 104 $this->installModule('views'); |
106 $storage = $this->container->get('entity_type.manager')->getStorage('view'); | 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.'); |
107 $storage->resetCache(['frontpage']); | |
108 $this->assertTrue($storage->load('frontpage') === NULL, 'After installing Views, frontpage view which is dependant on the Node and Views modules does not exist.'); | |
109 $this->installModule('node'); | 106 $this->installModule('node'); |
110 $storage->resetCache(['frontpage']); | 107 $this->assertTrue($this->getStorage('view')->load('frontpage') !== NULL, 'After installing Node, frontpage view which is dependant on the Node and Views modules exists.'); |
111 $this->assertTrue($storage->load('frontpage') !== NULL, 'After installing Node, frontpage view which is dependant on the Node and Views modules exists.'); | |
112 $this->uninstallModule('node'); | 108 $this->uninstallModule('node'); |
113 $storage = $this->container->get('entity_type.manager')->getStorage('view'); | 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.'); |
114 $storage->resetCache(['frontpage']); | |
115 $this->assertTrue($storage->load('frontpage') === NULL, 'After uninstalling Node, frontpage view which is dependant on the Node and Views modules does not exist.'); | |
116 } | 110 } |
117 | 111 |
118 /** | 112 /** |
119 * Installs a module. | 113 * Installs a module. |
120 * | 114 * |
135 protected function uninstallModule($module) { | 129 protected function uninstallModule($module) { |
136 $this->container->get('module_installer')->uninstall([$module]); | 130 $this->container->get('module_installer')->uninstall([$module]); |
137 $this->container = \Drupal::getContainer(); | 131 $this->container = \Drupal::getContainer(); |
138 } | 132 } |
139 | 133 |
134 /** | |
135 * Gets the provided entity type's storage. | |
136 * | |
137 * @param string $entity_type_id | |
138 * (optional) The entity type ID to get a storage for. Defaults to | |
139 * 'config_test'. | |
140 * | |
141 * @return \Drupal\Core\Entity\EntityStorageInterface | |
142 * The entity type's storage. | |
143 */ | |
144 protected function getStorage($entity_type_id = 'config_test') { | |
145 return \Drupal::entityTypeManager()->getStorage($entity_type_id); | |
146 } | |
147 | |
140 } | 148 } |