class SapphireTest extends PHPUnit_Framework_TestCase

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.

Config options

dependencies

Methods

static boolean
is_running_test()

Determines if unit tests are currently run (via {@link TestRunner}).

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 ({@link SapphireTest} subclass).

tearDownOnce()

tearDown method that's called once per test class rather once per test method.

setFixtureFactory(FixtureFactory $factory)

No description

loadFixture($fixtureFile)

Load a YAML fixture file into the database.

clearFixtures()

Clear all fixtures which were previously loaded through {@link loadFixture()}

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.

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 {@link 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 {@link 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 {@link SS_List} matches the given key-value pairs.

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

assertSQLContains(string $needleSQL, string $haystackSQL, string $message = '', boolean $ignoreCase = false, boolean $checkForObjectIdentity = true)

Asserts that a SQL query contains a SQL fragment

assertSQLNotContains(string $needleSQL, string $haystackSQL, string $message = '', boolean $ignoreCase = false, boolean $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.

Details

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.

Return Value

boolean

at line 139
static set_is_running_test($bool)

Parameters

$bool

at line 146
static set_test_class_manifest($manifest)

Set the manifest to be used to look up test classes by helper functions

Parameters

$manifest

at line 153
static get_test_class_manifest()

Return the manifest being used to look up test classes by helper functions

at line 160
static String get_fixture_file()

Return Value

String

at line 172
setUp()

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.

at line 354
tearDownOnce()

tearDown method that's called once per test class rather once per test method.

at line 389
FixtureFactory getFixtureFactory()

Return Value

FixtureFactory

at line 394
setFixtureFactory(FixtureFactory $factory)

Parameters

FixtureFactory $factory

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.

Parameters

$fixtureFile The location of the .yml fixture file, relative to the site base dir

at line 470
clearFixtures()

Clear all fixtures which were previously loaded through {@link loadFixture()}

at line 497
tearDown()

at line 535
static assertContains($needle, $haystack, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE, $checkForNonObjectIdentity = false)

Parameters

$needle
$haystack
$message
$ignoreCase
$checkForObjectIdentity
$checkForNonObjectIdentity

at line 547
static assertNotContains($needle, $haystack, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE, $checkForNonObjectIdentity = false)

Parameters

$needle
$haystack
$message
$ignoreCase
$checkForObjectIdentity
$checkForNonObjectIdentity

at line 562
clearEmails()

Clear the log of emails sent

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.

Parameters

$to
$from
$subject
$content

Return Value

array Contains keys: 'type', 'to', 'from', 'subject','content', 'plainContent', 'attachedFiles', 'customHeaders', 'htmlContent', 'inlineImages'

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.

Parameters

$to
$from
$subject
$content

Return Value

array Contains the keys: 'type', 'to', 'from', 'subject', 'content', 'plainContent', 'attachedFiles', 'customHeaders', 'htmlContent', inlineImages'

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.

Parameters

$matches The patterns to match. Each pattern is a map of key-value pairs. You can either pass a single pattern or an array of patterns.
$dataObjectSet The {@link SS_List} to test.

Examples

Check that $members includes an entry with Email = sam@example.com: $this->assertDOSContains(array('Email' => '...@example.com'), $members);

Check that $members includes entries with Email = sam@example.com and with Email = ingo@example.com: $this->assertDOSContains(array( array('Email' => '...@example.com'), array('Email' => 'i...@example.com'), ), $members);

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.

Parameters

$matches The patterns to match. Each pattern is a map of key-value pairs. You can either pass a single pattern or an array of patterns.
$dataObjectSet The {@link SS_List} to test.

Example

Check that only the entries Sam Minnee and Ingo Schommer exist in $members. Order doesn't matter: $this->assertDOSEquals(array( array('FirstName' =>'Sam', 'Surname' => 'Minnee'), array('FirstName' => 'Ingo', 'Surname' => 'Schommer'), ), $members);

at line 717
assertDOSAllMatch($match, $dataObjectSet)

Assert that the every record in the given {@link SS_List} matches the given key-value pairs.

Parameters

$match The pattern to match. The pattern is a map of key-value pairs.
$dataObjectSet The {@link SS_List} to test.

Example

Check that every entry in $members has a Status of 'Active': $this->assertDOSAllMatch(array('Status' => 'Active'), $members);

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

Parameters

string $expectedSQL
string $actualSQL
string $message
float $delta
integer $maxDepth
boolean $canonicalize
boolean $ignoreCase

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

Parameters

string $needleSQL
string $haystackSQL
string $message
boolean $ignoreCase
boolean $checkForObjectIdentity

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

Parameters

string $needleSQL
string $haystackSQL
string $message
boolean $ignoreCase
boolean $checkForObjectIdentity

at line 819
static using_temp_db()

Returns true if we are currently using a temporary database

at line 826
static kill_temp_db()

at line 848
static empty_temp_db()

Remove all content from the temporary database.

at line 862
static create_temp_db()

at line 888
static delete_all_temp_dbs()

at line 907
resetDBSchema($includeExtraDataObjects = false)

Reset the testing database's schema.

Parameters

$includeExtraDataObjects If true, the extraDataObjects tables will also be included

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.

Parameters

$permCode