3 namespace Drupal\Tests\system\Functional\Module;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests the installation of modules.
12 class ExperimentalModuleTest extends BrowserTestBase {
18 * @var \Drupal\user\UserInterface
25 protected function setUp() {
27 $this->adminUser = $this->drupalCreateUser(['access administration pages', 'administer modules']);
28 $this->drupalLogin($this->adminUser);
32 * Tests installing experimental modules and dependencies in the UI.
34 public function testExperimentalConfirmForm() {
36 // First, test installing a non-experimental module with no dependencies.
37 // There should be no confirmation form and no experimental module warning.
39 $edit["modules[test_page_test][enable]"] = TRUE;
40 $this->drupalPostForm('admin/modules', $edit, t('Install'));
41 $this->assertText('Module Test page has been enabled.');
42 $this->assertNoText('Experimental modules are provided for testing purposes only.');
44 // Uninstall the module.
45 \Drupal::service('module_installer')->uninstall(['test_page_test']);
47 // Next, test installing an experimental module with no dependencies.
48 // There should be a confirmation form with an experimental warning, but no
49 // list of dependencies.
51 $edit["modules[experimental_module_test][enable]"] = TRUE;
52 $this->drupalPostForm('admin/modules', $edit, 'Install');
54 // The module should not be enabled and there should be a warning and a
55 // list of the experimental modules with only this one.
56 $this->assertNoText('Experimental Test has been enabled.');
57 $this->assertText('Experimental modules are provided for testing purposes only.');
58 $this->assertText('The following modules are experimental: Experimental Test');
60 // There should be no message about enabling dependencies.
61 $this->assertNoText('You must enable');
63 // Enable the module and confirm that it worked.
64 $this->drupalPostForm(NULL, [], 'Continue');
65 $this->assertText('Experimental Test has been enabled.');
67 // Uninstall the module.
68 \Drupal::service('module_installer')->uninstall(['experimental_module_test']);
70 // Test enabling a module that is not itself experimental, but that depends
71 // on an experimental module.
73 $edit["modules[experimental_module_dependency_test][enable]"] = TRUE;
74 $this->drupalPostForm('admin/modules', $edit, 'Install');
76 // The module should not be enabled and there should be a warning and a
77 // list of the experimental modules with only this one.
78 $this->assertNoText('2 modules have been enabled: Experimental Dependency Test, Experimental Test');
79 $this->assertText('Experimental modules are provided for testing purposes only.');
81 $this->assertText('The following modules are experimental: Experimental Test');
83 // Ensure the non-experimental module is not listed as experimental.
84 $this->assertNoText('The following modules are experimental: Experimental Test, Experimental Dependency Test');
85 $this->assertNoText('The following modules are experimental: Experimental Dependency Test');
87 // There should be a message about enabling dependencies.
88 $this->assertText('You must enable the Experimental Test module to install Experimental Dependency Test');
90 // Enable the module and confirm that it worked.
91 $this->drupalPostForm(NULL, [], 'Continue');
92 $this->assertText('2 modules have been enabled: Experimental Dependency Test, Experimental Test');
94 // Uninstall the modules.
95 \Drupal::service('module_installer')->uninstall(['experimental_module_test', 'experimental_module_dependency_test']);
97 // Finally, check both the module and its experimental dependency. There is
98 // still a warning about experimental modules, but no message about
99 // dependencies, since the user specifically enabled the dependency.
101 $edit["modules[experimental_module_test][enable]"] = TRUE;
102 $edit["modules[experimental_module_dependency_test][enable]"] = TRUE;
103 $this->drupalPostForm('admin/modules', $edit, 'Install');
105 // The module should not be enabled and there should be a warning and a
106 // list of the experimental modules with only this one.
107 $this->assertNoText('2 modules have been enabled: Experimental Dependency Test, Experimental Test');
108 $this->assertText('Experimental modules are provided for testing purposes only.');
110 $this->assertText('The following modules are experimental: Experimental Test');
112 // Ensure the non-experimental module is not listed as experimental.
113 $this->assertNoText('The following modules are experimental: Experimental Dependency Test, Experimental Test');
114 $this->assertNoText('The following modules are experimental: Experimental Dependency Test');
116 // There should be no message about enabling dependencies.
117 $this->assertNoText('You must enable');
119 // Enable the module and confirm that it worked.
120 $this->drupalPostForm(NULL, [], 'Continue');
121 $this->assertText('2 modules have been enabled: Experimental Dependency Test, Experimental Test');
123 // Try to enable an experimental module that can not be due to
124 // hook_requirements().
125 \Drupal::state()->set('experimental_module_requirements_test_requirements', TRUE);
127 $edit["modules[experimental_module_requirements_test][enable]"] = TRUE;
128 $this->drupalPostForm('admin/modules', $edit, 'Install');
129 $this->assertUrl('admin/modules', [], 'If the module can not be installed we are not taken to the confirm form.');
130 $this->assertText('The Experimental Test Requirements module can not be installed.');