class FixtureContext implements Context (View source)

Context used to create fixtures in the SilverStripe ORM.

Traits

Represents a behat context which is aware of a main {SilverStripeContext} context.

Properties

protected SilverStripeContext $mainContext from  MainContextAwareTrait
protected $context
protected FixtureFactory $fixtureFactory
protected string $filesPath
protected TempDatabase $tempDatabase

Temp database helper

protected string $createdFilesPaths
protected array $createdAssets

Methods

public
getMainContext()

Get the main context

public
$this
setMainContext(SilverStripeContext $mainContext)

No description

public
detectMainContext(BeforeScenarioScope $scope)

Helper method to detect the main context

public
__construct(null $filesPath = null)

FixtureContext constructor.

public
FixtureFactory
getFixtureFactory()

No description

protected
FixtureFactory
scaffoldDefaultFixtureFactory()

Build default fixture factory

public
setFixtureFactory(FixtureFactory $factory)

No description

public
setFilesPath($path)

No description

public
string
getFilesPath()

No description

public
TempDatabase
getTempDatabase()

No description

public
$this
setTempDatabase(TempDatabase $database)

No description

public
beforeDatabaseDefaults(BeforeScenarioScope $event)

No description

public
afterResetDatabase(AfterScenarioScope $event)

No description

public
afterResetAssets(AfterScenarioScope $event)

No description

public
stepCreateRecord(string $type, string $id)

Example: Given a "page" "Page 1"

public
stepCreateRecordHasField(string $type, string $id, string $field, string $value)

Example: Given a "page" "Page 1" has the "content" "My content"

public
stepCreateRecordWithData(string $type, string $id, string $data)

Example: Given a "page" "Page 1" with "URL"="page-1" and "Content"="my page 1" Example: Given the "page" "Page 1" has "URL"="page-1" and "Content"="my page 1"

public
stepCreateRecordWithTable(string $type, string $id, string $null, TableNode $fieldsTable)

Example: And the "page" "Page 2" has the following data | Content | | | My Property | foo | | My Boolean | bar |

public
stepUpdateRecordRelation(string $type, string $id, string $relation, string $relationType, string $relationId)

Example: Given the "page" "Page 1.1" is a child of the "page" "Page1".

public
stepIAssignObjToObj(string $type, string $value, string $relationType, string $relationId)

Assign a type of object to another type of object. The base object will be created if it does not exist already.

public
stepIAssignObjToObjInTheRelation(string $type, string $value, string $relationType, string $relationId, string $relationName)

Assign a type of object to another type of object. The base object will be created if it does not exist already.

public
stepUpdateRecordState(string $type, string $id, string $state)

Example: Given the "page" "Page 1" is not published

public
stepThereAreTheFollowingRecords(string $dataObject, PyStringNode $string)

Accepts YAML fixture definitions similar to the ones used in SilverStripe unit testing.

public
stepCreateMemberWithGroup(string $id, string $groupId)

Example: Given a "member" "Admin" belonging to "Admin Group"

public
stepCreateMemberWithGroupAndData(string $id, string $groupId, string $data)

Example: Given a "member" "Admin" belonging to "Admin Group" with "Email"="[email protected]"

public
stepCreateGroupWithPermissions(string $id, string $permissionStr)

Example: Given a "group" "Admin" with permissions "Access to 'Pages' section" and "Access to 'Files' section"

public
stepGoToNamedRecord(string $type, string $id)

Navigates to a record based on its identifier set during fixture creation, using its RelativeLink() method to map the record to a URL.

public
stepThereShouldBeAFileOrFolder(string $type, string $path)

Checks that a file or folder exists in the webroot.

public
stepThereShouldBeAFileWithTuple(string $filename, string $hash)

Checks that a file exists in the asset store with a given filename and hash

public
mixed
lookupFixtureReference(string $string)

Replaces fixture references in values with their respective database IDs, with the notation "=>.". Example: "=>Page.My Page".

public
aRecordWasLastEditedRelative(string $type, string $id, string $mod, string $time)

No description

protected
array
prepareFixture(string $class, string $identifier, array $data = array())

Prepares a fixture for use

protected
prepareAsset($class, $identifier, $data = null)

No description

protected
AssetStore
getAssetStore()

No description

protected
string
convertTypeToClass($type)

Converts a natural language class description to an actual class name.

protected
array
convertFields(string $class, array $fields)

Updates an object with values, resolving aliases set through DataObject->fieldLabels().

protected
joinPaths()

No description

Details

SilverStripeContext getMainContext()

Get the main context

Return Value

SilverStripeContext

$this setMainContext(SilverStripeContext $mainContext)

No description

Parameters

SilverStripeContext $mainContext

Return Value

$this

detectMainContext(BeforeScenarioScope $scope)

Helper method to detect the main context

Parameters

BeforeScenarioScope $scope

__construct(null $filesPath = null)

FixtureContext constructor.

Parameters

null $filesPath

FixtureFactory getFixtureFactory()

No description

Return Value

FixtureFactory

protected FixtureFactory scaffoldDefaultFixtureFactory()

Build default fixture factory

Return Value

FixtureFactory

setFixtureFactory(FixtureFactory $factory)

No description

Parameters

FixtureFactory $factory

setFilesPath($path)

No description

Parameters

$path

string getFilesPath()

No description

Return Value

string

TempDatabase getTempDatabase()

No description

Return Value

TempDatabase

$this setTempDatabase(TempDatabase $database)

No description

Parameters

TempDatabase $database

Return Value

$this

beforeDatabaseDefaults(BeforeScenarioScope $event)

No description

Parameters

BeforeScenarioScope $event

afterResetDatabase(AfterScenarioScope $event)

No description

Parameters

AfterScenarioScope $event

afterResetAssets(AfterScenarioScope $event)

No description

Parameters

AfterScenarioScope $event

stepCreateRecord(string $type, string $id)

Example: Given a "page" "Page 1"

Parameters

string $type
string $id

stepCreateRecordHasField(string $type, string $id, string $field, string $value)

Example: Given a "page" "Page 1" has the "content" "My content"

Parameters

string $type
string $id
string $field
string $value

stepCreateRecordWithData(string $type, string $id, string $data)

Example: Given a "page" "Page 1" with "URL"="page-1" and "Content"="my page 1" Example: Given the "page" "Page 1" has "URL"="page-1" and "Content"="my page 1"

Parameters

string $type
string $id
string $data

stepCreateRecordWithTable(string $type, string $id, string $null, TableNode $fieldsTable)

Example: And the "page" "Page 2" has the following data | Content | | | My Property | foo | | My Boolean | bar |

Parameters

string $type
string $id
string $null
TableNode $fieldsTable

stepUpdateRecordRelation(string $type, string $id, string $relation, string $relationType, string $relationId)

Example: Given the "page" "Page 1.1" is a child of the "page" "Page1".

Note that this change is not published by default

Parameters

string $type
string $id
string $relation
string $relationType
string $relationId

stepIAssignObjToObj(string $type, string $value, string $relationType, string $relationId)

Assign a type of object to another type of object. The base object will be created if it does not exist already.

If the last part of the string (in the "X" relation) is omitted, then the first matching relation will be used.

Parameters

string $type
string $value
string $relationType
string $relationId

Examples

I assign the "TaxonomyTerm" "For customers" to the "Page" "Page1"

stepIAssignObjToObjInTheRelation(string $type, string $value, string $relationType, string $relationId, string $relationName)

Assign a type of object to another type of object. The base object will be created if it does not exist already.

If the last part of the string (in the "X" relation) is omitted, then the first matching relation will be used. Assumption: one object has relationship (has_one, has_many or many_many ) with the other object

Parameters

string $type
string $value
string $relationType
string $relationId
string $relationName

Exceptions

Exception

Examples

I assign the "TaxonomyTerm" "For customers" to the "Page" "Page1" in the "Terms" relation

stepUpdateRecordState(string $type, string $id, string $state)

Example: Given the "page" "Page 1" is not published

Parameters

string $type
string $id
string $state

stepThereAreTheFollowingRecords(string $dataObject, PyStringNode $string)

Accepts YAML fixture definitions similar to the ones used in SilverStripe unit testing.

Example: Given there are the following member records: member1: Email: [email protected] member2: Email: [email protected]

Parameters

string $dataObject
PyStringNode $string

stepCreateMemberWithGroup(string $id, string $groupId)

Example: Given a "member" "Admin" belonging to "Admin Group"

Parameters

string $id
string $groupId

stepCreateMemberWithGroupAndData(string $id, string $groupId, string $data)

Example: Given a "member" "Admin" belonging to "Admin Group" with "Email"="[email protected]"

Parameters

string $id
string $groupId
string $data

stepCreateGroupWithPermissions(string $id, string $permissionStr)

Example: Given a "group" "Admin" with permissions "Access to 'Pages' section" and "Access to 'Files' section"

Parameters

string $id
string $permissionStr

stepGoToNamedRecord(string $type, string $id)

Navigates to a record based on its identifier set during fixture creation, using its RelativeLink() method to map the record to a URL.

Example: Given I go to the "page" "My Page"

Parameters

string $type
string $id

stepThereShouldBeAFileOrFolder(string $type, string $path)

Checks that a file or folder exists in the webroot.

Example: There should be a file "assets/Uploads/test.jpg"

Parameters

string $type
string $path

stepThereShouldBeAFileWithTuple(string $filename, string $hash)

Checks that a file exists in the asset store with a given filename and hash

Example: there should be a filename "Uploads/test.jpg" with hash "59de0c841f"

Parameters

string $filename
string $hash

mixed lookupFixtureReference(string $string)

Replaces fixture references in values with their respective database IDs, with the notation "=>.". Example: "=>Page.My Page".

Parameters

string $string

Return Value

mixed

aRecordWasLastEditedRelative(string $type, string $id, string $mod, string $time)

No description

Parameters

string $type
string $id
string $mod
string $time

protected array prepareFixture(string $class, string $identifier, array $data = array())

Prepares a fixture for use

Parameters

string $class
string $identifier
array $data

Return Value

array

Prepared $data with additional injected fields

protected prepareAsset($class, $identifier, $data = null)

No description

Parameters

$class
$identifier
$data

protected AssetStore getAssetStore()

No description

Return Value

AssetStore

protected string convertTypeToClass($type)

Converts a natural language class description to an actual class name.

Respects DataObject::$singular_name variations. Example: "redirector page" -> "RedirectorPage"

Parameters

$type

Return Value

string

Class name

protected array convertFields(string $class, array $fields)

Updates an object with values, resolving aliases set through DataObject->fieldLabels().

Parameters

string $class

Class name

array $fields

Map of field names or aliases to their values.

Return Value

array

Map of actual object properties to their values.

protected joinPaths()

No description