Sample Hello World Module

Categories

Component ID

2859778

Component name

Sample Hello World Module

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Component created

Component changed

Component body

Here, I've managed to create a Hello World Page Module in D7 and also write a test involving some of the fundamental concepts necessary for writing tests for Drupal with SimpleTest.

The process involved defining our HelloworldTests class in a .test file and making sure Drupal can find it by adding it to our module's .info file. Then provided meta-data about the tests for the SimpleTest UI, and any setup instructions necessary so that the environment in which our tests run is appropriate for our test case. Finally, wrote a test*() method that used the internal SimpleTest browser to navigate to a page and verify that a string of text is present on that page.

This Hello World Page Module focused on the following specifics:

  • Create a new PHP class that defines a test
  • Provide Drupal with meta-data about your test
  • Run your test to see if it works

This module was just an experiment in D7 using SimpleTest functionality. However, creating this same module in D8 would be much simpler, owing to it's Object Oriented Structure.