Class SimpleBrowser

Description

Simulated web browser. This is an aggregate of the user agent, the HTML parsing, request history and the last header set.

Located in /browser.php (line 160)


	
			
Variable Summary
Method Summary
 SimpleBrowser SimpleBrowser ()
 void addHeader (string $header)
 void ageCookies (integer $interval)
 boolean authenticate (string $username, string $password)
 boolean back ()
 void clearFrameFocus ()
 string/boolean click (string $label)
 string/boolean clickImage (string $label, [integer $x = 1], [integer $y = 1], [hash $additional = false])
 string/boolean clickImageById (integer/string $id, [integer $x = 1], [integer $y = 1], [hash $additional = false])
 string/boolean clickImageByName (string $name, [integer $x = 1], [integer $y = 1], [hash $additional = false])
 string/boolean clickLink (string $label, [integer $index = 0])
 string/boolean clickLinkById (string $id)
 string/boolean clickSubmit ([string $label = 'Submit'], [hash $additional = false])
 string/boolean clickSubmitById (string $id, [hash $additional = false])
 string/boolean clickSubmitByName (string $name, [hash $additional = false])
 boolean forward ()
 string get (string/SimpleUrl $url, [hash/SimpleFormEncoding $parameters = false])
 string getAuthentication ()
 string getBaseUrl ()
 string getContent ()
 string getContentAsText ()
 string getCookieValue (string $host, string $path, string $name)
 string getCurrentCookieValue (string $name)
 string/boolean getField (string $label)
 string/boolean getFieldById (string/integer $id)
 string/boolean getFieldByName (string $name)
 integer/string/boolean getFrameFocus ()
 array getFrames ()
 string getHeaders ()
 string/boolean getLink (string $label, [integer $index = 0])
 string/boolean getLinkById (string $id)
 string getMimeType ()
 string getRealm ()
 string getRequest ()
 integer getResponseCode ()
 string getTitle ()
 string getTransportError ()
 string getUrl ()
 array getUrls ()
 boolean head (string/SimpleUrl $url, [hash/SimpleHeadEncoding $parameters = false])
 void ignoreCookies ()
 void ignoreFrames ()
 boolean isClickable (string $label)
 boolean isImage (string $label)
 boolean isSubmit (string $label)
 string post (string/SimpleUrl $url, [hash/SimpleFormEncoding $parameters = false])
 void restart ([string/integer $date = false])
 string/boolean retry ()
 void setConnectionTimeout (integer $timeout)
 void setCookie (string $name, string $value, [string $host = false], [string $path = '/'], [string $expiry = false])
 boolean setField (string $label, string $value, [ $position = false])
 boolean setFieldById (string/integer $id, string $value)
 boolean setFieldByName (string $name, string $value, [ $position = false])
 boolean setFrameFocus (string $name)
 boolean setFrameFocusByIndex (integer $choice)
 void setMaximumNestedFrames (integer $max)
 void setMaximumRedirects (integer $max)
 string/boolean submitFormById (string $id)
 void useCookies ()
 void useFrames ()
 void useProxy (string $proxy, [string $username = false], [string $password = false])
 SimpleFetcher &_createUserAgent ()
Variables
mixed $_history (line 163)
mixed $_ignore_frames (line 164)
mixed $_maximum_nested_frames (line 165)
mixed $_page (line 162)
mixed $_user_agent (line 161)
Methods
Constructor SimpleBrowser (line 174)

Starts with a fresh browser with no cookie or any other state information. The exception is that a default proxy will be set up if specified in the options.

  • access: public
SimpleBrowser SimpleBrowser ()
addHeader (line 360)

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 369)

Ages the cookies by the specified time.

  • access: public
void ageCookies (integer $interval)
  • integer $interval: Amount in seconds.
authenticate (line 583)

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 542)

Equivalent to hitting the back button on the browser. The browser history is unchanged on failure. The page content is refetched as there is no concept of content caching in SimpleTest.

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

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

  • access: public
void clearFrameFocus ()
click (line 1077)

Clicks a visible text item. Will first try buttons, then links and then images.

  • return: Raw page or false.
  • access: public
string/boolean click (string $label)
  • string $label: Visible text or alt text.
clickImage (line 923)

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: Page on success.
  • access: public
string/boolean clickImage (string $label, [integer $x = 1], [integer $y = 1], [hash $additional = false])
  • string $label: ID attribute of button.
  • integer $x: X-coordinate of imaginary click.
  • integer $y: Y-coordinate of imaginary click.
  • hash $additional: Additional form data.
clickImageById (line 968)

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: Page on success.
  • access: public
string/boolean 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 data.
clickImageByName (line 946)

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: Page on success.
  • access: public
string/boolean 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 data.
clickLink (line 1037)

Follows a link by label. Will click the first link found with this link text by default, or a later one if an index is given. The match ignores case and white space issues.

  • return: Page on success.
  • access: public
string/boolean clickLink (string $label, integer $index)
  • string $label: Text between the anchor tags.
  • integer $index: Link position counting from zero.
clickLinkById (line 1062)

Follows a link by id attribute.

  • return: Page on success.
  • access: public
string/boolean clickLinkById (string $id)
  • string $id: ID attribute value.
clickSubmit (line 853)

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

  • return: Page on success.
  • access: public
string/boolean clickSubmit ([string $label = 'Submit'], [hash $additional = false])
  • string $label: Button label. An unlabeled button can be triggered by 'Submit'.
  • hash $additional: Additional form data.
clickSubmitById (line 889)

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

  • return: Page on success.
  • access: public
string/boolean clickSubmitById (string $id, [hash $additional = false])
  • string $id: Button ID.
  • hash $additional: Additional form data.
clickSubmitByName (line 871)

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

  • return: Page on success.
  • access: public
string/boolean clickSubmitByName (string $name, [hash $additional = false])
  • string $name: Button name.
  • hash $additional: Additional form data.
forward (line 562)

Equivalent to hitting the forward button on the browser. The browser history is unchanged on failure. The page content is refetched as there is no concept of content caching in SimpleTest.

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

Fetches the page content with a simple GET request.

  • return: Content of page or false.
  • access: public
string get (string/SimpleUrl $url, [hash/SimpleFormEncoding $parameters = false])
  • string/SimpleUrl $url: Target to fetch.
  • hash/SimpleFormEncoding $parameters: Additional parameters for GET request.
getAuthentication (line 683)

Accessor for last Authentication type. Only valid straight after a challenge (401).

  • return: Description of challenge type.
  • access: public
string getAuthentication ()
getBaseUrl (line 712)

Accessor for base URL of page if set via BASE tag

  • return: base URL
string getBaseUrl ()
getContent (line 740)

Accessor for raw page information.

  • return: Original text content of web page.
  • access: public
string getContent ()
getContentAsText (line 749)

Accessor for plain text version of the page.

  • return: Normalised text representation.
  • access: public
string getContentAsText ()
getCookieValue (line 397)

Reads the most specific cookie value from the browser cookies.

  • return: False if not present, else the value as a string.
  • access: public
string getCookieValue (string $host, string $path, string $name)
  • string $host: Host to search.
  • string $path: Applicable path.
  • string $name: Name of cookie to read.
getCurrentCookieValue (line 408)

Reads the current cookies for the current URL.

  • return: Null if there is no current URL, false if the cookie is not set.
  • access: public
string getCurrentCookieValue (string $name)
  • string $name: Key of cookie to find.
getField (line 815)

Accessor for a form element value within the page.

Finds the first match.

  • return: A value if the field is present, false if unchecked and null if missing.
  • access: public
string/boolean getField (string $label)
  • string $label: Field label.
getFieldById (line 840)

Accessor for a form element value within the page.

  • return: A string if the field is present, false if unchecked and null if missing.
  • access: public
string/boolean getFieldById (string/integer $id)
  • string/integer $id: Id of field in forms.
getFieldByName (line 828)

Accessor for a form element value within the page.

Finds the first match.

  • return: A string if the field is present, false if unchecked and null if missing.
  • access: public
string/boolean getFieldByName (string $name)
  • string $name: Field name.
getFrameFocus (line 617)

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 ()
getFrames (line 605)

Accessor for a breakdown of the frameset.

  • return: Hash tree of frames by name or index if no name.
  • access: public
array getFrames ()
getHeaders (line 731)

Accessor for raw header information.

  • return: Header block.
  • access: public
string getHeaders ()
getLink (line 1016)

Finds a URL by label. Will find the first link found with this link text by default, or a later one if an index is given. The match ignores case and white space issues.

  • return: URL on success.
  • access: public
string/boolean getLink (string $label, integer $index)
  • string $label: Text between the anchor tags.
  • integer $index: Link position counting from zero.
getLinkById (line 1052)

Finds a link by id attribute.

  • return: URL on success.
  • access: public
string/boolean getLinkById (string $id)
  • string $id: ID attribute value.
getMimeType (line 664)

Accessor for current MIME type.

  • return: MIME type as string; e.g. 'text/html'
  • access: public
string getMimeType ()
getRealm (line 693)

Accessor for last Authentication realm. Only valid straight after a challenge (401).

  • return: Name of security realm.
  • access: public
string getRealm ()
getRequest (line 722)

Accessor for raw bytes sent down the wire.

  • return: Original text sent.
  • access: public
string getRequest ()
getResponseCode (line 673)

Accessor for last response code.

  • return: Last HTTP response code received.
  • access: public
integer getResponseCode ()
getTitle (line 758)

Accessor for parsed title.

  • return: Title or false if no title is present.
  • access: public
string getTitle ()
getTransportError (line 655)

Accessor for last error.

  • return: Error from last response.
  • access: public
string getTransportError ()
getUrl (line 703)

Accessor for current URL of page or frame if focused.

  • return: Location of current page or frame as a string.
string getUrl ()
getUrls (line 768)

Accessor for a list of all links in current page.

  • return: List of urls with scheme of http or https and hostname.
  • access: public
array getUrls ()
head (line 463)

Fetches the page content with a HEAD request.

Will affect cookies, but will not change the base URL.

  • return: True if successful.
  • access: public
boolean head (string/SimpleUrl $url, [hash/SimpleHeadEncoding $parameters = false])
  • string/SimpleUrl $url: Target to fetch as string.
  • hash/SimpleHeadEncoding $parameters: Additional parameters for HEAD request.
ignoreCookies (line 228)

Switches off cookie sending and recieving.

  • access: public
void ignoreCookies ()
ignoreFrames (line 211)

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

  • access: public
void ignoreFrames ()
isClickable (line 1094)

Tests to see if a click target exists.

  • return: True if target present.
  • access: public
boolean isClickable (string $label)
  • string $label: Visible text or alt text.
isImage (line 985)

Tests to see if an image exists with this title or alt text.

  • return: True if present.
  • access: public
boolean isImage (string $label)
  • string $label: Image text.
isSubmit (line 906)

Tests to see if a submit button exists with this label.

  • return: True if present.
  • access: public
boolean isSubmit (string $label)
  • string $label: Button label.
post (line 499)

Fetches the page content with a POST request.

  • return: Content of page.
  • access: public
string post (string/SimpleUrl $url, [hash/SimpleFormEncoding $parameters = false])
  • string/SimpleUrl $url: Target to fetch as string.
  • hash/SimpleFormEncoding $parameters: POST parameters.
restart (line 350)

Removes expired and temporary cookies as if the browser was closed and re-opened.

  • access: public
void restart ([string/integer $date = false])
  • string/integer $date: Time when session restarted. If omitted then all persistent cookies are kept.
retry (line 517)

Equivalent to hitting the retry button on the browser. Will attempt to repeat the page fetch. If there is no history to repeat it will give false.

  • return: Content if fetch succeeded else false.
  • access: public
string/boolean retry ()
setConnectionTimeout (line 437)

Sets the socket timeout for opening a connection.

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

Sets an additional cookie. If a cookie has the same name and path it is replaced.

  • access: public
void setCookie (string $name, string $value, [string $host = false], [string $path = '/'], [string $expiry = false])
  • string $name: Cookie key.
  • string $value: Value of cookie.
  • string $host: Host upon which the cookie is valid.
  • string $path: Cookie path if not host wide.
  • string $expiry: Expiry date.
setField (line 779)

Sets all form fields with that name.

  • return: True if field exists, otherwise false.
  • access: public
boolean setField (string $label, string $value, [ $position = false])
  • string $label: Name or label of field in forms.
  • string $value: New value of field.
  • $position
setFieldById (line 802)

Sets all form fields with that id attribute.

  • 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.
setFieldByName (line 791)

Sets all form fields with that name. Will use label if one is available (not yet implemented).

  • return: True if field exists, otherwise false.
  • access: public
boolean setFieldByName (string $name, string $value, [ $position = false])
  • string $name: Name of field in forms.
  • string $value: New value of field.
  • $position
setFrameFocus (line 637)

Sets the focus by name.

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

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.
setMaximumNestedFrames (line 428)

Sets the maximum number of nesting of framed pages within a framed page to prevent loops.

  • access: public
void setMaximumNestedFrames (integer $max)
  • integer $max: Highest depth allowed.
setMaximumRedirects (line 418)

Sets the maximum number of redirects before a page will be loaded anyway.

  • access: public
void setMaximumRedirects (integer $max)
  • integer $max: Most hops allowed.
submitFormById (line 996)

Submits a form by the ID.

  • return: Page on success.
  • access: public
string/boolean submitFormById (string $id)
  • string $id: The form ID. No submit button value will be sent.
useCookies (line 236)

Switches back on the cookie sending and recieving.

  • access: public
void useCookies ()
useFrames (line 220)

Enables frames support. Frames will be fetched from now on.

  • access: public
void useFrames ()
useProxy (line 450)

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.
_buildPage (line 269)

Assembles the parsing machinery and actually parses a single page. Frees all of the builder memory and so unjams the PHP memory management.

  • return: Parsed top level page.
  • access: protected
SimplePage &_buildPage (SimpleHttpResponse $response)
_createHistory (line 201)

Creates a new empty history list.

  • return: New list.
  • access: protected
SimpleBrowserHistory &_createHistory ()
_createUserAgent (line 191)

Creates the underlying user agent.

  • return: Content fetcher.
  • access: protected
SimpleFetcher &_createUserAgent ()

Documentation generated on Sun, 04 May 2008 09:21:19 -0500 by phpDocumentor 1.3.0