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 /libraries/pear/simpletest/browser.php (line 169)


	
			
Variable Summary
 mixed $_history
 mixed $_page
 mixed $_user_agent
Method Summary
 SimpleBrowser SimpleBrowser ()
 void addHeader (string $header)
 void ageCookies (integer $interval)
 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)
 boolean forward ()
 string get (string/SimpleUrl $url, [hash $parameters = false])
 array getAbsoluteUrls ()
 string getAuthentication ()
 string getContent ()
 string getCookieValue (string $host, string $path, string $name)
 string getCurrentCookieValue (string $name)
 string/boolean getField (string $name)
 string/boolean getFieldById (string/integer $id)
 integer/string/boolean getFrameFocus ()
 array getFrames ()
 string getHeaders ()
 string getMimeType ()
 string getRealm ()
 array getRelativeUrls ()
 string getRequest ()
 integer getResponseCode ()
 string getTitle ()
 string getTransportError ()
 string getUrl ()
 boolean head (string/SimpleUrl $url, [hash $parameters = false])
 void ignoreFrames ()
 boolean isLink (string $label)
 boolean isLinkById (string $id)
 string post (string/SimpleUrl $url, [hash $parameters = false])
 void restartSession ([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 $name, string $value)
 boolean setFieldById (string/integer $id, string $value)
 boolean setFrameFocus (string $name)
 boolean setFrameFocusByIndex (integer $choice)
 void setMaximumRedirects (integer $max)
 boolean submitFormById (string $id)
 void useFrames ()
 void useProxy (string $proxy, [string $username = false], [string $password = false])
 SimpleFetcher &_createUserAgent ()
 SimplePage &_fetch (string $method, string/SimpleUrl $url, hash $parameters)
 string _load (string $method, string/SimpleUrl $url, [hash $parameters = false])
 string _loadFrame (array $frames, string $method, string/SimpleUrl $url, [hash $parameters = false])
 string _loadPage (string $method, string/SimpleUrl $url, [hash $parameters = false])
Variables
mixed $_history (line 172)
mixed $_ignore_frames (line 173)
mixed $_page (line 171)
mixed $_user_agent (line 170)
Methods
Constructor SimpleBrowser (line 182)

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

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

Ages the cookies by the specified time.

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

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

Equivalent to hitting the back button on the browser. The browser history is unchanged on failure.

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

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

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

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: ID attribute of button.
  • integer $x: X-coordinate of imaginary click.
  • integer $y: Y-coordinate of imaginary click.
clickImageById (line 883)

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

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

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: 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 948)

Follows a link by id attribute.

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

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

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

  • return: True on success.
  • access: public
boolean clickSubmitById (string $id)
  • string $id: Button ID.
clickSubmitByName (line 801)

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: Button name.
forward (line 528)

Equivalent to hitting the forward button on the browser. The browser history is unchanged on failure.

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

Fetches the page content with a simple GET request.

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

Accessor for a list of all fixed links in current page.

  • return: List of urls with scheme of http or https and hostname.
  • access: public
array getAbsoluteUrls ()
getAuthentication (line 649)

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

  • return: Description of challenge type.
  • access: public
string getAuthentication ()
getContent (line 688)

Accessor for raw page information.

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

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

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

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 getField (string $name)
  • string $name: Field name.
getFieldById (line 772)

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.
getFrameFocus (line 583)

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

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

Accessor for raw header information.

  • return: Header block.
  • access: public
string getHeaders ()
getMimeType (line 630)

Accessor for current MIME type.

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

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

  • return: Name of security realm.
  • access: public
string getRealm ()
getRelativeUrls (line 725)

Accessor for a list of all relative links.

  • return: List of urls without hostname.
  • access: public
array getRelativeUrls ()
getRequest (line 679)

Accessor for raw bytes sent down the wire.

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

Accessor for last response code.

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

Accessor for parsed title.

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

Accessor for last error.

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

Accessor for current URL of page or frame if focused.

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

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 $parameters = false])
  • string/SimpleUrl $url: Target to fetch as string.
  • hash $parameters: Additional parameters for GET request.
ignoreFrames (line 216)

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

  • access: public
void ignoreFrames ()
isLink (line 938)

Tests to see if a link is present by label.

  • return: True if link present.
  • access: public
boolean isLink (string $label)
  • string $label: Text of value attribute.
isLinkById (line 962)

Tests to see if a link is present by ID attribute.

  • return: True if link present.
  • access: public
boolean isLinkById (string $id)
  • string $id: Text of id attribute.
post (line 463)

Fetches the page content with a POST request.

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

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

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

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

Sets the socket timeout for opening a connection.

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

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

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

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

Sets the focus by name.

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

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

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

Submits a form by the ID.

  • return: True on success.
  • access: public
boolean submitFormById (string $id)
  • string $id: The form ID. No submit button value will be sent.
useFrames (line 225)

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

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

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.
_createHistory (line 207)

Creates a new empty history list.

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

Creates the underlying user agent.

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

Fetches a page.

  • return: Parsed page.
  • access: private
SimplePage &_fetch (string $method, string/SimpleUrl $url, hash $parameters)
  • string $method: GET or POST.
  • string/SimpleUrl $url: Target to fetch as string.
  • hash $parameters: POST parameters.
_load (line 275)

Fetches a page or a single frame if that is the current focus.

  • return: Raw content of page.
  • access: private
string _load (string $method, string/SimpleUrl $url, [hash $parameters = false])
  • string $method: GET or POST.
  • string/SimpleUrl $url: Target to fetch as string.
  • hash $parameters: POST parameters.
_loadFrame (line 310)

Fetches a frame into the existing frameset replacing the original.

  • return: Raw content of page.
  • access: private
string _loadFrame (array $frames, string $method, string/SimpleUrl $url, [hash $parameters = false])
  • array $frames: List of names to drill down.
  • string $method: GET or POST.
  • string/SimpleUrl $url: Target to fetch as string.
  • hash $parameters: POST parameters.
_loadPage (line 291)

Fetches a page and makes it the current page/frame.

  • return: Raw content of page.
  • access: private
string _loadPage (string $method, string/SimpleUrl $url, [hash $parameters = false])
  • string $method: GET or POST.
  • string/SimpleUrl $url: Target to fetch as string.
  • hash $parameters: POST parameters.
_parse (line 236)

Parses the raw content into a page. Will load further frame pages unless frames are disabled.

  • return: Parsed HTML.
  • access: protected
SimplePage &_parse (SimpleHttpResponse $response)

Documentation generated on Fri, 11 Feb 2005 18:12:46 +0000 by phpDocumentor 1.3.0RC3