GHOP #110: Write Simpletest tests for admin/build/modules functionality
| Project: | SimpleTest |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
posting a GHOP task
| Project: | SimpleTest |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
posting a GHOP task
#1
task is here: http://code.google.com/p/google-highly-open-participation-drupal/issues/...
The main work for this task is to write a small suite of tests to check the
basic functionality at admin/build/modules. This suite should be written as
a single .test file.
Suggested tests:
1. Enable all core modules by POST - look for error messages, confirm table
creation, etc.
2. Attempt to enable a module with non-enabled dependencies, for example by
disabling comment and enabling forum. Use POST. Confirm expected error
message and that module is not enabled.
3. Disable and uninstall a module (such as aggregator) or better all
modules enabled in #1. Confirm table deletion, look for error messages, etc.
#2
OK, I'm attaching the .test file containing the 3 testcases.
I can't generate diffs to break the test at the moment, but I can suggest how to break the tests:
Test 1:
- http://api.drupal.org/api/function/system_modules_submit/6
Change
<?phpdrupal_set_message(t('The configuration options have been saved.'));
?>
to some other message.
- Comment out (same file)
<?phpdrupal_install_modules($new_modules);
?>
Test 2:
- http://api.drupal.org/api/function/system_modules_confirm_form/6
Change the second parameter of confirm_form in the following block of code.
<?phpif ($form) {
// Set some default form values
$form = confirm_form(
$form,
t('Some required modules must be enabled'),
'admin/build/modules',
t('Would you like to continue with enabling the above?'),
t('Continue'),
t('Cancel'));
return $form;
}
?>
- Before that block of code, set $form to false
- http://api.drupal.org/api/function/system_modules_submit/6
Remove the return from
<?php// If there where unmet dependencies and they haven't confirmed don't process
// the submission yet. Store the form submission data needed later.
if ($dependencies) {
if (!isset($form_state['values']['confirm'])) {
$form_state['storage'] = array($dependencies, $form_state['values']['status']);
return;
?>
Test 3:
- http://api.drupal.org/api/function/system_modules_submit/6
Change
<?phpdrupal_set_message(t('The configuration options have been saved.'));
?>
to some other message.
- Break/remove the uninstall hook for a module so that tables are not removed properly
- http://api.drupal.org/api/function/system_modules_uninstall_submit/6
Change
<?phpdrupal_set_message(t('The selected modules have been uninstalled.'));
?>
#3
#4
Looks like a good start - a few suggestions:
First off, for a more robust test, you should make sure that at least one of the modules that is to be enabled is not already enabled. If they are all enabled, you might directly disable a couple before starting the test (try using
$this->drupalModuleDisable();)To check that the modules are enabled, you should instead (or in addition) check the system table. Not all modules create tables - and if the module was previously enabled the table would already exist.
After posting to disable the modules, check the system table again to make sure the module is disabled.
Also, it would be simpler to use code like:
$this->assertTrue(db_table_exists($table));$this->assertFalse(db_table_exists($table));
rather than:
$this->assertEqual(db_table_exists($table), true);I don't think tests usually implement
function tearDown(), and since you don't add any code, you can just omit them.#5
Thanks :)
I'm attaching a revised set of tests that incorporates your comments.
#6
code style: all indents should be 2 spaces
also, each assertion should have an informative message like:
$this->assertTrue($node->status == '1', t('Check to make sure the node is automatically published'));#7
Fair enough, I'll get right on it :)
#8
And revised. :)
#9
I guess I should set this as well (it was set automatically before, how odd) :)
#10
Smartys, great work. A few comments: string concat code style, there is always a space on both sides of a dot but there is no space between a quote (single or double) and a dot. So
$edit['status['. $module .']'you lack 1-1 space. I would run coder module over this just to make sure there are no more code style violations. HEAD of coder works w/ D6.#11
Thanks a lot. :)
I just checked out the coder module from CVS and ran it (I had to move the .test file into the simpletest folder and give it a .php extension), but it didn't find any mistakes. I've made your changes though and the fixed version is attached.
#12
#13
@Smartys - please post the final version to the GHOP issue
#14
It would be my pleasure :)
#15
Committed.
#16
Automatically closed -- issue fixed for two weeks with no activity.