Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\system\Tests\Module;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Component\Utility\Unicode;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Enable module without dependency enabled.
|
Chris@0
|
9 *
|
Chris@0
|
10 * @group Module
|
Chris@0
|
11 */
|
Chris@0
|
12 class DependencyTest extends ModuleTestBase {
|
Chris@0
|
13 /**
|
Chris@0
|
14 * Checks functionality of project namespaces for dependencies.
|
Chris@0
|
15 */
|
Chris@0
|
16 public function testProjectNamespaceForDependencies() {
|
Chris@0
|
17 $edit = [
|
Chris@0
|
18 'modules[filter][enable]' => TRUE,
|
Chris@0
|
19 ];
|
Chris@0
|
20 $this->drupalPostForm('admin/modules', $edit, t('Install'));
|
Chris@0
|
21 // Enable module with project namespace to ensure nothing breaks.
|
Chris@0
|
22 $edit = [
|
Chris@0
|
23 'modules[system_project_namespace_test][enable]' => TRUE,
|
Chris@0
|
24 ];
|
Chris@0
|
25 $this->drupalPostForm('admin/modules', $edit, t('Install'));
|
Chris@0
|
26 $this->assertModules(['system_project_namespace_test'], TRUE);
|
Chris@0
|
27 }
|
Chris@0
|
28
|
Chris@0
|
29 /**
|
Chris@0
|
30 * Attempts to enable the Content Translation module without Language enabled.
|
Chris@0
|
31 */
|
Chris@0
|
32 public function testEnableWithoutDependency() {
|
Chris@0
|
33 // Attempt to enable Content Translation without Language enabled.
|
Chris@0
|
34 $edit = [];
|
Chris@0
|
35 $edit['modules[content_translation][enable]'] = 'content_translation';
|
Chris@0
|
36 $this->drupalPostForm('admin/modules', $edit, t('Install'));
|
Chris@0
|
37 $this->assertText(t('Some required modules must be enabled'), 'Dependency required.');
|
Chris@0
|
38
|
Chris@0
|
39 $this->assertModules(['content_translation', 'language'], FALSE);
|
Chris@0
|
40
|
Chris@0
|
41 // Assert that the language tables weren't enabled.
|
Chris@0
|
42 $this->assertTableCount('language', FALSE);
|
Chris@0
|
43
|
Chris@0
|
44 $this->drupalPostForm(NULL, NULL, t('Continue'));
|
Chris@0
|
45 $this->assertText(t('2 modules have been enabled: Content Translation, Language.'), 'Modules status has been updated.');
|
Chris@0
|
46 $this->assertModules(['content_translation', 'language'], TRUE);
|
Chris@0
|
47
|
Chris@0
|
48 // Assert that the language YAML files were created.
|
Chris@0
|
49 $storage = $this->container->get('config.storage');
|
Chris@0
|
50 $this->assertTrue(count($storage->listAll('language.entity.')) > 0, 'Language config entity files exist.');
|
Chris@0
|
51 }
|
Chris@0
|
52
|
Chris@0
|
53 /**
|
Chris@0
|
54 * Attempts to enable a module with a missing dependency.
|
Chris@0
|
55 */
|
Chris@0
|
56 public function testMissingModules() {
|
Chris@0
|
57 // Test that the system_dependencies_test module is marked
|
Chris@0
|
58 // as missing a dependency.
|
Chris@0
|
59 $this->drupalGet('admin/modules');
|
Chris@0
|
60 $this->assertRaw(t('@module (<span class="admin-missing">missing</span>)', ['@module' => Unicode::ucfirst('_missing_dependency')]), 'A module with missing dependencies is marked as such.');
|
Chris@0
|
61 $checkbox = $this->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[system_dependencies_test][enable]"]');
|
Chris@0
|
62 $this->assert(count($checkbox) == 1, 'Checkbox for the module is disabled.');
|
Chris@0
|
63 }
|
Chris@0
|
64
|
Chris@0
|
65 /**
|
Chris@0
|
66 * Tests enabling a module that depends on an incompatible version of a module.
|
Chris@0
|
67 */
|
Chris@0
|
68 public function testIncompatibleModuleVersionDependency() {
|
Chris@0
|
69 // Test that the system_incompatible_module_version_dependencies_test is
|
Chris@0
|
70 // marked as having an incompatible dependency.
|
Chris@0
|
71 $this->drupalGet('admin/modules');
|
Chris@0
|
72 $this->assertRaw(t('@module (<span class="admin-missing">incompatible with</span> version @version)', [
|
Chris@0
|
73 '@module' => 'System incompatible module version test (>2.0)',
|
Chris@0
|
74 '@version' => '1.0',
|
Chris@0
|
75 ]), 'A module that depends on an incompatible version of a module is marked as such.');
|
Chris@0
|
76 $checkbox = $this->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[system_incompatible_module_version_dependencies_test][enable]"]');
|
Chris@0
|
77 $this->assert(count($checkbox) == 1, 'Checkbox for the module is disabled.');
|
Chris@0
|
78 }
|
Chris@0
|
79
|
Chris@0
|
80 /**
|
Chris@0
|
81 * Tests enabling a module that depends on a module with an incompatible core version.
|
Chris@0
|
82 */
|
Chris@0
|
83 public function testIncompatibleCoreVersionDependency() {
|
Chris@0
|
84 // Test that the system_incompatible_core_version_dependencies_test is
|
Chris@0
|
85 // marked as having an incompatible dependency.
|
Chris@0
|
86 $this->drupalGet('admin/modules');
|
Chris@0
|
87 $this->assertRaw(t('@module (<span class="admin-missing">incompatible with</span> this version of Drupal core)', [
|
Chris@0
|
88 '@module' => 'System incompatible core version test',
|
Chris@0
|
89 ]), 'A module that depends on a module with an incompatible core version is marked as such.');
|
Chris@0
|
90 $checkbox = $this->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[system_incompatible_core_version_dependencies_test][enable]"]');
|
Chris@0
|
91 $this->assert(count($checkbox) == 1, 'Checkbox for the module is disabled.');
|
Chris@0
|
92 }
|
Chris@0
|
93
|
Chris@0
|
94 /**
|
Chris@0
|
95 * Tests failing PHP version requirements.
|
Chris@0
|
96 */
|
Chris@0
|
97 public function testIncompatiblePhpVersionDependency() {
|
Chris@0
|
98 $this->drupalGet('admin/modules');
|
Chris@0
|
99 $this->assertRaw('This module requires PHP version 6502.* and is incompatible with PHP version ' . phpversion() . '.', 'User is informed when the PHP dependency requirement of a module is not met.');
|
Chris@0
|
100 $checkbox = $this->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[system_incompatible_php_version_test][enable]"]');
|
Chris@0
|
101 $this->assert(count($checkbox) == 1, 'Checkbox for the module is disabled.');
|
Chris@0
|
102 }
|
Chris@0
|
103
|
Chris@0
|
104 /**
|
Chris@0
|
105 * Tests enabling a module that depends on a module which fails hook_requirements().
|
Chris@0
|
106 */
|
Chris@0
|
107 public function testEnableRequirementsFailureDependency() {
|
Chris@0
|
108 \Drupal::service('module_installer')->install(['comment']);
|
Chris@0
|
109
|
Chris@0
|
110 $this->assertModules(['requirements1_test'], FALSE);
|
Chris@0
|
111 $this->assertModules(['requirements2_test'], FALSE);
|
Chris@0
|
112
|
Chris@0
|
113 // Attempt to install both modules at the same time.
|
Chris@0
|
114 $edit = [];
|
Chris@0
|
115 $edit['modules[requirements1_test][enable]'] = 'requirements1_test';
|
Chris@0
|
116 $edit['modules[requirements2_test][enable]'] = 'requirements2_test';
|
Chris@0
|
117 $this->drupalPostForm('admin/modules', $edit, t('Install'));
|
Chris@0
|
118
|
Chris@0
|
119 // Makes sure the modules were NOT installed.
|
Chris@0
|
120 $this->assertText(t('Requirements 1 Test failed requirements'), 'Modules status has been updated.');
|
Chris@0
|
121 $this->assertModules(['requirements1_test'], FALSE);
|
Chris@0
|
122 $this->assertModules(['requirements2_test'], FALSE);
|
Chris@0
|
123
|
Chris@0
|
124 // Makes sure that already enabled modules the failing modules depend on
|
Chris@0
|
125 // were not disabled.
|
Chris@0
|
126 $this->assertModules(['comment'], TRUE);
|
Chris@0
|
127 }
|
Chris@0
|
128
|
Chris@0
|
129 /**
|
Chris@0
|
130 * Tests that module dependencies are enabled in the correct order in the UI.
|
Chris@0
|
131 *
|
Chris@0
|
132 * Dependencies should be enabled before their dependents.
|
Chris@0
|
133 */
|
Chris@0
|
134 public function testModuleEnableOrder() {
|
Chris@0
|
135 \Drupal::service('module_installer')->install(['module_test'], FALSE);
|
Chris@0
|
136 $this->resetAll();
|
Chris@0
|
137 $this->assertModules(['module_test'], TRUE);
|
Chris@0
|
138 \Drupal::state()->set('module_test.dependency', 'dependency');
|
Chris@0
|
139 // module_test creates a dependency chain:
|
Chris@0
|
140 // - color depends on config
|
Chris@0
|
141 // - config depends on help
|
Chris@0
|
142 $expected_order = ['help', 'config', 'color'];
|
Chris@0
|
143
|
Chris@0
|
144 // Enable the modules through the UI, verifying that the dependency chain
|
Chris@0
|
145 // is correct.
|
Chris@0
|
146 $edit = [];
|
Chris@0
|
147 $edit['modules[color][enable]'] = 'color';
|
Chris@0
|
148 $this->drupalPostForm('admin/modules', $edit, t('Install'));
|
Chris@0
|
149 $this->assertModules(['color'], FALSE);
|
Chris@0
|
150 // Note that dependencies are sorted alphabetically in the confirmation
|
Chris@0
|
151 // message.
|
Chris@0
|
152 $this->assertText(t('You must enable the Configuration Manager, Help modules to install Color.'));
|
Chris@0
|
153
|
Chris@0
|
154 $edit['modules[config][enable]'] = 'config';
|
Chris@0
|
155 $edit['modules[help][enable]'] = 'help';
|
Chris@0
|
156 $this->drupalPostForm('admin/modules', $edit, t('Install'));
|
Chris@0
|
157 $this->assertModules(['color', 'config', 'help'], TRUE);
|
Chris@0
|
158
|
Chris@0
|
159 // Check the actual order which is saved by module_test_modules_enabled().
|
Chris@0
|
160 $module_order = \Drupal::state()->get('module_test.install_order') ?: [];
|
Chris@0
|
161 $this->assertIdentical($module_order, $expected_order);
|
Chris@0
|
162 }
|
Chris@0
|
163
|
Chris@0
|
164 /**
|
Chris@0
|
165 * Tests attempting to uninstall a module that has installed dependents.
|
Chris@0
|
166 */
|
Chris@0
|
167 public function testUninstallDependents() {
|
Chris@0
|
168 // Enable the forum module.
|
Chris@0
|
169 $edit = ['modules[forum][enable]' => 'forum'];
|
Chris@0
|
170 $this->drupalPostForm('admin/modules', $edit, t('Install'));
|
Chris@0
|
171 $this->drupalPostForm(NULL, [], t('Continue'));
|
Chris@0
|
172 $this->assertModules(['forum'], TRUE);
|
Chris@0
|
173
|
Chris@0
|
174 // Check that the comment module cannot be uninstalled.
|
Chris@0
|
175 $this->drupalGet('admin/modules/uninstall');
|
Chris@0
|
176 $checkbox = $this->xpath('//input[@type="checkbox" and @name="uninstall[comment]" and @disabled="disabled"]');
|
Chris@0
|
177 $this->assert(count($checkbox) == 1, 'Checkbox for uninstalling the comment module is disabled.');
|
Chris@0
|
178
|
Chris@0
|
179 // Delete any forum terms.
|
Chris@0
|
180 $vid = $this->config('forum.settings')->get('vocabulary');
|
Chris@0
|
181 // Ensure taxonomy has been loaded into the test-runner after forum was
|
Chris@0
|
182 // enabled.
|
Chris@0
|
183 \Drupal::moduleHandler()->load('taxonomy');
|
Chris@0
|
184 $terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vid]);
|
Chris@0
|
185 foreach ($terms as $term) {
|
Chris@0
|
186 $term->delete();
|
Chris@0
|
187 }
|
Chris@0
|
188 // Uninstall the forum module, and check that taxonomy now can also be
|
Chris@0
|
189 // uninstalled.
|
Chris@0
|
190 $edit = ['uninstall[forum]' => 'forum'];
|
Chris@0
|
191 $this->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
|
Chris@0
|
192 $this->drupalPostForm(NULL, NULL, t('Uninstall'));
|
Chris@0
|
193 $this->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.');
|
Chris@0
|
194
|
Chris@0
|
195 // Uninstall comment module.
|
Chris@0
|
196 $edit = ['uninstall[comment]' => 'comment'];
|
Chris@0
|
197 $this->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
|
Chris@0
|
198 $this->drupalPostForm(NULL, NULL, t('Uninstall'));
|
Chris@0
|
199 $this->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.');
|
Chris@0
|
200 }
|
Chris@0
|
201
|
Chris@0
|
202 }
|