class TestSession (View source)

Represents a test usage session of a web-app It will maintain session-state from request to request

Properties

protected Controller $controller

Necessary to use the mock session created in session in the normal controller stack, e.g. to overwrite Member::currentUser() with custom login data.

Methods

public
__construct()

No description

public
__destruct()

No description

public
get(string $url, Session $session = null, array $headers = null, array $cookies = null)

Submit a get request

public
post(string $url, array $data, array $headers = null, Session $session = null, string $body = null, array $cookies = null)

Submit a post request

public
submitForm(string $formID, string $button = null, array $data = array())

Submit the form with the given HTML ID, filling it out with the given data.

public
followRedirection()

If the last request was a 3xx response, then follow the redirection

public
bool
wasRedirected()

Returns true if the last response was a 3xx redirection

public
lastResponse()

Get the most recent response

public
string
lastUrl()

Return the fake HTTP_REFERER; set each time get() or post() is called.

public
string
lastContent()

Get the most recent response's content

public
cssParser()

Return a CSSContentParser containing the most recent response

public
SimplePage
lastPage()

Get the last response as a SimplePage object

public
session()

Get the current session, as a Session object

Details

__construct()

No description

__destruct()

No description

SS_HTTPResponse get(string $url, Session $session = null, array $headers = null, array $cookies = null)

Submit a get request

Parameters

string $url
Session $session
array $headers
array $cookies

Return Value

SS_HTTPResponse

SS_HTTPResponse post(string $url, array $data, array $headers = null, Session $session = null, string $body = null, array $cookies = null)

Submit a post request

Parameters

string $url
array $data
array $headers
Session $session
string $body
array $cookies

Return Value

SS_HTTPResponse

SS_HTTPResponse submitForm(string $formID, string $button = null, array $data = array())

Submit the form with the given HTML ID, filling it out with the given data.

Acts on the most recent response.

Any data parameters have to be present in the form, with exact form field name and values, otherwise they are removed from the submission.

Caution: Parameter names have to be formatted as they are in the form submission, not as they are interpreted by PHP. Wrong: array('mycheckboxvalues' => array(1 => 'one', 2 => 'two')) Right: array('mycheckboxvalues[1]' => 'one', 'mycheckboxvalues[2]' => 'two')

Parameters

string $formID

HTML 'id' attribute of a form (loaded through a previous response)

string $button

HTML 'name' attribute of the button (NOT the 'id' attribute)

array $data

Map of GET/POST data.

Return Value

SS_HTTPResponse

See also

http://www.simpletest.org/en/form_testing_documentation.html

SS_HTTPResponse followRedirection()

If the last request was a 3xx response, then follow the redirection

Return Value

SS_HTTPResponse

The response given, or null if no redirect occurred

bool wasRedirected()

Returns true if the last response was a 3xx redirection

Return Value

bool

SS_HTTPResponse lastResponse()

Get the most recent response

Return Value

SS_HTTPResponse

string lastUrl()

Return the fake HTTP_REFERER; set each time get() or post() is called.

Return Value

string

string lastContent()

Get the most recent response's content

Return Value

string

CSSContentParser cssParser()

Return a CSSContentParser containing the most recent response

Return Value

CSSContentParser

SimplePage lastPage()

Get the last response as a SimplePage object

Return Value

SimplePage

The response if available

Session session()

Get the current session, as a Session object

Return Value

Session