Moodle  2.2.1
http://www.collinsharper.com
SimpleBrowser Class Reference

Public Member Functions

 SimpleBrowser ()
_createUserAgent ()
_createHistory ()
 ignoreFrames ()
 useFrames ()
 ignoreCookies ()
 useCookies ()
_parse ($response, $depth=0)
_buildPage ($response)
_fetch ($url, $encoding, $depth=0)
 _load ($url, $parameters)
 _loadPage ($url, $parameters)
 _loadFrame ($frames, $url, $parameters)
 restart ($date=false)
 addHeader ($header)
 ageCookies ($interval)
 setCookie ($name, $value, $host=false, $path= '/', $expiry=false)
 getCookieValue ($host, $path, $name)
 getCurrentCookieValue ($name)
 setMaximumRedirects ($max)
 setMaximumNestedFrames ($max)
 setConnectionTimeout ($timeout)
 useProxy ($proxy, $username=false, $password=false)
 head ($url, $parameters=false)
 get ($url, $parameters=false)
 post ($url, $parameters=false)
 retry ()
 back ()
 forward ()
 authenticate ($username, $password)
 getFrames ()
 getFrameFocus ()
 setFrameFocusByIndex ($choice)
 setFrameFocus ($name)
 clearFrameFocus ()
 getTransportError ()
 getMimeType ()
 getResponseCode ()
 getAuthentication ()
 getRealm ()
 getUrl ()
 getBaseUrl ()
 getRequest ()
 getHeaders ()
 getContent ()
 getContentAsText ()
 getTitle ()
 getUrls ()
 setField ($label, $value, $position=false)
 setFieldByName ($name, $value, $position=false)
 setFieldById ($id, $value)
 getField ($label)
 getFieldByName ($name)
 getFieldById ($id)
 clickSubmit ($label= 'Submit', $additional=false)
 clickSubmitByName ($name, $additional=false)
 clickSubmitById ($id, $additional=false)
 isSubmit ($label)
 clickImage ($label, $x=1, $y=1, $additional=false)
 clickImageByName ($name, $x=1, $y=1, $additional=false)
 clickImageById ($id, $x=1, $y=1, $additional=false)
 isImage ($label)
 submitFormById ($id)
 getLink ($label, $index=0)
 clickLink ($label, $index=0)
 getLinkById ($id)
 clickLinkById ($id)
 click ($label)
 isClickable ($label)

Data Fields

 $_user_agent
 $_page
 $_history
 $_ignore_frames
 $_maximum_nested_frames

Detailed Description

Definition at line 160 of file browser.php.


Member Function Documentation

& _buildPage ( response)

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

Parameters:
SimpleHttpResponse$responseResponse from fetch.
Returns:
SimplePage Parsed top level page. protected

Definition at line 269 of file browser.php.

Here is the caller graph for this function:

Creates a new empty history list.

Returns:
SimpleBrowserHistory New list. protected

Definition at line 201 of file browser.php.

Here is the caller graph for this function:

Creates the underlying user agent.

Returns:
SimpleFetcher Content fetcher. protected

Definition at line 191 of file browser.php.

Here is the caller graph for this function:

& _fetch ( url,
encoding,
depth = 0 
)

Fetches a page. Jointly recursive with the _parse() method as it descends a frameset.

Parameters:
string/SimpleUrl$url Target to fetch.
SimpleEncoding$encodingGET/POST parameters.
integer$depthNested frameset depth protection.
Returns:
SimplePage Parsed page. private

Definition at line 286 of file browser.php.

Here is the call graph for this function:

Here is the caller graph for this function:

_load ( url,
parameters 
)

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

Parameters:
SimpleUrl$urlTarget to fetch.
SimpleEncoding$parametersGET/POST parameters.
Returns:
string Raw content of page. private

Definition at line 304 of file browser.php.

Here is the call graph for this function:

Here is the caller graph for this function:

_loadFrame ( frames,
url,
parameters 
)

Fetches a frame into the existing frameset replacing the original.

Parameters:
array$framesList of names to drill down.
string/SimpleUrl$url Target to fetch as string.
SimpleFormEncoding$parametersPOST parameters.
Returns:
string Raw content of page. private

Definition at line 336 of file browser.php.

Here is the call graph for this function:

Here is the caller graph for this function:

_loadPage ( url,
parameters 
)

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

Parameters:
string/SimpleUrl$url Target to fetch as string.
SimplePostEncoding$parametersPOST parameters.
Returns:
string Raw content of page. private

Definition at line 319 of file browser.php.

Here is the call graph for this function:

Here is the caller graph for this function:

& _parse ( response,
depth = 0 
)

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

Parameters:
SimpleHttpResponse$responseResponse from fetch.
integer$depthNested frameset depth.
Returns:
SimplePage Parsed HTML. private

Definition at line 248 of file browser.php.

Here is the call graph for this function:

Here is the caller graph for this function:

addHeader ( header)

Adds a header to every fetch.

Parameters:
string$headerHeader line to add to every request until cleared. public

Definition at line 360 of file browser.php.

ageCookies ( interval)

Ages the cookies by the specified time.

Parameters:
integer$intervalAmount in seconds. public

Definition at line 369 of file browser.php.

authenticate ( username,
password 
)

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

Parameters:
string$usernameUsername for realm.
string$passwordPassword for realm.
Returns:
boolean True if successful fetch. Note that authentication may still have failed. public

Definition at line 583 of file browser.php.

Here is the call graph for this function:

back ( )

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.

Returns:
boolean True if history entry and fetch succeeded public

Definition at line 542 of file browser.php.

Here is the call graph for this function:

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

Definition at line 646 of file browser.php.

click ( label)

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

Parameters:
string$labelVisible text or alt text.
Returns:
string/boolean Raw page or false. public

Definition at line 1077 of file browser.php.

Here is the call graph for this function:

clickImage ( label,
x = 1,
y = 1,
additional = false 
)

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.

Parameters:
string$labelID attribute of button.
integer$xX-coordinate of imaginary click.
integer$yY-coordinate of imaginary click.
hash$additionalAdditional form data.
Returns:
string/boolean Page on success. public

Definition at line 923 of file browser.php.

Here is the call graph for this function:

Here is the caller graph for this function:

clickImageById ( id,
x = 1,
y = 1,
additional = false 
)

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.

Parameters:
integer/string$id ID attribute of button.
integer$xX-coordinate of imaginary click.
integer$yY-coordinate of imaginary click.
hash$additionalAdditional form data.
Returns:
string/boolean Page on success. public

Definition at line 968 of file browser.php.

Here is the call graph for this function:

clickImageByName ( name,
x = 1,
y = 1,
additional = false 
)

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.

Parameters:
string$nameName attribute of button.
integer$xX-coordinate of imaginary click.
integer$yY-coordinate of imaginary click.
hash$additionalAdditional form data.
Returns:
string/boolean Page on success. public

Definition at line 946 of file browser.php.

Here is the call graph for this function:

clickLink ( label,
index = 0 
)

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.

Parameters:
string$labelText between the anchor tags.
integer$indexLink position counting from zero.
Returns:
string/boolean Page on success. public

Definition at line 1037 of file browser.php.

Here is the call graph for this function:

Here is the caller graph for this function:

clickLinkById ( id)

Follows a link by id attribute.

Parameters:
string$idID attribute value.
Returns:
string/boolean Page on success. public

Definition at line 1062 of file browser.php.

Here is the call graph for this function:

clickSubmit ( label = 'Submit',
additional = false 
)

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

Parameters:
string$labelButton label. An unlabeled button can be triggered by 'Submit'.
hash$additionalAdditional form data.
Returns:
string/boolean Page on success. public

Definition at line 853 of file browser.php.

Here is the call graph for this function:

Here is the caller graph for this function:

clickSubmitById ( id,
additional = false 
)

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

Parameters:
string$idButton ID.
hash$additionalAdditional form data.
Returns:
string/boolean Page on success. public

Definition at line 889 of file browser.php.

Here is the call graph for this function:

clickSubmitByName ( name,
additional = false 
)

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

Parameters:
string$nameButton name.
hash$additionalAdditional form data.
Returns:
string/boolean Page on success. public

Definition at line 871 of file browser.php.

Here is the call graph for this function:

forward ( )

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.

Returns:
boolean True if history entry and fetch succeeded public

Definition at line 562 of file browser.php.

Here is the call graph for this function:

get ( url,
parameters = false 
)

Fetches the page content with a simple GET request.

Parameters:
string/SimpleUrl$url Target to fetch.
hash/SimpleFormEncoding$parameters Additional parameters for GET request.
Returns:
string Content of page or false. public

Definition at line 482 of file browser.php.

Here is the call graph for this function:

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

Returns:
string Description of challenge type. public

Definition at line 683 of file browser.php.

Accessor for base URL of page if set via BASE tag

Returns:
string base URL

Definition at line 712 of file browser.php.

Accessor for raw page information.

Returns:
string Original text content of web page. public

Definition at line 740 of file browser.php.

Here is the caller graph for this function:

Accessor for plain text version of the page.

Returns:
string Normalised text representation. public

Definition at line 749 of file browser.php.

getCookieValue ( host,
path,
name 
)

Reads the most specific cookie value from the browser cookies.

Parameters:
string$hostHost to search.
string$pathApplicable path.
string$nameName of cookie to read.
Returns:
string False if not present, else the value as a string. public

Definition at line 397 of file browser.php.

getCurrentCookieValue ( name)

Reads the current cookies for the current URL.

Parameters:
string$nameKey of cookie to find.
Returns:
string Null if there is no current URL, false if the cookie is not set. public

Definition at line 408 of file browser.php.

getField ( label)

Accessor for a form element value within the page. Finds the first match.

Parameters:
string$labelField label.
Returns:
string/boolean A value if the field is present, false if unchecked and null if missing. public

Definition at line 815 of file browser.php.

getFieldById ( id)

Accessor for a form element value within the page.

Parameters:
string/integer$id Id of field in forms.
Returns:
string/boolean A string if the field is present, false if unchecked and null if missing. public

Definition at line 840 of file browser.php.

getFieldByName ( name)

Accessor for a form element value within the page. Finds the first match.

Parameters:
string$nameField name.
Returns:
string/boolean A string if the field is present, false if unchecked and null if missing. public

Definition at line 828 of file browser.php.

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

Returns:
integer/string/boolean Label if any, otherwise the position in the frameset or false if none. public

Definition at line 617 of file browser.php.

getFrames ( )

Accessor for a breakdown of the frameset.

Returns:
array Hash tree of frames by name or index if no name. public

Definition at line 605 of file browser.php.

Accessor for raw header information.

Returns:
string Header block. public

Definition at line 731 of file browser.php.

getLink ( label,
index = 0 
)

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.

Parameters:
string$labelText between the anchor tags.
integer$indexLink position counting from zero.
Returns:
string/boolean URL on success. public

Definition at line 1016 of file browser.php.

Here is the caller graph for this function:

getLinkById ( id)

Finds a link by id attribute.

Parameters:
string$idID attribute value.
Returns:
string/boolean URL on success. public

Definition at line 1052 of file browser.php.

Here is the caller graph for this function:

Accessor for current MIME type.

Returns:
string MIME type as string; e.g. 'text/html' public

Definition at line 664 of file browser.php.

getRealm ( )

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

Returns:
string Name of security realm. public

Definition at line 693 of file browser.php.

Accessor for raw bytes sent down the wire.

Returns:
string Original text sent. public

Definition at line 722 of file browser.php.

Accessor for last response code.

Returns:
integer Last HTTP response code received. public

Definition at line 673 of file browser.php.

getTitle ( )

Accessor for parsed title.

Returns:
string Title or false if no title is present. public

Definition at line 758 of file browser.php.

Accessor for last error.

Returns:
string Error from last response. public

Definition at line 655 of file browser.php.

getUrl ( )

Accessor for current URL of page or frame if focused.

Returns:
string Location of current page or frame as a string.

Definition at line 703 of file browser.php.

Here is the caller graph for this function:

getUrls ( )

Accessor for a list of all links in current page.

Returns:
array List of urls with scheme of http or https and hostname. public

Definition at line 768 of file browser.php.

head ( url,
parameters = false 
)

Fetches the page content with a HEAD request. Will affect cookies, but will not change the base URL.

Parameters:
string/SimpleUrl$url Target to fetch as string.
hash/SimpleHeadEncoding$parameters Additional parameters for HEAD request.
Returns:
boolean True if successful. public

Definition at line 463 of file browser.php.

Here is the call graph for this function:

Switches off cookie sending and recieving. public

Definition at line 228 of file browser.php.

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

Definition at line 211 of file browser.php.

isClickable ( label)

Tests to see if a click target exists.

Parameters:
string$labelVisible text or alt text.
Returns:
boolean True if target present. public

Definition at line 1094 of file browser.php.

Here is the call graph for this function:

isImage ( label)

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

Parameters:
string$labelImage text.
Returns:
boolean True if present. public

Definition at line 985 of file browser.php.

Here is the caller graph for this function:

isSubmit ( label)

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

Parameters:
string$labelButton label.
Returns:
boolean True if present. public

Definition at line 906 of file browser.php.

Here is the caller graph for this function:

post ( url,
parameters = false 
)

Fetches the page content with a POST request.

Parameters:
string/SimpleUrl$url Target to fetch as string.
hash/SimpleFormEncoding$parameters POST parameters.
Returns:
string Content of page. public

Definition at line 499 of file browser.php.

Here is the call graph for this function:

restart ( date = false)

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

Parameters:
string/integer$date Time when session restarted. If omitted then all persistent cookies are kept. public

Definition at line 350 of file browser.php.

retry ( )

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.

Returns:
string/boolean Content if fetch succeeded else false. public

Definition at line 517 of file browser.php.

Here is the call graph for this function:

Here is the caller graph for this function:

setConnectionTimeout ( timeout)

Sets the socket timeout for opening a connection.

Parameters:
integer$timeoutMaximum time in seconds. public

Definition at line 437 of file browser.php.

setCookie ( name,
value,
host = false,
path = '/',
expiry = false 
)

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

Parameters:
string$nameCookie key.
string$valueValue of cookie.
string$hostHost upon which the cookie is valid.
string$pathCookie path if not host wide.
string$expiryExpiry date. public

Definition at line 383 of file browser.php.

setField ( label,
value,
position = false 
)

Sets all form fields with that name.

Parameters:
string$labelName or label of field in forms.
string$valueNew value of field.
Returns:
boolean True if field exists, otherwise false. public

Definition at line 779 of file browser.php.

setFieldById ( id,
value 
)

Sets all form fields with that id attribute.

Parameters:
string/integer$id Id of field in forms.
string$valueNew value of field.
Returns:
boolean True if field exists, otherwise false. public

Definition at line 802 of file browser.php.

setFieldByName ( name,
value,
position = false 
)

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

Parameters:
string$nameName of field in forms.
string$valueNew value of field.
Returns:
boolean True if field exists, otherwise false. public

Definition at line 791 of file browser.php.

setFrameFocus ( name)

Sets the focus by name.

Parameters:
string$nameChosen frame.
Returns:
boolean True if frame exists. public

Definition at line 637 of file browser.php.

setFrameFocusByIndex ( choice)

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

Parameters:
integer$choiceChosen frame.
Returns:
boolean True if frame exists. public

Definition at line 627 of file browser.php.

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

Parameters:
integer$maxHighest depth allowed. public

Definition at line 428 of file browser.php.

setMaximumRedirects ( max)

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

Parameters:
integer$maxMost hops allowed. public

Definition at line 418 of file browser.php.

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. public

Definition at line 174 of file browser.php.

Here is the call graph for this function:

submitFormById ( id)

Submits a form by the ID.

Parameters:
string$idThe form ID. No submit button value will be sent.
Returns:
string/boolean Page on success. public

Definition at line 996 of file browser.php.

Here is the call graph for this function:

Switches back on the cookie sending and recieving. public

Definition at line 236 of file browser.php.

useFrames ( )

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

Definition at line 220 of file browser.php.

useProxy ( proxy,
username = false,
password = false 
)

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

Parameters:
string$proxyProxy URL.
string$usernameProxy username for authentication.
string$passwordProxy password for authentication. public

Definition at line 450 of file browser.php.


Field Documentation

$_history

Definition at line 163 of file browser.php.

$_ignore_frames

Definition at line 164 of file browser.php.

$_maximum_nested_frames

Definition at line 165 of file browser.php.

$_page

Definition at line 162 of file browser.php.

$_user_agent

Definition at line 161 of file browser.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations