Advertising sustains the DA. Ads are hidden for members. Join today
On this page
Automated testing for Drupal 7
- Testing overview
- Testing module
- Testing tutorial
- Unit Testing with SimpleTest
- Organizing your test cases
- Selenium testing
- Testing setup and configuration
- Writing upgrade path tests
- Run tests
- Running tests through command-line
- Troubleshooting tests
- SimpleTest upload tests hanging
- SimpleTest [Browser] on Vista
- Improving SimpleTest performance
- Testing Reference
- API functions
- Assertions
- Why test
- Core tests
- Hidden modules and themes
- Comprehensive example
- Miscellaneous SimpleTest tips
Writing SimpleTest assertions
Last updated on
26 July 2020
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
Up to date documentation or additions may be found at the api.drupal.org reference site (not necessarily formatted for browsing).
Note: Whenever you pass a message into a SimpleTest assertion, do NOT translate the message using t(). (To format a string with variables, use format_string() instead.)
| Method | Description | Example usage |
|---|---|---|
|
Asserts that the variable $result resolves to TRUE. |
|
|
Asserts that the variable $result resolves to FALSE. |
|
|
Asserts that the variable $value resolves to NULL. |
|
|
Asserts that the variable $value does NOT resolve to NULL. |
|
|
Asserts that the variable $first is roughly equivalent (==) to $second. |
|
|
Asserts that the variable $first is not roughly equivalent (!=) to $second. |
|
|
Asserts that the variable $first is absolutely identical (===) to $second. |
|
|
Asserts that the variable $first is not absolutely identical (!==) to $second. |
|
Checking page results |
||
|
Asserts that the raw html content of the current page matches the regular expression $pattern. |
|
|
Asserts that the raw html content of the current page does not match the regular expression $pattern. |
|
|
Asserts that the html $raw appears in the raw html content of the current page in the SimpleTest browser. |
|
|
Asserts that the html $raw does NOT appear in the raw html content of the current page in the SimpleTest browser. |
|
|
Asserts that the text in $text appears in the content of the current page in the SimpleTest browser (html-stripped). |
|
|
Asserts that the text in $text does NOT appear in the content of the current page in the SimpleTest browser (html-stripped). |
|
|
Asserts that the title given in $title is the title of the current page in the SimpleTest browser. |
|
|
Asserts that the title given in $title is NOT the title of the current page in the SimpleTest browser. |
|
|
Asserts that the text in $text appears exactly once in the content of the current page in the SimpleTest browser (html-stripped). |
|
|
Asserts that the text in $text appears more than once in the content of the current page in the SimpleTest browser (html-stripped). |
|
|
Asserts that a link with the specified $label (the text between the anchor tags) is in the page. If more than one link will match, you may use the $index to specify which to look for. |
|
|
Asserts that no link with the specified $label (the text between the anchor tags) is on the page. |
|
|
Asserts that a link with the given $href or partial HREF is on the page. |
|
|
Asserts that no link with the specified $href or partial HREF is on the page. |
|
|
Asserts that the http response code for the current page in the simpletest browser matches $code. |
|
Checking form elements |
||
|
Assert that a field exists in the current page with the given id. If $value is not an empty string, also checks that the field contains that value. |
|
|
Assert that a field does not exists in the current page with the given id. If $value is not an empty string, also checks that the field does NOT contain that value. |
|
|
Assert that a field exists in the current page with the given name and value. |
|
|
Assert that a field does NOT exist in the current page with the given name and value. |
|
|
Assert that the checkbox field with the given $id exists and is checked. |
|
|
Assert that the checkbox field with the given $id exists but is NOT checked. |
|
|
Assert that a select option in the current page is checked. |
|
|
Assert that the specified select option in the current page is NOT checked. |
|
|
Assert that a field exists in the current page by the given XPath. | draft, needs testing or better examples
|
|
Assert that a field does NOT exist in the current page by the given XPath. | draft, needs testing or better examples
|
|
Assert that each HTML ID on the page is used for just one element. |
|
Miscellaneous |
||
|
Make an assertion that is always positive. |
|
|
Make an assertion that is always negative. |
|
|
Make an assertion that always yields an error condition. |
|
|
Assert that the most recently sent email message has a field $name (e.g. "subject", "body") with the given $value. |
|
| For Drupal 8 follow trait AssertContentTrait | ||
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion