GHOP #152: write SimpleTests for filter module

pwolanin - January 16, 2008 - 13:22
Project:SimpleTest
Version:6.x-1.x-dev
Component:Code
Category:task
Priority:normal
Assigned:boombatower
Status:closed
Description

This unfortunate SNAFU: http://drupal.org/node/208700 demonstrates again the need for unit tests for the filter module.

Deliverables:

Your overall task will be to create a set of tests that thoroughly tests the administrative interface of the filter module. This suite should be written as a single .test file and should achieve RTBC status.

Suggested tests/components to be written for this task:

1. Save all the original settings (e.g. you might even rename and duplicate the table) so you can revert to them.
2. admin/settings/filters change the default filter by POST. Check that the new default shows up and cannot be deleted.
3.admin/settings/filters/1/configure Add an additional tag, check that is shows up, and check that the filter cache is cleared
4 admin/settings/filters/1/order reorder the input formats by POST, and check that the changes are saved.
5. settings/filters/add add a new input format by POST and check that it is saved and has all selected options
6.settings/filters/delete/x check that the newly added format can be deleted
7. admin/settings/filters/2 allow authenticated users, log in as a normal user and check access to the filter.

Note, you can assume the default filtered and full HTML filters are 1 and 2 (though bonus points for checking or making it so). Revert to the original filters when you are done.

Your test should either work for Drupal 5.x as well as 6.x, or provide both 5.x and 6.x versions.

Note each of these 3 tests should include at least 3 to 8 assertions that are checked. Proper validation of your new tests will ideally include changing the Drupal core code to break the tested functionality and then confirming that your tests report a failure. Ideally, post each such change as a patch to help the reviewers.

#1

pwolanin - January 16, 2008 - 14:06
Title:GHOP : write SimpleTests for filter module» GHOP #152: write SimpleTests for filter module

GHOP issue: http://code.google.com/p/google-highly-open-participation-drupal/issues/...

#2

boombatower - January 19, 2008 - 19:42
Status:active» patch (code needs review)

I got the 6.x test working fine, but 5.x doesn't want to work.

It doesn't seem like logout works, or that drupalGet correctly...I'm not exactly sure.

So i'm not sure what exactly to do with the 5.x test.

AttachmentSize
filter_module5x.test_.txt6.28 KB
filter_module6x.test_.txt5.84 KB

#3

boombatower - January 20, 2008 - 03:45

I think I figured the stuff out. This test should work for both 6.x and 5.x

AttachmentSize
filter_module.test_.txt6.73 KB

#4

boombatower - January 20, 2008 - 17:52

Removed enabling of filter since it must be enabled for Drupal to run.

AttachmentSize
filter_module.test_.txt6.69 KB

#5

boombatower - January 20, 2008 - 20:18

Changes requested by pwolanin in IRC:

  • Order actually confirmed
  • URL filter check wasn't correct
AttachmentSize
filter_module.test_.txt7.29 KB

#6

pwolanin - January 20, 2008 - 21:26
Status:patch (code needs review)» patch (code needs work)

code style problems - use {} with all if/else statements. For example:

      if ($filter->delta == $second_filter || $filter->delta == $first_filter)
        $filters[] = $filter;

needs to be:

      if ($filter->delta == $second_filter || $filter->delta == $first_filter) {
        $filters[] = $filter;
      }

#7

boombatower - January 20, 2008 - 22:35
Status:patch (code needs work)» patch (code needs review)

This should do it.

AttachmentSize
filter_module.test_.txt7.3 KB

#8

boombatower - January 21, 2008 - 01:19

I made the following changes after talking with chx in IRC:

  • Cleaned up a few coding guideline issues
  • Clean up some code
  • Added test to make sure filter removes unwanted tags
  • Made a patch for 5.x simpletest framework to remove need to different url standard
AttachmentSize
drupal_test_case.diff327 bytes
filter_module.test_.txt7.71 KB

#9

chx - January 21, 2008 - 01:42

Note that the patch for D5 simpletest is submtited reversed. It also could use a $query = NULL parameter.

#10

boombatower - January 21, 2008 - 01:49

Here is the updated diff.

AttachmentSize
drupal_test_case.diff411 bytes

#11

Gribnif - March 7, 2008 - 19:41

This is a version of the tests, updated to work with HEAD. It accounts for the name change in the drupalPostRequest function, and changes in the submit button text. More unit tests to follow.

AttachmentSize
filter_module.test_.txt7.71 KB

#12

boombatower - March 15, 2008 - 22:24
Status:patch (code needs review)» fixed

Committed.

In future this test will probably be made HEAD specific, removing all 5.x stuff.

@Gribnif: Thanks for updating test.

#13

boombatower - March 15, 2008 - 22:25
Assigned to:Anonymous» boombatower

Double post.

#14

Anonymous (not verified) - March 29, 2008 - 22:32
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.