Version 1
[yaffs-website] / web / core / modules / system / tests / src / Functional / Module / ExperimentalModuleTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Module;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests the installation of modules.
9  *
10  * @group Module
11  */
12 class ExperimentalModuleTest extends BrowserTestBase {
13
14
15   /**
16    * The admin user.
17    *
18    * @var \Drupal\user\UserInterface
19    */
20   protected $adminUser;
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function setUp() {
26     parent::setUp();
27     $this->adminUser = $this->drupalCreateUser(['access administration pages', 'administer modules']);
28     $this->drupalLogin($this->adminUser);
29   }
30
31   /**
32    * Tests installing experimental modules and dependencies in the UI.
33    */
34   public function testExperimentalConfirmForm() {
35
36     // First, test installing a non-experimental module with no dependencies.
37     // There should be no confirmation form and no experimental module warning.
38     $edit = [];
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.');
43
44     // Uninstall the module.
45     \Drupal::service('module_installer')->uninstall(['test_page_test']);
46
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.
50     $edit = [];
51     $edit["modules[experimental_module_test][enable]"] = TRUE;
52     $this->drupalPostForm('admin/modules', $edit, 'Install');
53
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');
59
60     // There should be no message about enabling dependencies.
61     $this->assertNoText('You must enable');
62
63     // Enable the module and confirm that it worked.
64     $this->drupalPostForm(NULL, [], 'Continue');
65     $this->assertText('Experimental Test has been enabled.');
66
67     // Uninstall the module.
68     \Drupal::service('module_installer')->uninstall(['experimental_module_test']);
69
70     // Test enabling a module that is not itself experimental, but that depends
71     // on an experimental module.
72     $edit = [];
73     $edit["modules[experimental_module_dependency_test][enable]"] = TRUE;
74     $this->drupalPostForm('admin/modules', $edit, 'Install');
75
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.');
80
81     $this->assertText('The following modules are experimental: Experimental Test');
82
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');
86
87     // There should be a message about enabling dependencies.
88     $this->assertText('You must enable the Experimental Test module to install Experimental Dependency Test');
89
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');
93
94     // Uninstall the modules.
95     \Drupal::service('module_installer')->uninstall(['experimental_module_test', 'experimental_module_dependency_test']);
96
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.
100     $edit = [];
101     $edit["modules[experimental_module_test][enable]"] = TRUE;
102     $edit["modules[experimental_module_dependency_test][enable]"] = TRUE;
103     $this->drupalPostForm('admin/modules', $edit, 'Install');
104
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.');
109
110     $this->assertText('The following modules are experimental: Experimental Test');
111
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');
115
116     // There should be no message about enabling dependencies.
117     $this->assertNoText('You must enable');
118
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');
122
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);
126     $edit = [];
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.');
131   }
132
133 }