Last updated November 25, 2013.

On this page:

To get help completing this task, see the Getting help completing your task page.

Goal

Create a patch (software fix) for an automated test to detect a Drupal core bug.

Skills needed

PHP programming skills

Detailed steps

  1. If you don't have a Drupal site to test on, set up a local server. You probably do not want to use a live, production web site for this task.
  2. Install Git on your computer, if it is not already installed. See the installing git page for more information.
  3. Find issues for Drupal core.
  4. Use the advanced search to find an issue tagged with Needs tests.
  5. Make sure you can reproduce the bug on your test site. (If the steps to reproduce the issue are unclear, you can document them or add a comment asking for clarification. If you cannot figure out how to reproduce the bug, choose a different issue.)
  6. Your task now is to create an automated test that follows the steps to reproduce the issue and asserts the expected result. The test should fail when the bug is present and pass once the bug is fixed.
  7. Determine which file should contain the automated test.
    • If the bug is related to a specific core module, the test should be added to:
      • for Drupal 7.x: modules/modulename/modulename.test.
      • for Drupal 8.x: core/modules/modulename/lib/Drupal/modulename/Tests/.
      • for Drupal 8.x: read more about phpunit tests.
    • If the bug is related to a core subsystem (such as the menu system), look for an appropriate file in the appropriate directory.
      • for Drupal 7.x: modules/simpletest/tests/
      • for Drupal 8.x: core/modules/system/lib/Drupal/system/Tests/
  8. Look at the different test case classes in that file and determine if one is a good fit for your test.
    • In Drupal 7, the test should extend DrupalWebTestCase. In Drupal 8, the test should extend Drupal\simpletest\WebTestBase. (Note that many modules have a base helper test class; if so, the test should probably extend that class instead.)
    • Consider the class's name, description, and setUp() method. If there is no class that is a good fit, add a new class for your test at the end of the file. (For more information, see the SimpleTest documentation.)
  9. Add a test method to the class for your automated test. (In some cases, you may be able to extend an existing test method.)
    • In Drupal 7:
    • In Drupal 8:
    • In some cases, you may need to create or extend a hidden test module or theme for your test to install and use.
    • Other test methods in the same file may provide useful examples.
  10. Clear your site cache and run your test to verify that it reproduces the bug (failing the expected assertions when the bug is unpatched).
  11. Create a patch that contains your test code.
  12. If there is already a patch to fix the bug, apply that patch to your test site along with your automated test, clear the cache, and run the test again. The test should now pass. Create a second patch that contains your test code together with the fix.
  13. Create a new comment on the issue and upload your patch as an attachment. If you also created a patch containing a fix for the bug, upload the test-only patch as the first attachment and the combined test & fix patch as the second. Set the issue status to "Needs Review" so that the patches are automatically tested by the Drupal.org testbots.

comment_attachments_tests.png

Background and reference information

Next steps: moving beyond this task

AttachmentSize
comment_attachments_tests.png12.02 KB