posting a GHOP task

Comments

pwolanin’s picture

Title: GHOP: Write Simpletest tests for admin/build/modules functionality » GHOP #110: Write Simpletest tests for admin/build/modules functionality

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.

Smartys-1’s picture

StatusFileSize
new6.46 KB

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

drupal_set_message(t('The configuration options have been saved.'));

to some other message.
- Comment out (same file)

drupal_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.

  if ($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

  // 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

drupal_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
drupal_set_message(t('The selected modules have been uninstalled.'));

pwolanin’s picture

Status: Active » Needs review
pwolanin’s picture

Status: Needs review » Needs work

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.

Smartys-1’s picture

Status: Needs work » Needs review
StatusFileSize
new6.75 KB

Thanks :)
I'm attaching a revised set of tests that incorporates your comments.

pwolanin’s picture

Status: Needs review » Needs work

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'));
Smartys-1’s picture

Fair enough, I'll get right on it :)

Smartys-1’s picture

StatusFileSize
new7.54 KB

And revised. :)

Smartys-1’s picture

Status: Needs work » Needs review

I guess I should set this as well (it was set automatically before, how odd) :)

chx’s picture

Status: Needs review » Needs work

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.

Smartys-1’s picture

Status: Needs work » Needs review
StatusFileSize
new7.55 KB

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.

chx’s picture

Status: Needs review » Reviewed & tested by the community
pwolanin’s picture

@Smartys - please post the final version to the GHOP issue

Smartys-1’s picture

It would be my pleasure :)

Rok Žlender’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.