SapphireTest
class SapphireTest extends PHPUnit_Framework_TestCase (View source)
Test case class for the Sapphire framework.
Sapphire unit testing is based on PHPUnit, but provides a number of hooks into our data model that make it easier to work with.
Properties
protected static | string|array | $fixture_file | Path to fixture data for this test run. |
|
protected | FixtureFactory | $fixtureFactory | ||
protected | bool | $skipTest | ||
protected | bool | $usesDatabase | ||
protected deprecated | $originalMailer | |||
protected | $originalMemberPasswordValidator | |||
protected | $originalRequirements | |||
protected | $originalIsRunningTest | |||
protected | $originalTheme | |||
protected | $originalNestedURLsState | |||
protected | $originalMemoryLimit | |||
protected | $mailer | |||
protected static | $regular_manifest | Pointer to the manifest that isn't a test manifest |
||
protected static | bool | $is_running_test | ||
protected static | $test_class_manifest | |||
protected | $requireDefaultRecordsFrom | By default, setUp() does not require default records. Pass class names in here, and the require/augment default records function will be called on them. |
||
protected | $illegalExtensions | A list of extensions that can't be applied during the execution of this run. If they are applied, they will be temporarily removed and a database migration called. |
||
protected | $requiredExtensions | A list of extensions that must be applied during the execution of this run. If they are not applied, they will be temporarily added and a database migration called. |
||
protected | $extraDataObjects | By default, the test database won't contain any DataObjects that have the interface TestOnly. |
||
protected | $backupGlobals | We need to disabling backing up of globals to avoid overriding the few globals SilverStripe relies on, like $lang for the i18n subsystem. |
||
protected deprecated | array | $fixtures | ||
protected | $model | |||
protected | $cache_generatedMembers | Cache for logInWithPermission() |
Methods
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
tearDown method that's called once per test class rather once per test method.
Return all of the IDs in the fixture of a particular class name.
Get an object from the fixture.
Useful for writing unit tests without hardcoding folder structures.
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 SS_List includes DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record.
Assert that the given 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 SS_List matches the given key-value pairs.
Removes sequences of repeated whitespace characters from SQL queries making them suitable for string comparison
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
Create a member and group with the given permission code, and log in with it.
Details
static bool
is_running_test()
Determines if unit tests are currently run (via 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.
static
set_is_running_test($bool)
No description
static
set_test_class_manifest($manifest)
Set the manifest to be used to look up test classes by helper functions
static
get_test_class_manifest()
Return the manifest being used to look up test classes by helper functions
static string
get_fixture_file()
No description
setUp()
No description
setUpOnce()
Called once per test case (SapphireTest subclass).
This is different to 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 tearDownOnce() for tearing down the state again.
tearDownOnce()
tearDown method that's called once per test class rather once per test method.
FixtureFactory
getFixtureFactory()
No description
setFixtureFactory(FixtureFactory $factory)
No description
protected int
idFromFixture($className, $identifier)
Get the ID of an object from the fixture.
protected array
allFixtureIDs(string $className)
Return all of the IDs in the fixture of a particular class name.
Will collate all IDs form all fixtures if multiple fixtures are provided.
protected DataObject
objFromFixture(string $className, string $identifier)
Get an object from the fixture.
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.
clearFixtures()
Clear all fixtures which were previously loaded through loadFixture()
protected string
getCurrentAbsolutePath()
Useful for writing unit tests without hardcoding folder structures.
protected string
getCurrentRelativePath()
No description
tearDown()
No description
static
assertContains($needle, $haystack, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE, $checkForNonObjectIdentity = false)
No description
static
assertNotContains($needle, $haystack, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE, $checkForNonObjectIdentity = false)
No description
clearEmails()
Clear the log of emails sent
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.
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.
assertDOSContains($matches, $dataObjectSet)
Assert that the given SS_List includes DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record.
assertDOSEquals($matches, $dataObjectSet)
Assert that the given SS_List includes only DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record.
assertDOSAllMatch($match, $dataObjectSet)
Assert that the every record in the given SS_List matches the given key-value pairs.
protected string
normaliseSQL(string $sql)
Removes sequences of repeated whitespace characters from SQL queries making them suitable for string comparison
assertSQLEquals(string $expectedSQL, string $actualSQL, string $message = '', float $delta = 0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false)
Asserts that two SQL queries are equivalent
assertSQLContains(string $needleSQL, string $haystackSQL, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true)
Asserts that a SQL query contains a SQL fragment
assertSQLNotContains(string $needleSQL, string $haystackSQL, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true)
Asserts that a SQL query contains a SQL fragment
static
using_temp_db()
Returns true if we are currently using a temporary database
static
kill_temp_db()
No description
static
empty_temp_db()
Remove all content from the temporary database.
static
create_temp_db()
No description
static
delete_all_temp_dbs()
No description
resetDBSchema($includeExtraDataObjects = false)
Reset the testing database's schema.
logInWithPermission($permCode = "ADMIN")
Create a member and group with the given permission code, and log in with it.
Returns the member ID.
protected
useTestTheme($themeBaseDir, $theme, $callback)
Test against a theme.