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?
- In the process of modules/themes development, testing plays a vital role.
- It ensures that the modules/themes works as expected without any flawl.
Steps for testing Drupal module/theme:
- Create a file and name it as
my_module.test/my_theme.test
. - Write the appropriate test cases with good documentation for each class or function as per Drupal’s coding standards.
- Go to the Drupal Admin Panel
- Enable the Simpletesting module (Simpletesting module is Drupal’s core module for testing purpose.)
- Now you can run your test cases.
- To run your tests.
- Either you can run your test using the Drupal Admin Panel or your CLI (terminal/command prompt).
- To run your tests using admin panel
- Navigate to Drupal Admin Panel » Configuration » Testing
- There you can select your module/theme and click on Run tests button.
- To run your tests using CLI (terminal/command prompts)
- Open your CLI
- Install drush.
- Installing Drush For Linux:
- Check if PEAR is on the server with
pear version
. - If PEAR is not on the server then type in
- Debian based:
sudo apt-get install php-pear
. - RedHat based:
sudo yum install pear
. - SUSE based:
sudo zypper install php5-pear
.
- Check if PEAR is on the server with
- Then type in
pear channel-discover pear.drush.org
. - And finally
pear install drush/drush-version
(eg: pear install drush/drush-5.7.0). - If something goes wrong you can uninstall drush with
pear uninstall drush/drush
. - For CentOS
- Check if PEAR is on the server with
pear version
. - If PEAR is not on the server then type in
yum install php-pear
. - Then type in
pear channel-discover pear.drush.org
. - And finally
pear install drush/drush
.
- Check if PEAR is on the server with
- Now to run your test cases type in
drush test-run My_Module
and see the output.