Line # | Frequency | Source Line |
1 | | <?php
|
2 | | // $Id: system.test,v 1.9 2008/04/01 23:33:54 boombatower Exp $
|
3 | |
|
4 | | class EnableCoreModuleTestCase extends DrupalTestCase {
|
5 | | /**
|
6 | | * Implementation of getInfo() for information
|
7 | | */
|
8 | | function getInfo() {
|
9 | 1 | return array('name' => t('Enable core modules'), 'description' => 'Enables all core modules by POST - looks for error messages, confirms table creation, etc.', 'group' => 'Modules');
|
10 | | }
|
11 | |
|
12 | | function testEnableCoreModules () {
|
13 | | // Get a list of the modules to enable
|
14 | | $modules_to_enable = array (
|
15 | | 'aggregator',
|
16 | | 'blog',
|
17 | | 'blogapi',
|
18 | | 'book',
|
19 | | 'color',
|
20 | | 'comment',
|
21 | | 'contact',
|
22 | | 'dblog',
|
23 | | 'forum',
|
24 | | 'help',
|
25 | | 'locale',
|
26 | | 'menu',
|
27 | | 'openid',
|
28 | | 'path',
|
29 | | 'php',
|
30 | | 'ping',
|
31 | | 'poll',
|
32 | | 'profile',
|
33 | | 'search',
|
34 | | 'statistics',
|
35 | | 'syslog',
|
36 | | 'taxonomy',
|
37 | | 'throttle',
|
38 | | 'tracker',
|
39 | | 'translation',
|
40 | | 'trigger',
|
41 | | 'update',
|
42 | | 'upload',
|
43 | | );
|
44 | |
|
45 | | // Get a list of the currently enabled modules
|
46 | | $enabled_modules = module_list(true, false);
|
47 | |
|
48 | | $web_user = $this->drupalCreateUser(array (
|
49 | | 'access administration pages',
|
50 | | 'administer site configuration',
|
51 | | ));
|
52 | | $this->drupalLogin($web_user);
|
53 | |
|
54 | | $edit = array();
|
55 | | // We temporarily disable any modules we're testing so that we can re-enable them for testing
|
56 | | foreach ($modules_to_enable as $module) {
|
57 | | if (module_exists($module))
|
58 | | $this->drupalModuleDisable($module);
|
59 | |
|
60 | | $edit['status['. $module .']'] = $module;
|
61 | | }
|
62 | |
|
63 | | $this->drupalPost('admin/build/modules/list/confirm', $edit, t('Save configuration'));
|
64 | | $this->assertRaw(t('The configuration options have been saved.'), t('Ensure that the module status has been updated'));
|
65 | |
|
66 | | // Now, we check the tables for each module
|
67 | | // We also refresh the module list and make sure the modules are enabled
|
68 | | module_list(true, false);
|
69 | | foreach ($modules_to_enable as $module) {
|
70 | | $cur_schema = drupal_get_schema_unprocessed($module);
|
71 | |
|
72 | | $tables = is_array($cur_schema) ? array_keys($cur_schema) : array();
|
73 | | foreach ($tables as $table)
|
74 | | $this->assertTrue(db_table_exists($table), t('Make sure that the database table for the module exists'));
|
75 | |
|
76 | | $this->assertTrue(module_exists($module), t('Check to see that the module is actually enabled'));
|
77 | | }
|
78 | |
|
79 | | // Disable/uninstall all the modules that have been installed by this process
|
80 | | // We first need to refresh the module list
|
81 | | include_once './includes/install.inc';
|
82 | |
|
83 | | foreach ($modules_to_enable as $module) {
|
84 | | // We uninstall the modules that weren't already enabled
|
85 | | if (!in_array($module, $enabled_modules)) {
|
86 | | module_disable(array($module));
|
87 | | drupal_uninstall_module($module);
|
88 | | }
|
89 | | }
|
90 | |
|
91 | | drupal_clear_css_cache();
|
92 | | drupal_clear_js_cache();
|
93 | | }
|
94 | | }
|
95 | |
|
96 | | class EnableModuleWithoutDependencyTestCase extends DrupalTestCase {
|
97 | | /**
|
98 | | * Implementation of getInfo() for information
|
99 | | */
|
100 | | function getInfo() {
|
101 | 1 | return array('name' => t('Enable module without required dependencies'), 'description' => 'Attempts to enable the forum module without enabling dependencies.', 'group' => 'Modules');
|
102 | | }
|
103 | |
|
104 | | function testEnableWithoutDependency () {
|
105 | | // Disable all modules for this test
|
106 | | $current_modules = module_list(true, false);
|
107 | | foreach ($current_modules as $module) {
|
108 | | // We don't disable core modules
|
109 | | if (!in_array($module, drupal_required_modules()))
|
110 | | $this->drupalModuleDisable($module);
|
111 | | }
|
112 | |
|
113 | | // Attempt to enable forum module, which should fail because comment and taxonomy are not enabled
|
114 | | $web_user = $this->drupalCreateUser(array (
|
115 | | 'access administration pages',
|
116 | | 'administer site configuration',
|
117 | | ));
|
118 | | $this->drupalLogin($web_user);
|
119 | |
|
120 | | $edit = array (
|
121 | | 'status[forum]' => 'forum',
|
122 | | );
|
123 | |
|
124 | | $this->drupalPost('admin/build/modules/list/confirm', $edit, t('Save configuration'));
|
125 | | $this->assertRaw(t('Some required modules must be enabled'), t('Make sure the dependency error is shown'));
|
126 | |
|
127 | | $this->assertFalse(module_exists('forum'), t('Check to make sure that the module has not somehow become enabled'));
|
128 | | }
|
129 | | }
|
130 | |
|
131 | | class DisableUninstallCoreModuleTestCase extends DrupalTestCase {
|
132 | | /**
|
133 | | * Implementation of getInfo() for information
|
134 | | */
|
135 | | function getInfo() {
|
136 | 1 | return array('name' => t('Disable/uninstall core modules'), 'description' => 'Disables and uninstalls core modules, ensures that that tables are properly deleted, no error messages are shown, etc.', 'group' => 'Modules');
|
137 | | }
|
138 | |
|
139 | | function testDisableUninstallCoreModules () {
|
140 | | // Get a list of the modules to test
|
141 | | $modules_to_test = array (
|
142 | | 'aggregator',
|
143 | | 'blog',
|
144 | | 'blogapi',
|
145 | | 'book',
|
146 | | 'color',
|
147 | | 'comment',
|
148 | | 'contact',
|
149 | | 'dblog',
|
150 | | 'forum',
|
151 | | 'help',
|
152 | | 'locale',
|
153 | | 'menu',
|
154 | | 'openid',
|
155 | | 'path',
|
156 | | 'php',
|
157 | | 'ping',
|
158 | | 'poll',
|
159 | | 'profile',
|
160 | | 'search',
|
161 | | 'statistics',
|
162 | | 'syslog',
|
163 | | 'taxonomy',
|
164 | | 'throttle',
|
165 | | 'tracker',
|
166 | | 'translation',
|
167 | | 'trigger',
|
168 | | 'update',
|
169 | | 'upload',
|
170 | | );
|
171 | |
|
172 | | // Get a list of the currently enabled modules
|
173 | | $enabled_modules = module_list(true, false);
|
174 | |
|
175 | | // We don't want to test any modules that are already enabled, since that would involve a loss of data
|
176 | | foreach ($enabled_modules as $module) {
|
177 | | if (in_array($module, $modules_to_test))
|
178 | | unset($modules_to_test[array_search($module, $modules_to_test)]);
|
179 | | }
|
180 | |
|
181 | | // Enable all the modules that are not already enabled
|
182 | | include_once './includes/install.inc';
|
183 | | module_enable($modules_to_test);
|
184 | | drupal_install_modules($modules_to_test);
|
185 | |
|
186 | | $web_user = $this->drupalCreateUser(array (
|
187 | | 'access administration pages',
|
188 | | 'administer site configuration',
|
189 | | ));
|
190 | | $this->drupalLogin($web_user);
|
191 | |
|
192 | | // Disable/uninstall the given modules: we keep every other module enabled
|
193 | | // We do this loop because for each level of dependency, we need one more request
|
194 | | while (count(array_diff(module_list(true, false), $enabled_modules)) > 0) {
|
195 | | $edit = array();
|
196 | | foreach ($modules_to_test as $module) {
|
197 | | $edit['status['. $module .']'] = 0;
|
198 | | }
|
199 | | foreach ($enabled_modules as $module) {
|
200 | | $edit['status['. $module .']'] = $module;
|
201 | | }
|
202 | |
|
203 | | $this->drupalPost('admin/build/modules/list/confirm', $edit, t('Save configuration'));
|
204 | | $this->assertRaw(t('The configuration options have been saved.'), t('Ensure that the module status has been updated'));
|
205 | | }
|
206 | |
|
207 | | // Now, lets make sure the modules are truly disabled and then try to uninstall them
|
208 | | module_list(true, false);
|
209 | | $edit = array();
|
210 | | foreach ($modules_to_test as $module) {
|
211 | | $this->assertFalse(module_exists($module), t('Make sure the module has been disabled'));
|
212 | |
|
213 | | if (module_hook($module, 'uninstall'))
|
214 | | $edit['uninstall['. $module .']'] = $module;
|
215 | | }
|
216 | |
|
217 | | $this->drupalPost('admin/build/modules/uninstall/confirm', $edit, t('Uninstall'));
|
218 | | // We need to confirm this by clicking again
|
219 | | $this->drupalPost(NULL, array(), t('Uninstall'));
|
220 | | $this->assertRaw(t('The selected modules have been uninstalled.'), 'Check to ensure that the modules have been removed');
|
221 | |
|
222 | | // Now, we check the tables for each module
|
223 | | foreach ($modules_to_test as $module) {
|
224 | | $cur_schema = drupal_get_schema_unprocessed($module);
|
225 | |
|
226 | | $tables = is_array($cur_schema) ? array_keys($cur_schema) : array();
|
227 | | foreach ($tables as $table)
|
228 | | $this->assertFalse(db_table_exists($table), t('Ensure that the database table has been properly removed'));
|
229 | | }
|
230 | |
|
231 | | drupal_clear_css_cache();
|
232 | | drupal_clear_js_cache();
|
233 | | }
|
234 | | }
|