Class WebTestCase

Description

Test case for testing of web pages. Allows fetching of pages, parsing of HTML and submitting forms.

Located in /libraries/pear/simpletest/web_tester.php (line 24)

RunnableTest
   |
   --SimpleTestCase
      |
      --WebTestCase
Direct descendents
Class Description
 class LiveSitesTestCase Test case for testing of web pages. Allows fetching of pages, parsing of HTML and submitting forms.
 class TestOfLiveFetching Test case for testing of web pages. Allows fetching of pages, parsing of HTML and submitting forms.
 class TestOfLiveFrontControllerEmulation Test case for testing of web pages. Allows fetching of pages, parsing of HTML and submitting forms.
 class TestOfLiveRedirects Test case for testing of web pages. Allows fetching of pages, parsing of HTML and submitting forms.
 class TestOfLiveCookies Test case for testing of web pages. Allows fetching of pages, parsing of HTML and submitting forms.
 class TestOfLiveForm Test case for testing of web pages. Allows fetching of pages, parsing of HTML and submitting forms.
 class TestOfLiveMultiValueWidgets Test case for testing of web pages. Allows fetching of pages, parsing of HTML and submitting forms.
 class TestOfLiveHistoryNavigation Test case for testing of web pages. Allows fetching of pages, parsing of HTML and submitting forms.
 class TestOfLiveAuthentication Test case for testing of web pages. Allows fetching of pages, parsing of HTML and submitting forms.
 class TestOfLiveFrames Test case for testing of web pages. Allows fetching of pages, parsing of HTML and submitting forms.
Variable Summary
 mixed $_browser
Method Summary
 WebTestCase WebTestCase ([string $label = false])
 void addHeader (string $header)
 void ageCookies (integer $interval)
 void assertAuthentication ([string $authentication = false], [string $message = '%s'])
 void assertCookie (string $name, [string $expected = false], [string $message = "%s"])
 void assertField (string $name, [mixed $expected = true], [string $message = "%s"])
 void assertFieldById (string/integer $id, [mixed $expected = true], [string $message = "%s"])
 boolean assertLink (string $label, [string $message = "%s"])
 boolean assertLinkById (string $id, [string $message = "%s"])
 void assertMime (array $types, [string $message = '%s'])
 void assertNoAuthentication ([string $message = '%s'])
 void assertNoCookie (string $name, [string $message = "%s"])
 void assertNoUnwantedPattern (string $pattern, [string $message = "%s"])
 void assertRealm (string $realm, [string $message = '%s'])
 void assertResponse (array $responses, [string $message = '%s'])
 void assertTitle ([string $title = false], [string $message = '%s'])
 void assertWantedPattern (string $pattern, [string $message = '%s'])
 boolean authenticate (string $username, string $password)
 boolean back ()
 void clearFrameFocus ()
 boolean clickImage (string $label, [integer $x = 1], [integer $y = 1])
 boolean clickImageById (integer/string $id, [integer $x = 1], [integer $y = 1])
 boolean clickImageByName (string $name, [integer $x = 1], [integer $y = 1])
 boolean clickLink (string $label, integer $index)
 boolean clickLinkById (string $id)
 boolean clickSubmit ([string $label = 'Submit'])
 boolean clickSubmitById (string $id)
 boolean clickSubmitByName (string $name)
 TestBrowser &createBrowser ()
 boolean forward ()
 boolean get (string $url, [hash $parameters = false])
 void &getBrowser (SimpleBrowser $browser)
 integer/string/boolean getFrameFocus ()
 string getTransportError ()
 boolean head (string $url, [hash $parameters = false])
 void ignoreFrames ()
 void invoke (string $method)
 boolean post (string $url, [hash $parameters = false])
 void restartSession ([string/integer $date = false])
 boolean retry ()
 void setConnectionTimeout (integer $timeout)
 void setCookie (string $name, string $value, [string $host = false], [string $path = "/"], [string $expiry = false])
 boolean setField (string $name, string $value)
 boolean setFieldById (string/integer $id, string $value)
 boolean setFrameFocus (string $name)
 boolean setFrameFocusByIndex (integer $choice)
 void setMaximumRedirects (integer $max)
 void showHeaders ()
 void showRequest ()
 void showSource ()
 boolean submitFormById (string $id)
 void useProxy (string $proxy, [string $username = false], [string $password = false])
Variables
mixed $_browser (line 25)

Inherited Variables

Inherited from SimpleTestCase

SimpleTestCase::$_reporter

Inherited from RunnableTest

RunnableTest::$_label
Methods
Constructor WebTestCase (line 34)

Creates an empty test case. Should be subclassed with test methods for a functional test case.

  • access: public
WebTestCase WebTestCase ([string $label = false])
  • string $label: Name of test case. Will use the class name if none specified.
addHeader (line 159)

Adds a header to every fetch.

  • access: public
void addHeader (string $header)
  • string $header: Header line to add to every request until cleared.
ageCookies (line 95)

Moves cookie expiry times back into the past.

Useful for testing timeouts and expiries.

  • access: public
void ageCookies (integer $interval)
  • integer $interval: Amount to age in seconds.
assertAuthentication (line 592)

Attempt to match the authentication type within the security realm we are currently matching.

  • access: public
void assertAuthentication ([string $authentication = false], [string $message = '%s'])
  • string $authentication: Usually basic.
  • string $message: Message to display.
assertCookie (line 686)

Checks that a cookie is set for the current page and optionally checks the value.

  • access: public
void 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.
assertField (line 514)

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.

  • access: public
void assertField (string $name, [mixed $expected = true], [string $message = "%s"])
  • string $name: Name of field in forms.
  • mixed $expected: Expected string/aray value or false for unset fields.
  • string $message: Message to display. Default can be embedded with %s.
assertFieldById (line 540)

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.

  • access: public
void assertFieldById (string/integer $id, [mixed $expected = true], [string $message = "%s"])
  • string/integer $id: Name of field in forms.
  • mixed $expected: Expected string/aray value or false for unset fields.
  • string $message: Message to display. Default can be embedded with %s.
assertLink (line 460)

Tests for the presence of a link label. Match is case insensitive with normalised space.

  • return: True if link present.
  • access: public
boolean assertLink (string $label, [string $message = "%s"])
  • string $label: Text between the anchor tags.
  • string $message: Message to display. Default can be embedded with %s.
assertLinkById (line 474)

Tests for the presence of a link id attribute.

  • return: True if link present.
  • access: public
boolean assertLinkById (string $id, [string $message = "%s"])
  • string $id: Id attribute value.
  • string $message: Message to display. Default can be embedded with %s.
assertMime (line 577)

Checks the mime type against a list of possible values.

  • access: public
void assertMime (array $types, [string $message = '%s'])
  • array $types: Possible mime types for a pass.
  • string $message: Message to display.
assertNoAuthentication (line 612)

Checks that no authentication is necessary to view the desired page.

  • access: public
void assertNoAuthentication ([string $message = '%s'])
  • string $message: Message to display.
assertNoCookie (line 706)

Checks that no cookie is present or that it has been successfully cleared.

  • access: public
void assertNoCookie (string $name, [string $message = "%s"])
  • string $name: Name of cookie to test.
  • string $message: Message to display.
assertNoUnwantedPattern (line 670)

Will trigger a pass if the perl regex pattern is not present in raw content.

  • access: public
void assertNoUnwantedPattern (string $pattern, [string $message = "%s"])
  • string $pattern: Perl regex to look for including the regex delimiters.
  • string $message: Message to display.
assertRealm (line 624)

Attempts to match the current security realm.

  • access: public
void assertRealm (string $realm, [string $message = '%s'])
  • string $realm: Name of security realm.
  • string $message: Message to display.
assertResponse (line 562)

Checks the response code against a list of possible values.

  • access: public
void assertResponse (array $responses, [string $message = '%s'])
  • array $responses: Possible responses for a pass.
  • string $message: Message to display. Default can be embedded with %s.
assertTitle (line 639)

Tests the text between the title tags.

  • access: public
void assertTitle ([string $title = false], [string $message = '%s'])
  • string $title: Expected title or empty if expecting no title.
  • string $message: Message to display.
assertWantedPattern (line 655)

Will trigger a pass if the Perl regex pattern is found in the raw content.

  • access: public
void assertWantedPattern (string $pattern, [string $message = '%s'])
  • string $pattern: Perl regex to look for including the regex delimiters.
  • string $message: Message to display.
authenticate (line 290)

Retries a request after setting the authentication for the current realm.

  • return: True if successful fetch. Note that authentication may still have failed.
  • access: public
boolean authenticate (string $username, string $password)
  • string $username: Username for realm.
  • string $password: Password for realm.
back (line 265)

Equivalent to hitting the back button on the browser.

  • return: True if history entry and fetch succeeded.
  • access: public
boolean back ()
clearFrameFocus (line 331)

Clears the frame focus. All frames will be searched for content.

  • access: public
void clearFrameFocus ()
clickImage (line 381)

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.

  • return: True on successful submit.
  • access: public
boolean clickImage (string $label, [integer $x = 1], [integer $y = 1])
  • string $label: Alt attribute of button.
  • integer $x: X-coordinate of imaginary click.
  • integer $y: Y-coordinate of imaginary click.
clickImageById (line 412)

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.

  • return: True on successful submit.
  • access: public
boolean clickImageById (integer/string $id, [integer $x = 1], [integer $y = 1])
  • integer/string $id: ID attribute of button.
  • integer $x: X-coordinate of imaginary click.
  • integer $y: Y-coordinate of imaginary click.
clickImageByName (line 397)

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.

  • return: True on successful submit.
  • access: public
boolean clickImageByName (string $name, [integer $x = 1], [integer $y = 1])
  • string $name: Name attribute of button.
  • integer $x: X-coordinate of imaginary click.
  • integer $y: Y-coordinate of imaginary click.
clickLink (line 437)

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.

  • return: True if link present.
  • access: public
boolean clickLink (string $label, integer $index)
  • string $label: Text between the anchor tags.
  • integer $index: Link position counting from zero.
clickLinkById (line 447)

Follows a link by id attribute.

  • return: True if successful.
  • access: public
boolean clickLinkById (string $id)
  • string $id: ID attribute value.
clickSubmit (line 343)

Clicks the submit button by label. The owning form will be submitted by this.

  • return: True on success.
  • access: public
boolean clickSubmit ([string $label = 'Submit'])
  • string $label: Button label. An unlabeled button can be triggered by 'Submit'.
clickSubmitById (line 365)

Clicks the submit button by ID attribute. The owning form will be submitted by this.

  • return: True on successful submit.
  • access: public
boolean clickSubmitById (string $id)
  • string $id: ID attribute of button.
clickSubmitByName (line 354)

Clicks the submit button by name attribute. The owning form will be submitted by this.

  • return: True on success.
  • access: public
boolean clickSubmitByName (string $name)
  • string $name: Name attribute of button.
createBrowser (line 116)

Creates a new default web browser object.

Will be cleared at the end of the test method.

  • return: New browser.
  • access: public
TestBrowser &createBrowser ()
forward (line 276)

Equivalent to hitting the forward button on the browser.

  • return: True if history entry and fetch succeeded.
  • access: public
boolean forward ()
get (line 210)

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.

  • return: True on success.
  • access: public
boolean get (string $url, [hash $parameters = false])
  • string $url: URL to fetch.
  • hash $parameters: Optional additional GET data.
getBrowser (line 106)

Gets a current browser reference for setting special expectations or for detailed examination of page fetches.

  • access: public
void &getBrowser (SimpleBrowser $browser)
getFrameFocus (line 302)

Accessor for current frame focus. Will be false if no frame has focus.

  • return: Label if any, otherwise the position in the frameset or false if none.
  • access: public
integer/string/boolean getFrameFocus ()
getTransportError (line 67)

Gets the last response error.

  • return: Last low level HTTP error.
  • access: public
string getTransportError ()
head (line 244)

Does a HTTP HEAD fetch, fetching only the page headers. The current base URL is unchanged by this.

  • return: True on success.
  • access: public
boolean head (string $url, [hash $parameters = false])
  • string $url: URL to fetch.
  • hash $parameters: Optional additional GET data.
ignoreFrames (line 136)

Disables frames support. Frames will not be fetched and the frameset page will be used instead.

  • access: public
void ignoreFrames ()
invoke (line 126)

Sets up a browser for the start of each test method.

  • access: protected
void invoke (string $method)
  • string $method: Name of test method.

Redefinition of:
SimpleTestCase::invoke()
Invokes a test method and dispatches any untrapped errors. Called back from the visiting runner.
post (line 228)

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.

  • return: True on success.
  • access: public
boolean post (string $url, [hash $parameters = false])
  • string $url: URL to fetch.
  • hash $parameters: Optional additional GET data.
restartSession (line 82)

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.

  • access: public
void restartSession ([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.
retry (line 254)

Equivalent to hitting the retry button on the browser. Will attempt to repeat the page fetch.

  • return: True if fetch succeeded.
  • access: public
boolean retry ()
setConnectionTimeout (line 183)

Sets the socket timeout for opening a connection and receiving at least one byte of information.

  • access: public
void setConnectionTimeout (integer $timeout)
  • integer $timeout: Maximum time in seconds.
setCookie (line 149)

Sets a cookie in the current browser.

  • access: public
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.
setField (line 487)

Sets all form fields with that name.

  • return: True if field exists, otherwise false.
  • access: public
boolean setField (string $name, string $value)
  • string $name: Name of field in forms.
  • string $value: New value of field.
setFieldById (line 498)

Sets all form fields with that name.

  • return: True if field exists, otherwise false.
  • access: public
boolean setFieldById (string/integer $id, string $value)
  • string/integer $id: Id of field in forms.
  • string $value: New value of field.
setFrameFocus (line 322)

Sets the focus by name.

  • return: True if frame exists.
  • access: public
boolean setFrameFocus (string $name)
  • string $name: Chosen frame.
setFrameFocusByIndex (line 312)

Sets the focus by index. The integer index starts from 1.

  • return: True if frame exists.
  • access: public
boolean setFrameFocusByIndex (integer $choice)
  • integer $choice: Chosen frame.
setMaximumRedirects (line 169)

Sets the maximum number of redirects before the web page is loaded regardless.

  • access: public
void setMaximumRedirects (integer $max)
  • integer $max: Maximum hops.
showHeaders (line 58)

Dumps the current HTTP headers for debugging.

  • access: public
void showHeaders ()
showRequest (line 42)

Dumps the current request for debugging.

  • access: public
void showRequest ()
showSource (line 50)

Dumps the current HTML source for debugging.

  • access: public
void showSource ()
submitFormById (line 423)

Submits a form by the ID.

  • return: True on success.
  • access: public
boolean submitFormById (string $id)
  • string $id: Form ID. No button information is submitted this way.
useProxy (line 196)

Sets proxy to use on all requests for when testing from behind a firewall. Set URL to false to disable.

  • access: public
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.

Inherited Methods

Inherited From SimpleTestCase

 SimpleTestCase::SimpleTestCase()
 SimpleTestCase::assertExpectation()
 SimpleTestCase::assertFalse()
 SimpleTestCase::assertTrue()
 SimpleTestCase::dump()
 SimpleTestCase::error()
 SimpleTestCase::fail()
 SimpleTestCase::getAssertionLine()
 SimpleTestCase::invoke()
 SimpleTestCase::pass()
 SimpleTestCase::run()
 SimpleTestCase::sendMessage()
 SimpleTestCase::setUp()
 SimpleTestCase::signal()
 SimpleTestCase::swallowErrors()
 SimpleTestCase::tearDown()
 SimpleTestCase::_createRunner()
 SimpleTestCase::_isConstructor()
 SimpleTestCase::_isTest()

Inherited From RunnableTest

 RunnableTest::RunnableTest()
 RunnableTest::getLabel()
 RunnableTest::getSize()
 RunnableTest::run()

Documentation generated on Fri, 24 Dec 2004 13:04:03 +0000 by phpDocumentor 1.3.0RC3