Drupal modules

A quick start to Drupal Testing for modules/themes

Drupal can be extended by composing your own module as per the needs.Before taking you through the practical guide I will be giving you a lime light of what a module is?

What is a Drupal Module?

A set of files with some special features and functionalities makes a module. The purpose behind this is to extend drupal.Before its approval it gets executed through hooks which are well defined interfaces. The modules written in PHP must be according to the code/functionality of the hook so that it can be invoked through Drupal Framework/Engine.

Why testing of Modules/Themes is important?

  1. In the process of modules/themes development, testing plays a vital role.
  2. It ensures that the modules/themes works as expected without any flawl.

Steps for testing Drupal module/theme:

  1. Create a file and name it as my_module.test/my_theme.test.
  2. Write the appropriate test cases with good documentation for each class or function as per Drupal’s coding standards.
  3. Go to the Drupal Admin Panel
  4. Enable the Simpletesting module (Simpletesting module is Drupal’s core module for testing purpose.)
  5. Now you can run your test cases.
  6. To run your tests.
    1. Either you can run your test using the Drupal Admin Panel or your CLI (terminal/command prompt).
    2. To run your tests using admin panel
      1. Navigate to Drupal Admin Panel » Configuration » Testing
      2. There you can select your module/theme and click on Run tests button.
    3. To run your tests using CLI (terminal/command prompts)
      1. Open your CLI
      2. Install drush.
      3. Installing Drush For Linux:
        1. Check if PEAR is on the server with pear version.
        2. If PEAR is not on the server then type in
        3. Debian based: sudo apt-get install php-pear.
        4. RedHat based: sudo yum install pear.
        5. SUSE based: sudo zypper install php5-pear.
      4. Then type in pear channel-discover
      5. And finally pear install drush/drush-version (eg: pear install drush/drush-5.7.0).
      6. If something goes wrong you can uninstall drush with pear uninstall drush/drush.
      7. For CentOS
        1. Check if PEAR is on the server with pear version.
        2. If PEAR is not on the server then type in yum install php-pear.
        3. Then type in pear channel-discover
        4. And finally pear install drush/drush.
    4. Now to run your test cases type in drush test-run My_Module and see the output.

Happy Coding!