Dagfinn in a new post over his blog, lists the techniques that he has learned when writing tests to exercise the web interface of a PHP application. He says, that the idea of being able to record and play back tests, as done with Selenium, is tempting. But he wants to program the tests. The programming, in this context will mean anything from simple conditionals and loops to advanced test patterns. So, it will help to achieve an organization and more flexible results, he says.
He gives the following tips for PHP web testing:
- Use SimpleTest's Web tester if you can: he informs that it’s the simplest and most direct way to write web tests. But to test an interface that involves advanced JavaScript such as AJAX, he says, Selenium can be of help to do all the testing, provided it runs on an actual web browser. He also provides added information with an example that ignoring and bypassing it in SimpleTest can handle some simple JavaScript.
- Test the web output using regular expressions: he says, regular expressions make tests more tolerant and less likely to break when web page details change. The assertPattern in SimpleTest tests the HTML source of the page. He illustrates this pointer with an example:
$this->assertPattern('/<td class="?admin"?/i');. - Use element IDs or names to test links, forms and fields: he explains, the point of IDs is to identify elements. They can be made unique, and can be left unchanged when the text seen by the user changes. That goes for form and field names, too, but they're slightly less reliable since they have other work to do as well, he explains.
- Log HTTP requests in the application: in this pointer, he says, if the tests fail for reasons that seem hard to fathom, he suggests to write the contents of the request variables to a log file. Then the next step to be carried out is to compare the test requests to the ones your browser generates when tested manually, he says.




