Version: current

# Class SapphireTest

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.

  PHPUnit_Framework_TestCase
  SapphireTest

### Direct known subclasses

`FunctionalTest`

Package: sapphire\testing
Located at sapphire/dev/SapphireTest.php

## Methods summary

`public static` | # `is_running_test( )`
`public` | # `setUp( )`
`public` | # `setUpOnce( )` Called once per test case (`SapphireTest` subclass). This is different to `SapphireTest::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 `SapphireTest::tearDownOnce()` for tearing down the state again. Called once per test case (`SapphireTest` subclass). This is different to `SapphireTest::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 `SapphireTest::tearDownOnce()` for tearing down the state again.
`public` | # `tearDownOnce( )` tearDown method that's called once per test class rather once per test method. tearDown method that's called once per test class rather once per test method.
`protected integer` | # `idFromFixture( mixed $className, mixed $identifier )` Get the ID of an object from the fixture. Get the ID of an object from the fixture. #### Parameters $className $className The data class, as specified in your fixture file. Parent classes won't work $identifier $identifier The identifier string, as provided in your fixture file #### Returns `integer` int
`protected A` | # `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. 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. #### Parameters $className string $className #### Returns `A` map of fixture-identifier => object-id
`protected` | # `objFromFixture( mixed $className, mixed $identifier )` Get an object from the fixture. Get an object from the fixture. #### Parameters $className $className The data class, as specified in your fixture file. Parent classes won't work $identifier $identifier The identifier string, as provided in your fixture file
`public` | # `loadFixture( mixed $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. 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 $fixtureFile The location of the .yml fixture file, relative to the site base dir
`public` | # `clearFixtures( )` Clear all fixtures which were previously loaded through `SapphireTest::loadFixture()`. Clear all fixtures which were previously loaded through `SapphireTest::loadFixture()`.
`public` | # `tearDown( )`
`public` | # `clearEmails( )` Clear the log of emails sent Clear the log of emails sent
`public An` | # `findEmail( mixed $to, mixed $from = null, mixed $subject = null, mixed $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. 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 $to $from $from $subject $subject $content $content #### Returns `An` array containing the keys: 'type','to','from','subject','content', 'plainContent','attachedFiles','customHeaders','htmlContent',inlineImages'
`public An` | # `assertEmailSent( mixed $to, mixed $from = null, mixed $subject = null, mixed $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. 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 $to $from $from $subject $subject $content $content #### Returns `An` array containing the keys: 'type','to','from','subject','content', 'plainContent','attachedFiles','customHeaders','htmlContent',inlineImages'
`public` | # `assertDOSContains( mixed $matches, mixed $dataObjectSet )` Assert that the given `DataObjectSet` includes DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record. Assert that the given `DataObjectSet` includes DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record. #### Parameters $matches $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 $dataObjectSet The `DataObjectSet` 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);
`public` | # `assertDOSEquals( mixed $matches, mixed $dataObjectSet )` Assert that the given `DataObjectSet` includes only DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record. Assert that the given `DataObjectSet` includes only DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record. #### Parameters $matches $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 $dataObjectSet The `DataObjectSet` 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);
`public` | # `assertDOSAllMatch( mixed $match, mixed $dataObjectSet )` Assert that the every record in the given `DataObjectSet` matches the given key-value pairs. Assert that the every record in the given `DataObjectSet` matches the given key-value pairs. #### Parameters $match $match The pattern to match. The pattern is a map of key-value pairs. $dataObjectSet $dataObjectSet The `DataObjectSet` to test. Example -------- Check that every entry in $members has a Status of 'Active': $this->assertDOSAllMatch(array('Status' => 'Active'), $members);
`public static` | # `using_temp_db( )` Returns true if we are currently using a temporary database Returns true if we are currently using a temporary database
`public static` | # `kill_temp_db( )`
`public static` | # `empty_temp_db( )` Remove all content from the temporary database. Remove all content from the temporary database.
`public static` | # `create_temp_db( )`
`public static` | # `delete_all_temp_dbs( )`
`public` | # `resetDBSchema( mixed $includeExtraDataObjects = false )` Reset the testing database's schema. Reset the testing database's schema. #### Parameters $includeExtraDataObjects $includeExtraDataObjects If true, the extraDataObjects tables will also be included
`public` | # `logInWithPermission( mixed $permCode = "ADMIN" )` Create a member and group with the given permission code, and log in with it. Returns the member ID. Create a member and group with the given permission code, and log in with it. Returns the member ID.

### Magic methods summary

## Properties summary

`public static string|array` | $fixture_file | # Path to fixture data for this test run. If passed as an array, multiple fixture files will be loaded. Please note that you won't be able to refer with "=>" notation between the fixtures, they act independent of each other. Path to fixture data for this test run. If passed as an array, multiple fixture files will be loaded. Please note that you won't be able to refer with "=>" notation between the fixtures, they act independent of each other.
`protected mixed` | $originalMailer | #
`protected mixed` | $originalMemberPasswordValidator | #
`protected mixed` | $originalRequirements | #
`protected mixed` | $originalIsRunningTest | #
`protected mixed` | $originalTheme | #
`protected mixed` | $originalNestedURLsState | #
`protected mixed` | $mailer | #
`protected static boolean` | $is_running_test | #
`protected array` | $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. 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 array` | $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. 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. The keys of the are the classes that the extensions can't be applied the extensions to, and the values are an array of illegal extensions on that class.
`protected array` | $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. 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. The keys of the are the classes to apply the extensions to, and the values are an array of illegal required extensions on that class.
`protected array` | $extraDataObjects | # By default, the test database won't contain any DataObjects that have the interface TestOnly. This variable lets you define additional TestOnly DataObjects to set up for this test. Set it to an array of DataObject subclass names. By default, the test database won't contain any DataObjects that have the interface TestOnly. This variable lets you define additional TestOnly DataObjects to set up for this test. Set it to an array of DataObject subclass names.
`protected boolean` | $backupGlobals | # We need to disabling backing up of globals to avoid overriding the few globals SilverStripe relies on, like $lang for the i18n subsystem. We need to disabling backing up of globals to avoid overriding the few globals SilverStripe relies on, like $lang for the i18n subsystem. #### See http://sebastian-bergmann.de/archives/797-Global-Variables-and-PHPUnit.html
`protected array` | $fixtures | # $fixtures Array of `YamlFixture` instances $fixtures Array of `YamlFixture` instances
`protected mixed` | $fixtureDictionary | # Array Array
`protected array` | $cache_generatedMembers | # Cache for logInWithPermission() Cache for logInWithPermission()

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -