FixtureContext
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
Example: Given a "page" "Page 1" has the "content" "My content"
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"
Example: And the "page" "Page 2" has the following data | Content |
Example: Given the "page" "Page 1.1" is a child of the "page" "Page1".
Assign a type of object to another type of object. The base object will be created if it does not exist already.
Assign a type of object to another type of object. The base object will be created if it does not exist already.
Example: Given the "page" "Page 1" is not published
Accepts YAML fixture definitions similar to the ones used in SilverStripe unit testing.
Example: Given a "member" "Admin" belonging to "Admin Group"
Example: Given a "member" "Admin" belonging to "Admin Group" with "Email"="[email protected]"
Example: Given a "group" "Admin" with permissions "Access to 'Pages' section" and "Access to 'Files' section"
Navigates to a record based on its identifier set during fixture creation, using its RelativeLink() method to map the record to a URL.
Checks that a file or folder exists in the webroot.
Checks that a file exists in the asset store with a given filename and hash
Replaces fixture references in values with their respective database IDs,
with the notation "=>
No description
Prepares a fixture for use
Converts a natural language class description to an actual class name.
Updates an object with values, resolving aliases set through DataObject->fieldLabels().
Details
SilverStripeContext
getMainContext()
Get the main context
$this
setMainContext(SilverStripeContext $mainContext)
No description
detectMainContext(BeforeScenarioScope $scope)
Helper method to detect the main context
__construct(null $filesPath = null)
FixtureContext constructor.
FixtureFactory
getFixtureFactory()
No description
protected FixtureFactory
scaffoldDefaultFixtureFactory()
Build default fixture factory
setFixtureFactory(FixtureFactory $factory)
No description
setFilesPath($path)
No description
string
getFilesPath()
No description
TempDatabase
getTempDatabase()
No description
$this
setTempDatabase(TempDatabase $database)
No description
beforeDatabaseDefaults(BeforeScenarioScope $event)
No description
afterResetDatabase(AfterScenarioScope $event)
No description
afterResetAssets(AfterScenarioScope $event)
No description
stepCreateRecord(string $type, string $id)
Example: Given a "page" "Page 1"
stepCreateRecordHasField(string $type, string $id, string $field, string $value)
Example: Given a "page" "Page 1" has the "content" "My content"
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"
stepCreateRecordWithTable(string $type, string $id, string $null, TableNode $fieldsTable)
Example: And the "page" "Page 2" has the following data | Content |
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
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.
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
stepUpdateRecordState(string $type, string $id, string $state)
Example: Given the "page" "Page 1" is not published
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]
stepCreateMemberWithGroup(string $id, string $groupId)
Example: Given a "member" "Admin" belonging to "Admin Group"
stepCreateMemberWithGroupAndData(string $id, string $groupId, string $data)
Example: Given a "member" "Admin" belonging to "Admin Group" with "Email"="[email protected]"
stepCreateGroupWithPermissions(string $id, string $permissionStr)
Example: Given a "group" "Admin" with permissions "Access to 'Pages' section" and "Access to 'Files' section"
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"
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"
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"
mixed
lookupFixtureReference(string $string)
Replaces fixture references in values with their respective database IDs,
with the notation "=>
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.
Respects DataObject::$singular_name variations. Example: "redirector page" -> "RedirectorPage"
protected array
convertFields(string $class, array $fields)
Updates an object with values, resolving aliases set through DataObject->fieldLabels().
protected
joinPaths()
No description