When a page is fetched by the WebTestCase
using get() or
post() the page content is
automatically parsed.
This results in any form controls that are inside <form> tags
being available from within the test case.
For example, if we have this snippet of HTML...
]]>
Which looks like this...
We can navigate to this code, via the
LastCraft
site, with the following test...
We could submit the form straight away, but first we'll change
the value of the text field and only then submit it...
If a field is not present in any form, or if an option is unavailable,
then WebTestCase::setField() will return
false.
For example, suppose we wish to verify that a "Superuser"
option is not present in this form...
Select type of user to add: ]]>Which looks like...
The following test will confirm it...
Here is the full list of widgets currently supported...
Although most standard HTML widgets are catered for by SimpleTest's built in parser, it is unlikely that JavaScript will be implemented anytime soon.
SimpleTest can cope with two types of multivalue controls: Multiple selection drop downs, and multiple checkboxes with the same name within a form. The multivalue nature of these means that setting and testing are slightly different. Using checkboxes as an example...
Create privileges allowed:
Retrieve privileges allowed:
Update privileges allowed:
Destroy privileges allowed:
]]>
Which renders as...
If we wish to disable all but the retrieval privileges and
submit this information we can do it like this...
If you want to test a form handler, but have not yet written
or do not have access to the form itself, you can create a
form submission by hand.
WebTestCase::post()
method, we are attempting to fetch the page as a form submission.