silverstripe-framework/docs/en/02_Developer_Guides/06_Testing/01_Functional_Testing.md
Michael Pritchard fdbd899766 DOC Update SilverStripe to Silverstripe CMS
- Remaining Developer Guides and Upgrading
- SilverStripe in a namespace or api has not been change
- To keep PRs easier no formatting was changed

Update merge conflics with two files

Update Silverstripe Ltd, Silverstripe Cloud and Silverstripe CMS

Silverstripe CMS Ltd > Silverstripe Ltd
Silverstripe CMS Platform > Silverstripe Cloud
Silverstripe CMS Framework > Silverstripe CMS

Resolve merge conflict

Remove Framework from Silverstripe CMS Framework

- 3 files

Change SilverStripe CMS to Silverstripe CMS
2021-07-30 13:54:15 +01:00

4.1 KiB

title summary
Functional Testing Test controllers, forms and HTTP responses.

Functional Testing

FunctionalTest test your applications Controller logic and anything else which requires a web request. The core idea of these tests is the same as SapphireTest unit tests but FunctionalTest adds several methods for creating HTTPRequest, receiving HTTPResponse objects and modifying the current user session.

Get

$page = $this->get($url);

Performs a GET request on $url and retrieves the HTTPResponse. This also changes the current page to the value of the response.

Post

$page = $this->post($url);

Performs a POST request on $url and retrieves the HTTPResponse. This also changes the current page to the value of the response.

**Compatibility Notice:** Previous versions of Silverstripe CMS would send a GET request if `post()` was called with no POST variables supplied in the second argument. Silverstripe CMS 4.6 and later always sends a POST request for consistency.

Other Requests

$page = $this->sendRequest('PUT', $url);

Performs a request on $url with the HTTP method provided (useful for PUT, PATCH, DELETE, etc.). This also changes the current page to the value of the response.

Submit

$submit = $this->submitForm($formID, $button = null, $data = []);

Submits the given form (#ContactForm) on the current page and returns the HTTPResponse.

LogInAs

$this->logInAs($member);

Logs a given user in, sets the current session. To log all users out pass null to the method.

$this->logInAs(null);

Assertions

The FunctionalTest class also provides additional asserts to validate your tests.

assertPartialMatchBySelector

$this->assertPartialMatchBySelector('p.good',[
    'Test save was successful'
]);

Asserts that the most recently queried page contains a number of content tags specified by a CSS selector. The given CSS selector will be applied to the HTML of the most recent page. The content of every matching tag will be examined. The assertion fails if one of the expectedMatches fails to appear.

assertExactMatchBySelector

$this->assertExactMatchBySelector("#MyForm_ID p.error", [
    "That email address is invalid."
]);

Asserts that the most recently queried page contains a number of content tags specified by a CSS selector. The given CSS selector will be applied to the HTML of the most recent page. The full HTML of every matching tag will be examined. The assertion fails if one of the expectedMatches fails to appear.

assertPartialHTMLMatchBySelector

$this->assertPartialHTMLMatchBySelector("#MyForm_ID p.error", [
    "That email address is invalid."
]);

Assert that the most recently queried page contains a number of content tags specified by a CSS selector. The given CSS selector will be applied to the HTML of the most recent page. The content of every matching tag will be examined. The assertion fails if one of the expectedMatches fails to appear.

[notice]   characters are stripped from the content; make sure that your assertions take this into account. [/notice]

assertExactHTMLMatchBySelector

$this->assertExactHTMLMatchBySelector("#MyForm_ID p.error", [
    "That email address is invalid."
]);

Assert that the most recently queried page contains a number of content tags specified by a CSS selector. The given CSS selector will be applied to the HTML of the most recent page. The full HTML of every matching tag will be examined. The assertion fails if one of the expectedMatches fails to appear.

[notice]   characters are stripped from the content; make sure that your assertions take this into account. [/notice]

API Documentation