Check your version

This video covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Alternate resources: 

Testing an Existing Site with SimpleTest 2.x

Video loading...

Transcript language code: 

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:03
    Testing an Existing Site with SimpleTest 2.x
  • 0:05
    with Joe Shindelar
  • 0:07
    All of the tests that we've written so far
  • 0:10
    are run in a clean environment.
  • 0:12
    A fresh install of Drupal gets created for each test run, in which
  • 0:16
    we are required to create all the users and the content
  • 0:18
    that we need in order to verify our application is working.
  • 0:22
    And this is great for testing things like the business
  • 0:25
    logic in our modules, and ensuring that all of our code
  • 0:28
    is functioning properly.

Testing an Existing Site with SimpleTest 2.x


So far all the tests that we've written are testing the functionality of our module in the context of a fresh Drupal install. However, in the real world we're also going to want to have tests that test the content of our application. As well as other things that it's unrealistic to assume we'll also have the time and resources to write a complete installation routine to replicate. Instead, it would be nice if we could test against a clone of our site rather than a from scratch installation of Drupal.

The SimpleTest module included with Drupal 7 core doesn't support this feature. However, the 7.x-2.x version of the module in contrib has a DrupalCloneTestCase class that we can extend instead of the usual DrupalWebTestCase that operates on a clone of the database from our existing site. Allowing us to test things like, "Does the about page exist.", and other mission critical features of our site. In this lesson we'll take a look at installing the SimpleTest module from contrib, and writing some new tests using the 2.x version of the API in order to test an existing website.

Note that after you install the 2.x version of the SimpleTest module none of the tests we've written so far, or any of the tests from core will be in the list of available tests to run. This is because each tests needs to explicitly declare that it is compatible with the 2.x version of the test suite. This is done in the .info file of the module that provides the tests.

Add this to your .info file:

testing_api = 2.x

As of the time that this video was recorded you also need to apply the patch in this SimpleTest issue. The current version of the patch to use is Without it the DrupalCloneTestCase setup method won't properly clone the tables from your existing site. You should always use whatever the latest working patch is from that issue.

Here's how I patched it:

curl -O
patch -p1 < 983266-10-simletest-clone.patch
Log in or sign up to download companion files.
Additional resources: 

SimpleTest 2.x module

Patched with patch from issue #983266