Friday, January 16, 2009

Simple Test Module - Drupal

Drupal is currently lacking a test suite to be run by developers before submitting important patches. The simpletest module shows some great promise but it is unfortunately not widely adopted yet and there aren't many tests written. See here for a tutorial on how to write tests for your module.

The following setup isn't really a test suite but it is a start to avoid the most embarrassing errors.

Proceed as follows:

1. Enable the menu module and disable the 'log out' link.
2. If you have the image module installed, enable the image module and set permissions so images can be written for the userid running the link check. This will avoid image creation errors when crawling with image enabled.
3. Run
wget --mirror --delete-after http://example.com/

where example.com is your development site. This command will crawl your site very quickly which can put a large stress on the site. You can add --wait=5 to the options if you don't want to perform the stress test.
4. If you want to test as an authenticated user you first should login to the site using a browser and get the authenticated cookie. Then do
wget --mirror --delete-after --load-cookies=/path/to/cookies.txt http://example.com/

where /path/to/cookies.txt is the cookie for your site inside your cookie directory. The exact location of this cookie depends on which browser you are using.
5. You can repeat for each of your roles on your site, and look for errors users with different roles might experience.

Note that this can take some time. wget will access every Drupal page linked from anywhere on your site. You can later have a look at the error logs and find out if any errors where caused. This will not test submitting forms. You can test submitting forms through simple test module.

No comments: