Creates an empty test case. Should be subclassed with test methods for a functional test case.
WebTestCase
WebTestCase
([string $label = false])
-
string
$label: Name of test case. Will use the class name if none specified.
Adds a header to every fetch.
void
addHeader
(string $header)
-
string
$header: Header line to add to every request until cleared.
Announces the end of the test. Includes private clean up.
void
after
(string $method)
-
string
$method: Test method just finished.
Redefinition of:
- SimpleTestCase::after()
- Announces the end of the test. Includes private clean up.
Moves cookie expiry times back into the past.
Useful for testing timeouts and expiries.
void
ageCookies
(integer $interval)
-
integer
$interval: Amount to age in seconds.
Attempt to match the authentication type within the security realm we are currently matching.
boolean
assertAuthentication
([string $authentication = false], [string $message = '%s'])
-
string
$authentication: Usually basic.
-
string
$message: Message to display.
Checks for a click target.
boolean
assertClickable
(string $label, [ $message = '%s'])
-
string
$label: Visible text or alt text.
-
$message
Checks that a cookie is set for the current page and optionally checks the value.
boolean
assertCookie
(string $name, [string $expected = false], [string $message = '%s'])
-
string
$name: Name of cookie to test.
-
string
$expected: Expected value as a string or false if any value will do.
-
string
$message: Message to display.
Will trigger a pass if the two parameters have the same value only. Otherwise a fail. This is for testing hand extracted text, etc.
boolean
assertEqual
(mixed $first, mixed $second, [string $message = '%s'])
-
mixed
$first: Value to compare.
-
mixed
$second: Value to compare.
-
string
$message: Message to display.
Will be true on false and vice versa. False is the PHP definition of false, so that null, empty strings, zero and an empty array all count as false.
boolean
assertFalse
(boolean $result, [string $message = '%s'])
-
boolean
$result: Pass on false.
-
string
$message: Message to display.
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.
boolean
assertField
( $label, [mixed $expected = true], [string $message = '%s'], string $name)
-
string
$name: Name of field in forms.
-
mixed
$expected: Expected string/array value or false for unset fields.
-
string
$message: Message to display. Default can be embedded with %s.
-
$label
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.
boolean
assertFieldById
(string/integer $id, [mixed $expected = true], [string $message = '%s'])
-
string/integer
$id: Name of field in forms.
-
mixed
$expected: Expected string/array value or false for unset fields.
-
string
$message: Message to display. Default can be embedded with %s.
Confirms that the form element is currently set to the expected value. A missing form element will always fail. If no value is given then only the existence of the field is checked.
boolean
assertFieldByName
(string $name, [mixed $expected = true], [string $message = '%s'])
-
string
$name: Name of field in forms.
-
mixed
$expected: Expected string/array value or false for unset fields.
-
string
$message: Message to display. Default can be embedded with %s.
Checks each header line for the required value. If no value is given then only an existence check is made.
boolean
assertHeader
(string $header, [mixed $value = false], [ $message = '%s'])
-
string
$header: Case insensitive header name.
-
mixed
$value: Case sensitive trimmed string to match against. An expectation object can be used for pattern matching.
-
$message
void
assertHeaderPattern
( $header, $pattern, [ $message = '%s'])
-
$header
-
$pattern
-
$message
Checks for a valid image with atht alt text or title.
boolean
assertImage
(string $label, [ $message = '%s'])
-
string
$label: Visible text.
-
$message
Tests for the presence of a link label. Match is case insensitive with normalised space.
boolean
assertLink
(string $label, [mixed $expected = true], [string $message = '%s'])
-
string
$label: Text between the anchor tags.
-
mixed
$expected: Expected URL or expectation object.
-
string
$message: Message to display. Default can be embedded with %s.
Tests for the presence of a link id attribute.
boolean
assertLinkById
(string $id, [mixed $expected = true], [string $message = '%s'])
-
string
$id: Id attribute value.
-
mixed
$expected: Expected URL or expectation object.
-
string
$message: Message to display. Default can be embedded with %s.
Checks the mime type against a list of possible values.
boolean
assertMime
(array $types, [string $message = '%s'])
-
array
$types: Possible mime types for a pass.
-
string
$message: Message to display.
Checks that no authentication is necessary to view the desired page.
boolean
assertNoAuthentication
([string $message = '%s'])
-
string
$message: Message to display.
Checks that no cookie is present or that it has been successfully cleared.
boolean
assertNoCookie
(string $name, [string $message = '%s'])
-
string
$name: Name of cookie to test.
-
string
$message: Message to display.
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.
boolean
assertNoHeader
(string $header, [ $message = '%s'])
-
string
$header: Case insensitive header name.
-
$message
Tests for the non-presence of a link label. Match is case insensitive with normalised space.
boolean
assertNoLink
(string/integer $label, [string $message = '%s'])
-
string/integer
$label: Text between the anchor tags or ID attribute.
-
string
$message: Message to display. Default can be embedded with %s.
Tests for the non-presence of a link label. Match is case insensitive with normalised space.
boolean
assertNoLinkById
(string $id, [string $message = '%s'])
-
string
$id: Id attribute value.
-
string
$message: Message to display. Default can be embedded with %s.
Will trigger a pass if the perl regex pattern is not present in raw content.
boolean
assertNoPattern
(string $pattern, [string $message = '%s'])
-
string
$pattern: Perl regex to look for including the regex delimiters.
-
string
$message: Message to display.
Will trigger a pass if the two parameters have a different value. Otherwise a fail. This is for testing hand extracted text, etc.
boolean
assertNotEqual
(mixed $first, mixed $second, [string $message = '%s'])
-
mixed
$first: Value to compare.
-
mixed
$second: Value to compare.
-
string
$message: Message to display.
Will trigger a pass if the text is not found in the plain text form of the page.
boolean
assertNoText
(string $text, [string $message = '%s'])
-
string
$text: Text to look for.
-
string
$message: Message to display.
void
assertNoUnwantedHeader
( $header, [ $message = '%s'])
void
assertNoUnwantedPattern
( $pattern, [ $message = '%s'])
void
assertNoUnwantedText
( $text, [ $message = '%s'])
Will trigger a pass if the Perl regex pattern is found in the raw content.
boolean
assertPattern
(string $pattern, [string $message = '%s'])
-
string
$pattern: Perl regex to look for including the regex delimiters.
-
string
$message: Message to display.
Attempts to match the current security realm.
boolean
assertRealm
(string $realm, [string $message = '%s'])
-
string
$realm: Name of security realm.
-
string
$message: Message to display.
Checks the response code against a list of possible values.
boolean
assertResponse
(array $responses, [string $message = '%s'])
-
array
$responses: Possible responses for a pass.
-
string
$message: Message to display. Default can be embedded with %s.
Checks for a valid button label.
boolean
assertSubmit
(string $label, [ $message = '%s'])
-
string
$label: Visible text.
-
$message
Will trigger a pass if the text is found in the plain text form of the page.
boolean
assertText
(string $text, [string $message = '%s'])
-
string
$text: Text to look for.
-
string
$message: Message to display.
Tests the text between the title tags.
boolean
assertTitle
([string/SimpleExpectation $title = false], [string $message = '%s'])
-
string/SimpleExpectation
$title: Expected title.
-
string
$message: Message to display.
Called from within the test methods to register passes and failures.
boolean
assertTrue
(boolean $result, [string $message = false])
-
boolean
$result: Pass on true.
-
string
$message: Message to display describing the test state.
void
assertWantedPattern
( $pattern, [ $message = '%s'])
void
assertWantedText
( $text, [ $message = '%s'])
Retries a request after setting the authentication for the current realm.
boolean/string
authenticate
(string $username, string $password)
-
string
$username: Username for realm.
-
string
$password: Password for realm.
Equivalent to hitting the back button on the browser.
boolean
back
()
Announces the start of the test.
void
before
(string $method)
-
string
$method: Test method just started.
Redefinition of:
- SimpleTestCase::before()
- Announces the start of the test.
Clears the frame focus. All frames will be searched for content.
void
clearFrameFocus
()
Clicks a visible text item. Will first try buttons, then links and then images.
string/boolean
click
(string $label)
-
string
$label: Visible text or alt text.
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.
boolean/string
clickImage
(string $label, [integer $x = 1], [integer $y = 1], [hash $additional = false])
-
string
$label: Alt attribute of button.
-
integer
$x: X-coordinate of imaginary click.
-
integer
$y: Y-coordinate of imaginary click.
-
hash
$additional: Additional form values.
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.
boolean/string
clickImageById
(integer/string $id, [integer $x = 1], [integer $y = 1], [hash $additional = false])
-
integer/string
$id: ID attribute of button.
-
integer
$x: X-coordinate of imaginary click.
-
integer
$y: Y-coordinate of imaginary click.
-
hash
$additional: Additional form values.
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.
boolean/string
clickImageByName
(string $name, [integer $x = 1], [integer $y = 1], [hash $additional = false])
-
string
$name: Name attribute of button.
-
integer
$x: X-coordinate of imaginary click.
-
integer
$y: Y-coordinate of imaginary click.
-
hash
$additional: Additional form values.
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.
boolean/string
clickLink
(string $label, integer $index)
-
string
$label: Text between the anchor tags.
-
integer
$index: Link position counting from zero.
Follows a link by id attribute.
boolean/string
clickLinkById
(string $id)
-
string
$id: ID attribute value.
Clicks the submit button by label. The owning form will be submitted by this.
boolean/string
clickSubmit
([string $label = 'Submit'], [hash $additional = false])
-
string
$label: Button label. An unlabeled button can be triggered by 'Submit'.
-
hash
$additional: Additional form values.
Clicks the submit button by ID attribute. The owning form will be submitted by this.
boolean/string
clickSubmitById
(string $id, [hash $additional = false])
-
string
$id: ID attribute of button.
-
hash
$additional: Additional form values.
Clicks the submit button by name attribute. The owning form will be submitted by this.
boolean/string
clickSubmitByName
(string $name, [hash $additional = false])
-
string
$name: Name attribute of button.
-
hash
$additional: Additional form values.
Creates a new default web browser object.
Will be cleared at the end of the test method.
TestBrowser
&createBrowser
()
Equivalent to hitting the forward button on the browser.
boolean
forward
()
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.
boolean/string
get
(string $url, [hash $parameters = false])
-
string
$url: URL to fetch.
-
hash
$parameters: Optional additional GET data.
Uses a stack trace to find the line of an assertion.
string
getAssertionLine
()
Redefinition of:
- SimpleTestCase::getAssertionLine()
- Uses a stack trace to find the line of an assertion.
Gets a current browser reference for setting special expectations or for detailed examination of page fetches.
Gets the cookie value for the current browser context.
string
getCookie
(string $name)
-
string
$name: Name of cookie.
Accessor for current frame focus. Will be false if no frame has focus.
integer/string/boolean
getFrameFocus
()
Gets the last response error.
string
getTransportError
()
Accessor for the currently selected URL.
string
getUrl
()
Does a HTTP HEAD fetch, fetching only the page headers. The current base URL is unchanged by this.
boolean
head
(string $url, [hash $parameters = false])
-
string
$url: URL to fetch.
-
hash
$parameters: Optional additional GET data.
Switches off cookie sending and recieving.
void
ignoreCookies
()
Skips errors for the next request only. You might want to confirm that a page is unreachable for example.
void
ignoreErrors
()
Disables frames support. Frames will not be fetched and the frameset page will be used instead.
void
ignoreFrames
()
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.
boolean/string
post
(string $url, [hash $parameters = false])
-
string
$url: URL to fetch.
-
hash
$parameters: Optional additional GET data.
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.
void
restart
([string/integer $date = false])
-
string/integer
$date: Time when session restarted. If ommitted then all persistent cookies are kept. Time is either Cookie format string or timestamp.
Equivalent to hitting the retry button on the browser. Will attempt to repeat the page fetch.
boolean
retry
()
Gets a current browser reference for setting special expectations or for detailed examination of page fetches.
Sets the socket timeout for opening a connection and receiving at least one byte of information.
void
setConnectionTimeout
(integer $timeout)
-
integer
$timeout: Maximum time in seconds.
Sets a cookie in the current browser.
void
setCookie
(string $name, string $value, [string $host = false], [string $path = '/'], [string $expiry = false])
-
string
$name: Name of cookie.
-
string
$value: Cookie value.
-
string
$host: Host upon which the cookie is valid.
-
string
$path: Cookie path if not host wide.
-
string
$expiry: Expiry date.
Sets all form fields with that label, or name if there is no label attached.
boolean
setField
( $label, string $value, [ $position = false], string $name)
-
string
$name: Name of field in forms.
-
string
$value: New value of field.
-
$label
-
$position
Sets all form fields with that id.
boolean
setFieldById
(string/integer $id, string $value)
-
string/integer
$id: Id of field in forms.
-
string
$value: New value of field.
Sets all form fields with that name.
boolean
setFieldByName
(string $name, string $value, [ $position = false])
-
string
$name: Name of field in forms.
-
string
$value: New value of field.
-
$position
Sets the focus by name.
boolean
setFrameFocus
(string $name)
-
string
$name: Chosen frame.
Sets the focus by index. The integer index starts from 1.
boolean
setFrameFocusByIndex
(integer $choice)
-
integer
$choice: Chosen frame.
Sets the maximum number of redirects before the web page is loaded regardless.
void
setMaximumRedirects
(integer $max)
-
integer
$max: Maximum hops.
Dumps the current HTTP headers for debugging.
void
showHeaders
()
Dumps the current request for debugging.
void
showRequest
()
Dumps the current HTML source for debugging.
void
showSource
()
Dumps the visible text only for debugging.
void
showText
()
Submits a form by the ID.
boolean/string
submitFormById
(string $id)
-
string
$id: Form ID. No button information is submitted this way.
Clears the current browser reference to help the PHP garbage collector.
void
unsetBrowser
()
Sets proxy to use on all requests for when testing from behind a firewall. Set URL to false to disable.
void
useProxy
(string $proxy, [string $username = false], [string $password = false])
-
string
$proxy: Proxy URL.
-
string
$username: Proxy username for authentication.
-
string
$password: Proxy password for authentication.
Tests the field value against the expectation.
boolean
_assertFieldValue
(string $identifier, mixed $value, mixed $expected, string $message)
-
string
$identifier: Name, ID or label.
-
mixed
$value: Current field value.
-
mixed
$expected: Expected value to match.
-
string
$message: Failure message.
Inherited Methods
Inherited From SimpleTestCase
SimpleTestCase::SimpleTestCase()
SimpleTestCase::after()
SimpleTestCase::assert()
SimpleTestCase::assertExpectation()
SimpleTestCase::before()
SimpleTestCase::createInvoker()
SimpleTestCase::dump()
SimpleTestCase::error()
SimpleTestCase::exception()
SimpleTestCase::fail()
SimpleTestCase::getAssertionLine()
SimpleTestCase::getLabel()
SimpleTestCase::getSize()
SimpleTestCase::getTests()
SimpleTestCase::pass()
SimpleTestCase::run()
SimpleTestCase::sendMessage()
SimpleTestCase::setUp()
SimpleTestCase::signal()
SimpleTestCase::skip()
SimpleTestCase::skipIf()
SimpleTestCase::skipUnless()
SimpleTestCase::tearDown()
SimpleTestCase::tell()
SimpleTestCase::_isTest()