SimpleTestCase
└─WebTestCase
public class WebTestCase
extends SimpleTestCase
Constructor Summary | |
---|---|
WebTestCase(string label) Creates an empty test case. |
Method Summary | |
---|---|
void | addHeader(string header) Adds a header to every fetch. |
void | ageCookies(integer interval) Moves cookie expiry times back into the past. |
boolean | assertAuthentication(string authentication, string message) Attempt to match the authentication type within the security realm we are currently matching. |
boolean | assertCookie(string name, string expected, string message) Checks that a cookie is set for the current page and optionally checks the value. |
boolean | assertField(string name, mixed expected, string message) Confirms that the form element is currently set to the expected value. |
boolean | assertFieldById(string/integer id, mixed expected, string message) Confirms that the form element is currently set to the expected value. |
boolean | assertHeader(string header, string value, mixed message) Checks each header line for the required value. |
boolean | assertHeaderPattern(string header, string pattern, mixed message) Checks each header line for the required pattern. |
boolean | assertLink(string label, string message) Tests for the presence of a link label. |
boolean | assertLinkById(string id, string message) Tests for the presence of a link id attribute. |
boolean | assertMime(array types, string message) Checks the mime type against a list of possible values. |
boolean | assertNoAuthentication(string message) Checks that no authentication is necessary to view the desired page. |
boolean | assertNoCookie(string name, string message) Checks that no cookie is present or that it has been successfully cleared. |
boolean | assertNoLink(string/integer label, string message) Tests for the non-presence of a link label. |
boolean | assertNoLinkById(string id, string message) Tests for the non-presence of a link label. |
boolean | assertNoUnwantedHeader(string header, mixed message) Confirms that the header type has not been received. |
boolean | assertNoUnwantedPattern(string pattern, string message) Will trigger a pass if the perl regex pattern is not present in raw content. |
boolean | assertNoUnwantedText(string text, string message) Will trigger a pass if the text is not found in the plain text form of the page. |
boolean | assertRealm(string realm, string message) Attempts to match the current security realm. |
boolean | assertResponse(array responses, string message) Checks the response code against a list of possible values. |
boolean | assertTitle(string title, string message) Tests the text between the title tags. |
boolean | assertWantedPattern(string pattern, string message) Will trigger a pass if the Perl regex pattern is found in the raw content. |
boolean | assertWantedText(string text, string message) Will trigger a pass if the text is found in the plain text form of the page. |
boolean | authenticate(string username, string password) Retries a request after setting the authentication for the current realm. |
boolean | back() Equivalent to hitting the back button on the browser. |
void | Clears the frame focus. |
boolean/string | clickImage(string label, integer x, integer y, hash additional) Clicks the submit image by some kind of label. |
boolean/string | clickImageById(integer/string id, integer x, integer y, hash additional) Clicks the submit image by ID attribute. |
boolean/string | clickImageByName(string name, integer x, integer y, hash additional) Clicks the submit image by the name. |
boolean/string | clickLink(string label, integer index) Follows a link by name. |
boolean/string | clickLinkById(string id) Follows a link by id attribute. |
boolean/string | clickSubmit(string label, hash additional) Clicks the submit button by label. |
boolean/string | clickSubmitById(string id, hash additional) Clicks the submit button by ID attribute. |
boolean/string | clickSubmitByName(string name, hash additional) Clicks the submit button by name attribute. |
TestBrowser | Creates a new default web browser object. |
SimpleInvoker | Sets the invoker to one that restarts the browser on each request. |
boolean | forward() Equivalent to hitting the forward button on the browser. |
boolean | get(string url, hash parameters) Fetches a page into the page buffer. |
SimpleBrowser | Gets a current browser reference for setting special expectations or for detailed examination of page fetches. |
string | getCookie(string name) Gets the cookie value for the current browser context. |
integer/string/boolean | Accessor for current frame focus. |
string | Gets the last response error. |
string | getUrl() Accessor for the currently selected URL. |
boolean | head(string url, hash parameters) Does a HTTP HEAD fetch, fetching only the page headers. |
void | Disables frames support. |
boolean | post(string url, hash parameters) Fetches a page by POST into the page buffer. |
void | restart(string/integer date) Simulates the closing and reopening of the browser. |
boolean | retry() Equivalent to hitting the retry button on the browser. |
void | setBrowser(SimpleBrowser browser) Gets a current browser reference for setting special expectations or for detailed examination of page fetches. |
void | setConnectionTimeout(integer timeout) Sets the socket timeout for opening a connection and receiving at least one byte of information. |
void | setCookie(string name, string value, string host, string path, string expiry) Sets a cookie in the current browser. |
boolean | setField(string name, string value) Sets all form fields with that name. |
boolean | setFieldById(string/integer id, string value) Sets all form fields with that name. |
boolean | setFrameFocus(string name) Sets the focus by name. |
boolean | setFrameFocusByIndex(integer choice) Sets the focus by index. |
void | setMaximumRedirects(integer max) Sets the maximum number of redirects before the web page is loaded regardless. |
void | Dumps the current HTTP headers for debugging. |
void | Dumps the current request for debugging. |
void | Dumps the current HTML source for debugging. |
boolean/string | submitFormById(string id) Submits a form by the ID. |
void | Clears the current browser reference to help the PHP garbage collector. |
void | useProxy(string proxy, string username, string password) Sets proxy to use on all requests for when testing from behind a firewall. |
Methods inherited from SimpleTest\SimpleTestCase | |
---|---|
assertExpectation, assertFalse, assertTrue, createInvoker, dump, error, fail, getAssertionLine, getLabel, getSize, pass, run, sendMessage, setUp, signal, swallowErrors, tearDown |
public WebTestCase(string label)
Creates an empty test case. Should be subclassed with test methods for a functional test case.
public void addHeader(string header)
Adds a header to every fetch.
public void ageCookies(integer interval)
Moves cookie expiry times back into the past. Useful for testing timeouts and expiries.
public boolean assertAuthentication(string authentication, string message)
Attempt to match the authentication type within the security realm we are currently matching.
public boolean assertCookie(string name, string expected, string message)
Checks that a cookie is set for the current page and optionally checks the value.
public boolean assertField(string name, mixed expected, string message)
Confirms that the form element is currently set to the expected value. A missing form will always fail. If no value is given then only the existence of the field is checked.
public boolean assertFieldById(string/integer id, mixed expected, string message)
Confirms that the form element is currently set to the expected value. A missing form will always fail. If no ID is given then only the existence of the field is checked.
public boolean assertHeader(string header, string value, mixed message)
Checks each header line for the required value. If no value is given then only an existence check is made.
public boolean assertHeaderPattern(string header, string pattern, mixed message)
Checks each header line for the required pattern.
public boolean assertLink(string label, string message)
Tests for the presence of a link label. Match is case insensitive with normalised space.
public boolean assertLinkById(string id, string message)
Tests for the presence of a link id attribute.
public boolean assertMime(array types, string message)
Checks the mime type against a list of possible values.
public boolean assertNoAuthentication(string message)
Checks that no authentication is necessary to view the desired page.
public boolean assertNoCookie(string name, string message)
Checks that no cookie is present or that it has been successfully cleared.
public boolean assertNoLink(string/integer label, string message)
Tests for the non-presence of a link label. Match is case insensitive with normalised space.
public boolean assertNoLinkById(string id, string message)
Tests for the non-presence of a link label. Match is case insensitive with normalised space.
public boolean assertNoUnwantedHeader(string header, mixed message)
Confirms that the header type has not been received. Only the landing page is checked. If you want to check redirect pages, then you should limit redirects so as to capture the page you want.
public boolean assertNoUnwantedPattern(string pattern, string message)
Will trigger a pass if the perl regex pattern is not present in raw content.
public boolean assertNoUnwantedText(string text, string message)
Will trigger a pass if the text is not found in the plain text form of the page.
public boolean assertRealm(string realm, string message)
Attempts to match the current security realm.
public boolean assertResponse(array responses, string message)
Checks the response code against a list of possible values.
public boolean assertTitle(string title, string message)
Tests the text between the title tags.
public boolean assertWantedPattern(string pattern, string message)
Will trigger a pass if the Perl regex pattern is found in the raw content.
public boolean assertWantedText(string text, string message)
Will trigger a pass if the text is found in the plain text form of the page.
public boolean authenticate(string username, string password)
Retries a request after setting the authentication for the current realm.
public boolean back()
Equivalent to hitting the back button on the browser.
public void clearFrameFocus()
Clears the frame focus. All frames will be searched for content.
public boolean/string clickImage(string label, integer x, integer y, hash additional)
Clicks the submit image by some kind of label. Usually the alt tag or the nearest equivalent. The owning form will be submitted by this. Clicking outside of the boundary of the coordinates will result in a failure.
public boolean/string clickImageById(integer/string id, integer x, integer y, hash additional)
Clicks the submit image by ID attribute. The owning form will be submitted by this. Clicking outside of the boundary of the coordinates will result in a failure.
public boolean/string clickImageByName(string name, integer x, integer y, hash additional)
Clicks the submit image by the name. Usually the alt tag or the nearest equivalent. The owning form will be submitted by this. Clicking outside of the boundary of the coordinates will result in a failure.
public boolean/string clickLink(string label, integer index)
Follows a link by name. Will click the first link found with this link text by default, or a later one if an index is given. Match is case insensitive with normalised space.
public boolean/string clickLinkById(string id)
Follows a link by id attribute.
public boolean/string clickSubmit(string label, hash additional)
Clicks the submit button by label. The owning form will be submitted by this.
public boolean/string clickSubmitById(string id, hash additional)
Clicks the submit button by ID attribute. The owning form will be submitted by this.
public boolean/string clickSubmitByName(string name, hash additional)
Clicks the submit button by name attribute. The owning form will be submitted by this.
public TestBrowser createBrowser()
Creates a new default web browser object. Will be cleared at the end of the test method.
public SimpleInvoker createInvoker()
Sets the invoker to one that restarts the browser on each request.
public boolean forward()
Equivalent to hitting the forward button on the browser.
public boolean get(string url, hash parameters)
Fetches a page into the page buffer. If there is no base for the URL then the current base URL is used. After the fetch the base URL reflects the new location.
public SimpleBrowser getBrowser()
Gets a current browser reference for setting special expectations or for detailed examination of page fetches.
public string getCookie(string name)
Gets the cookie value for the current browser context.
public integer/string/boolean getFrameFocus()
Accessor for current frame focus. Will be false if no frame has focus.
public string getTransportError()
Gets the last response error.
public string getUrl()
Accessor for the currently selected URL.
public boolean head(string url, hash parameters)
Does a HTTP HEAD fetch, fetching only the page headers. The current base URL is unchanged by this.
public void ignoreFrames()
Disables frames support. Frames will not be fetched and the frameset page will be used instead.
public boolean post(string url, hash parameters)
Fetches a page by POST into the page buffer. If there is no base for the URL then the current base URL is used. After the fetch the base URL reflects the new location.
public void restart(string/integer date)
Simulates the closing and reopening of the browser. Temporary cookies will be discarded and timed cookies will be expired if later than the specified time.
public boolean retry()
Equivalent to hitting the retry button on the browser. Will attempt to repeat the page fetch.
public void setBrowser(SimpleBrowser browser)
Gets a current browser reference for setting special expectations or for detailed examination of page fetches.
public void setConnectionTimeout(integer timeout)
Sets the socket timeout for opening a connection and receiving at least one byte of information.
public void setCookie(string name, string value, string host, string path, string expiry)
Sets a cookie in the current browser.
public boolean setField(string name, string value)
Sets all form fields with that name.
public boolean setFieldById(string/integer id, string value)
Sets all form fields with that name.
public boolean setFrameFocus(string name)
Sets the focus by name.
public boolean setFrameFocusByIndex(integer choice)
Sets the focus by index. The integer index starts from 1.
public void setMaximumRedirects(integer max)
Sets the maximum number of redirects before the web page is loaded regardless.
public void showHeaders()
Dumps the current HTTP headers for debugging.
public void showRequest()
Dumps the current request for debugging.
public void showSource()
Dumps the current HTML source for debugging.
public boolean/string submitFormById(string id)
Submits a form by the ID.
public void unsetBrowser()
Clears the current browser reference to help the PHP garbage collector.
public void useProxy(string proxy, string username, string password)
Sets proxy to use on all requests for when testing from behind a firewall. Set URL to false to disable.
Test case for testing of web pages. Allows fetching of pages, parsing of HTML and submitting forms.