Software QA FYI - SQAFYI

Testing Forms in PHP with SimpleTest

By: W. Jason Gilmore

Testing Forms in PHP with SimpleTest
Although not as well known as PHPUnit, SimpleTest is an immensely capable framework, having been adopted by popular PHP projects including CakePHP and Drupal. In addition to offer a complete suite of unit testing capabilities, SimpleTest is bundled with an internal Web browser which you can use to automate the navigation of your Web site and perform tests such as completing and submitting Web forms much in the same way a typical user would. In this tutorial, I'll show you how to use SimpleTest to automate these otherwise tedious tasks.

Installing SimpleTest
Download SimpleTest by heading over to its SourceForge page and downloading the latest stable version. Once downloaded, unzip the package to a convenient location and add its path to PHP's include_path. After restarting your Web server, you can make sure SimpleTest is accessible from a PHP script by creating a PHP script which contains the following code:

<?php
require_once('simpletest/autorun.php');
require_once('simpletest/web_tester.php');

?>

Save this file (using a name such as simpletest.php) to a convenient location within your Web server document root path and call it from within your Web browser. You should see output similar to that presented in Figure 1.

The SimpleTest Framework
Figure 1. Making Sure the SimpleTest Framework Is Accessible If you receive a warning about not being able to find one of the SimpleTest files, the problem is almost certainly due to an incorrect include_path setting.

Confirming That a Web Page Exists
With SimpleTest installed, let's work through testing the contact form shown in Figure 2. This is a pretty standard form, consisting of three input fields, including two text fields named name and email, respectively, and a text area field named message.

Full article...


Other Resource

... to read more articles, visit http://sqa.fyicenter.com/art/

Testing Forms in PHP with SimpleTest