Writing a Functional Web Test

In addition to unit testing, we shall also do some functional testing or web testing. Functional tests are, in this case, basically automated tests that will interact with the overall web application, as if it was the user, while checking the output for correctness. The functional test tool we shall use here is based on Selenium where the test cases can be written and run using PHP and SimpleTest.

<?php class HelloPradoTestCase extends SeleniumTestCase { function test() { $this->open('../index.php'); $this->assertTextPresent('Welcome to Prado!'); } } ?>

Save the code as HelloPradoTestCase.php in the document_root/time-tracker/tests/functional/ directory.

Functional test cases are written very similar to unit test cases. The method such as open($url) are those found in Selenium. All the methods available in Selenium are available.

Run your first unit test case from your browser

Point your browser to your development server's unit test case runner, e.g. http://web-server-address/time-tracker/tests/functional.php. You should see the following

Figure 4: Functional test runner

Clicking on the All button, you should see

Figure 5: Functional test success