FunctionalTest
class FunctionalTest extends SapphireTest
SilverStripe-specific testing object designed to support functional testing of your web app. It simulates get/post requests, form submission, and can validate resulting HTML, looking up content by CSS selector.
The example below shows how it works.
public function testMyForm() {
// Visit a URL
$this->get("your/url");
// Submit a form on the page that you get in response
$this->submitForm("MyForm_ID", "action_dologin", array("Email" => "invalid email ^&*&^"));
// Validate the content that is returned
$this->assertExactMatchBySelector("#MyForm_ID p.error", array("That email address is invalid."));
}
Methods
Determines if unit tests are currently run (via {@link TestRunner}).
Set the manifest to be used to look up test classes by helper functions
Return the manifest being used to look up test classes by helper functions
No description
tearDown method that's called once per test class rather once per test method.
Clear all fixtures which were previously loaded through {@link loadFixture()}
No description
No description
No description
Search for an email that was sent.
Assert that the matching email was sent since the last call to clearEmails() All of the parameters can either be a string, or, if they start with "/", a PREG-compatible regular expression.
Assert that the given {@link SS_List} includes DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record.
Assert that the given {@link SS_List} includes only DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record.
Assert that the every record in the given {@link SS_List} matches the given key-value pairs.
Asserts that two SQL queries are equivalent
Asserts that a SQL query contains a SQL fragment
Asserts that a SQL query contains a SQL fragment
Returns true if we are currently using a temporary database
Reset the testing database's schema.
Create a member and group with the given permission code, and log in with it.
Submit the form with the given HTML ID, filling it out with the given data.
Return the most recent content
Find an attribute in a SimpleXMLElement object by name.
Return a CSSContentParser for the most recent content.
Assert that the most recently queried page contains a number of content tags specified by a CSS selector.
Assert that the most recently queried page contains a number of content tags specified by a CSS selector.
Assert that the most recently queried page contains a number of content tags specified by a CSS selector.
Assert that the most recently queried page contains a number of content tags specified by a CSS selector.
Log in as the given member
Use the draft (stage) site for testing.
Return a static variable from this class.
No description
No description
Details
in SapphireTest at line 135
static boolean
is_running_test()
Determines if unit tests are currently run (via {@link TestRunner}).
This is used as a cheap replacement for fully mockable state in certain contiditions (e.g. access checks). Caution: When set to FALSE, certain controllers might bypass access checks, so this is a very security sensitive setting.
in SapphireTest at line 139
static
set_is_running_test($bool)
in SapphireTest at line 146
static
set_test_class_manifest($manifest)
Set the manifest to be used to look up test classes by helper functions
in SapphireTest at line 153
static
get_test_class_manifest()
Return the manifest being used to look up test classes by helper functions
in SapphireTest at line 160
static String
get_fixture_file()
at line 77
setUp()
in SapphireTest at line 302
setUpOnce()
Called once per test case ({@link SapphireTest} subclass).
This is different to {@link setUp()}, which gets called once per method. Useful to initialize expensive operations which don't change state for any called method inside the test, e.g. dynamically adding an extension. See {@link tearDownOnce()} for tearing down the state again.
in SapphireTest at line 354
tearDownOnce()
tearDown method that's called once per test class rather once per test method.
in SapphireTest at line 389
FixtureFactory
getFixtureFactory()
in SapphireTest at line 394
setFixtureFactory(FixtureFactory $factory)
in SapphireTest at line 460
loadFixture($fixtureFile)
Load a YAML fixture file into the database.
Once loaded, you can use idFromFixture() and objFromFixture() to get items from the fixture. Doesn't clear existing fixtures.
in SapphireTest at line 470
clearFixtures()
Clear all fixtures which were previously loaded through {@link loadFixture()}
at line 102
tearDown()
in SapphireTest at line 535
static
assertContains($needle, $haystack, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE, $checkForNonObjectIdentity = false)
in SapphireTest at line 547
static
assertNotContains($needle, $haystack, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE, $checkForNonObjectIdentity = false)
in SapphireTest at line 562
clearEmails()
Clear the log of emails sent
in SapphireTest at line 576
array
findEmail($to, $from = null, $subject = null, $content = null)
Search for an email that was sent.
All of the parameters can either be a string, or, if they start with "/", a PREG-compatible regular expression.
in SapphireTest at line 590
array
assertEmailSent($to, $from = null, $subject = null, $content = null)
Assert that the matching email was sent since the last call to clearEmails() All of the parameters can either be a string, or, if they start with "/", a PREG-compatible regular expression.
in SapphireTest at line 628
assertDOSContains($matches, $dataObjectSet)
Assert that the given {@link SS_List} includes DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record.
in SapphireTest at line 670
assertDOSEquals($matches, $dataObjectSet)
Assert that the given {@link SS_List} includes only DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record.
in SapphireTest at line 717
assertDOSAllMatch($match, $dataObjectSet)
Assert that the every record in the given {@link SS_List} matches the given key-value pairs.
in SapphireTest at line 752
assertSQLEquals(string $expectedSQL, string $actualSQL, string $message = '', float $delta, integer $maxDepth = 10, boolean $canonicalize = false, boolean $ignoreCase = false)
Asserts that two SQL queries are equivalent
in SapphireTest at line 771
assertSQLContains(string $needleSQL, string $haystackSQL, string $message = '', boolean $ignoreCase = false, boolean $checkForObjectIdentity = true)
Asserts that a SQL query contains a SQL fragment
in SapphireTest at line 789
assertSQLNotContains(string $needleSQL, string $haystackSQL, string $message = '', boolean $ignoreCase = false, boolean $checkForObjectIdentity = true)
Asserts that a SQL query contains a SQL fragment
in SapphireTest at line 819
static
using_temp_db()
Returns true if we are currently using a temporary database
in SapphireTest at line 826
static
kill_temp_db()
in SapphireTest at line 848
static
empty_temp_db()
Remove all content from the temporary database.
in SapphireTest at line 862
static
create_temp_db()
in SapphireTest at line 888
static
delete_all_temp_dbs()
in SapphireTest at line 907
resetDBSchema($includeExtraDataObjects = false)
Reset the testing database's schema.
in SapphireTest at line 947
logInWithPermission($permCode = "ADMIN")
Create a member and group with the given permission code, and log in with it.
Returns the member ID.
at line 73
Session
session()
Returns the {@link Session} object for this test
at line 147
SS_HTTPResponse
get(string $url, Session $session = null, array $headers = null, array $cookies = null)
Submit a get request
at line 168
SS_HTTPResponse
post(string $url, array $data, array $headers = null, Session $session = null, string $body = null, array $cookies = null)
Submit a post request
at line 196
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')
at line 210
string
content()
Return the most recent content
at line 220
SimpleXMLElement
findAttribute(SimpleXMLElement $object, string $attribute)
Find an attribute in a SimpleXMLElement object by name.
at line 235
CSSContentParser
cssParser()
Return a CSSContentParser for the most recent content.
at line 252
boolean
assertPartialMatchBySelector(string $selector, array|string $expectedMatches)
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.
Note: characters are stripped from the content; make sure that your assertions take this into account.
at line 285
boolean
assertExactMatchBySelector(string $selector, array|string $expectedMatches)
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.
Note: characters are stripped from the content; make sure that your assertions take this into account.
at line 315
boolean
assertPartialHTMLMatchBySelector(string $selector, array|string $expectedMatches)
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.
Note: characters are stripped from the content; make sure that your assertions take this into account.
at line 347
boolean
assertExactHTMLMatchBySelector(string $selector, array|string $expectedMatches)
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.
Note: characters are stripped from the content; make sure that your assertions take this into account.
at line 365
logInAs($member)
Log in as the given member
at line 380
useDraftSite(bool $enabled = true)
Use the draft (stage) site for testing.
This is helpful if you're not testing publication functionality and don't want "stage management" cluttering your test.
at line 399
mixed
stat(string $varName)
Return a static variable from this class.