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 getBaseCookieValue (string $name)
 string getContent ()
 string getCookieValue (string $host, string $path, string $name)
 string/boolean getField (string $name)
 string/boolean getFieldById (string/integer $id)
 integer/string/boolean getFrameFocus ()
 string getHeaders ()
 string getMimeType ()
 string getRealm ()
 array getRelativeUrls ()
 string getRequest ()
 integer getResponseCode ()
 string getTitle ()
 string getTransportError ()
 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, boolean $add_to_history)
 string _getAction (SimpleForm &$form)
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 291)

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

Ages the cookies by the specified time.

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

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

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

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

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

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

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

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

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

Follows a link by id attribute.

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

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

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

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

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

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

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

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

  • return: Description of challenge type.
  • access: public
string getAuthentication ()
getBaseCookieValue (line 339)

Reads the current cookies for the base URL.

  • return: Null if there is no base URL, false if the cookie is not set.
  • access: public
string getBaseCookieValue (string $name)
  • string $name: Key of cookie to find.
getContent (line 598)

Accessor for raw page information.

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

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.
getField (line 670)

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

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

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 ()
getHeaders (line 607)

Accessor for raw header information.

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

Accessor for current MIME type.

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

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

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

Accessor for a list of all relative links.

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

Accessor for raw bytes sent down the wire.

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

Accessor for last response code.

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

Accessor for parsed title.

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

Accessor for last error.

  • return: Error from last response.
  • access: public
string getTransportError ()
head (line 383)

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

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

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

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

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

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

Sets the socket timeout for opening a connection.

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

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

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

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

Sets the focus by name.

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

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

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

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

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

Fetches a page.

  • return: Parsed page.
  • access: private
SimplePage &_fetch (string $method, string/SimpleUrl $url, hash $parameters, boolean $add_to_history)
  • string $method: GET or POST.
  • string/SimpleUrl $url: Target to fetch as string.
  • hash $parameters: POST parameters.
  • boolean $add_to_history: Whether to record in the history.
_getAction (line 805)

Replaces missing form action.

  • return: URL to send results to.
  • access: private
string _getAction (SimpleForm &$form)
_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, 3 Dec 2004 12:26:14 +0000 by phpDocumentor 1.3.0RC3