mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Merge pull request #117 from open-sausages/pulls/4.0/namespace-orm
Update to support new namespace SilverStripe\ORM
This commit is contained in:
commit
6ea51d4f95
@ -7,6 +7,10 @@ use Behat\Behat\Context\BehatContext,
|
|||||||
Behat\Gherkin\Node\PyStringNode,
|
Behat\Gherkin\Node\PyStringNode,
|
||||||
Behat\Gherkin\Node\TableNode,
|
Behat\Gherkin\Node\TableNode,
|
||||||
SilverStripe\Filesystem\Storage\AssetStore;
|
SilverStripe\Filesystem\Storage\AssetStore;
|
||||||
|
use SilverStripe\ORM\DB;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\ORM\Versioning\Versioned;
|
||||||
|
|
||||||
|
|
||||||
// PHPUnit
|
// PHPUnit
|
||||||
require_once BASE_PATH . '/vendor/phpunit/phpunit/src/Framework/Assert/Functions.php';
|
require_once BASE_PATH . '/vendor/phpunit/phpunit/src/Framework/Assert/Functions.php';
|
||||||
@ -84,17 +88,17 @@ class FixtureContext extends BehatContext
|
|||||||
*/
|
*/
|
||||||
public function beforeDatabaseDefaults(ScenarioEvent $event) {
|
public function beforeDatabaseDefaults(ScenarioEvent $event) {
|
||||||
\SapphireTest::empty_temp_db();
|
\SapphireTest::empty_temp_db();
|
||||||
\DB::getConn()->quiet();
|
DB::get_conn()->quiet();
|
||||||
$dataClasses = \ClassInfo::subclassesFor('DataObject');
|
$dataClasses = \ClassInfo::subclassesFor('SilverStripe\\ORM\\DataObject');
|
||||||
array_shift($dataClasses);
|
array_shift($dataClasses);
|
||||||
foreach ($dataClasses as $dataClass) {
|
foreach ($dataClasses as $dataClass) {
|
||||||
\singleton($dataClass)->requireDefaultRecords();
|
\singleton($dataClass)->requireDefaultRecords();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @AfterScenario
|
* @AfterScenario
|
||||||
*/
|
*/
|
||||||
public function afterResetDatabase(ScenarioEvent $event) {
|
public function afterResetDatabase(ScenarioEvent $event) {
|
||||||
\SapphireTest::empty_temp_db();
|
\SapphireTest::empty_temp_db();
|
||||||
}
|
}
|
||||||
@ -113,7 +117,7 @@ class FixtureContext extends BehatContext
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Example: Given a "page" "Page 1"
|
* Example: Given a "page" "Page 1"
|
||||||
*
|
*
|
||||||
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)"$/
|
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)"$/
|
||||||
*/
|
*/
|
||||||
public function stepCreateRecord($type, $id) {
|
public function stepCreateRecord($type, $id) {
|
||||||
@ -123,8 +127,8 @@ class FixtureContext extends BehatContext
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example: Given a "page" "Page 1" has the "content" "My content"
|
* Example: Given a "page" "Page 1" has the "content" "My content"
|
||||||
*
|
*
|
||||||
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" has (?:(an|a|the) )"(?<field>.*)" "(?<value>.*)"$/
|
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" has (?:(an|a|the) )"(?<field>.*)" "(?<value>.*)"$/
|
||||||
*/
|
*/
|
||||||
public function stepCreateRecordHasField($type, $id, $field, $value) {
|
public function stepCreateRecordHasField($type, $id, $field, $value) {
|
||||||
@ -144,17 +148,17 @@ class FixtureContext extends BehatContext
|
|||||||
$this->fixtureFactory->createObject($class, $id, $fields);
|
$this->fixtureFactory->createObject($class, $id, $fields);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example: Given a "page" "Page 1" with "URL"="page-1" and "Content"="my page 1"
|
* 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: Given the "page" "Page 1" has "URL"="page-1" and "Content"="my page 1"
|
||||||
*
|
*
|
||||||
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" (?:(with|has)) (?<data>".*)$/
|
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" (?:(with|has)) (?<data>".*)$/
|
||||||
*/
|
*/
|
||||||
public function stepCreateRecordWithData($type, $id, $data) {
|
public function stepCreateRecordWithData($type, $id, $data) {
|
||||||
$class = $this->convertTypeToClass($type);
|
$class = $this->convertTypeToClass($type);
|
||||||
preg_match_all(
|
preg_match_all(
|
||||||
'/"(?<key>[^"]+)"\s*=\s*"(?<value>[^"]+)"/',
|
'/"(?<key>[^"]+)"\s*=\s*"(?<value>[^"]+)"/',
|
||||||
$data,
|
$data,
|
||||||
$matches
|
$matches
|
||||||
);
|
);
|
||||||
@ -176,11 +180,11 @@ class FixtureContext extends BehatContext
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example: And the "page" "Page 2" has the following data
|
* Example: And the "page" "Page 2" has the following data
|
||||||
* | Content | <blink> |
|
* | Content | <blink> |
|
||||||
* | My Property | foo |
|
* | My Property | foo |
|
||||||
* | My Boolean | bar |
|
* | My Boolean | bar |
|
||||||
*
|
*
|
||||||
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" has the following data$/
|
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" has the following data$/
|
||||||
*/
|
*/
|
||||||
public function stepCreateRecordWithTable($type, $id, $null, TableNode $fieldsTable) {
|
public function stepCreateRecordWithTable($type, $id, $null, TableNode $fieldsTable) {
|
||||||
@ -204,7 +208,7 @@ class FixtureContext extends BehatContext
|
|||||||
/**
|
/**
|
||||||
* Example: Given the "page" "Page 1.1" is a child of the "page" "Page1".
|
* Example: Given the "page" "Page 1.1" is a child of the "page" "Page1".
|
||||||
* Note that this change is not published by default
|
* Note that this change is not published by default
|
||||||
*
|
*
|
||||||
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" is a (?<relation>[^\s]*) of (?:(an|a|the) )"(?<relationType>[^"]+)" "(?<relationId>[^"]+)"/
|
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" is a (?<relation>[^\s]*) of (?:(an|a|the) )"(?<relationType>[^"]+)" "(?<relationId>[^"]+)"/
|
||||||
*/
|
*/
|
||||||
public function stepUpdateRecordRelation($type, $id, $relation, $relationType, $relationId) {
|
public function stepUpdateRecordRelation($type, $id, $relation, $relationType, $relationId) {
|
||||||
@ -257,7 +261,7 @@ class FixtureContext extends BehatContext
|
|||||||
* 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.
|
||||||
* If the last part of the string (in the "X" relation) is omitted, then the first matching relation will be used.
|
* 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
|
* Assumption: one object has relationship (has_one, has_many or many_many ) with the other object
|
||||||
*
|
*
|
||||||
* @example I assign the "TaxonomyTerm" "For customers" to the "Page" "Page1" in the "Terms" relation
|
* @example I assign the "TaxonomyTerm" "For customers" to the "Page" "Page1" in the "Terms" relation
|
||||||
* @Given /^I assign (?:(an|a|the) )"(?<type>[^"]+)" "(?<value>[^"]+)" to (?:(an|a|the) )"(?<relationType>[^"]+)" "(?<relationId>[^"]+)" in the "(?<relationName>[^"]+)" relation$/
|
* @Given /^I assign (?:(an|a|the) )"(?<type>[^"]+)" "(?<value>[^"]+)" to (?:(an|a|the) )"(?<relationType>[^"]+)" "(?<relationId>[^"]+)" in the "(?<relationName>[^"]+)" relation$/
|
||||||
*/
|
*/
|
||||||
@ -288,14 +292,14 @@ class FixtureContext extends BehatContext
|
|||||||
throw new \Exception("'$relationClass' has no relationship (has_one, has_many and many_many) with '$class'!");
|
throw new \Exception("'$relationClass' has no relationship (has_one, has_many and many_many) with '$class'!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the searchable field to check if the fixture object already exists
|
// Get the searchable field to check if the fixture object already exists
|
||||||
$temObj = new $class;
|
$temObj = new $class;
|
||||||
if(isset($temObj->Name)) $field = "Name";
|
if(isset($temObj->Name)) $field = "Name";
|
||||||
else if(isset($temObj->Title)) $field = "Title";
|
else if(isset($temObj->Title)) $field = "Title";
|
||||||
else $field = "ID";
|
else $field = "ID";
|
||||||
|
|
||||||
// Check if the fixture object exists - if not, we create it
|
// Check if the fixture object exists - if not, we create it
|
||||||
$obj = \DataObject::get($class)->filter($field, $value)->first();
|
$obj = DataObject::get($class)->filter($field, $value)->first();
|
||||||
if(!$obj) $obj = $this->fixtureFactory->createObject($class, $value);
|
if(!$obj) $obj = $this->fixtureFactory->createObject($class, $value);
|
||||||
// If has_many or many_many, add this fixture object to the relation object
|
// If has_many or many_many, add this fixture object to the relation object
|
||||||
// If has_one, set value to the joint field with this fixture object's ID
|
// If has_one, set value to the joint field with this fixture object's ID
|
||||||
@ -305,14 +309,14 @@ class FixtureContext extends BehatContext
|
|||||||
// E.g. $has_one = array('PanelOffer' => 'Offer');
|
// E.g. $has_one = array('PanelOffer' => 'Offer');
|
||||||
// then the join field is PanelOfferID. This is the common rule in the CMS
|
// then the join field is PanelOfferID. This is the common rule in the CMS
|
||||||
$relationObj->{$oneField . 'ID'} = $obj->ID;
|
$relationObj->{$oneField . 'ID'} = $obj->ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
$relationObj->write();
|
$relationObj->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example: Given the "page" "Page 1" is not published
|
* Example: Given the "page" "Page 1" is not published
|
||||||
*
|
*
|
||||||
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" is (?<state>[^"]*)$/
|
* @Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" is (?<state>[^"]*)$/
|
||||||
*/
|
*/
|
||||||
public function stepUpdateRecordState($type, $id, $state) {
|
public function stepUpdateRecordState($type, $id, $state) {
|
||||||
@ -332,11 +336,11 @@ class FixtureContext extends BehatContext
|
|||||||
break;
|
break;
|
||||||
case 'not published':
|
case 'not published':
|
||||||
case 'unpublished':
|
case 'unpublished':
|
||||||
$oldMode = \Versioned::get_reading_mode();
|
$oldMode = Versioned::get_reading_mode();
|
||||||
\Versioned::set_stage(\Versioned::LIVE);
|
Versioned::set_stage(Versioned::LIVE);
|
||||||
$clone = clone $obj;
|
$clone = clone $obj;
|
||||||
$clone->delete();
|
$clone->delete();
|
||||||
\Versioned::set_reading_mode($oldMode);
|
Versioned::set_reading_mode($oldMode);
|
||||||
break;
|
break;
|
||||||
case 'deleted':
|
case 'deleted':
|
||||||
$obj->delete();
|
$obj->delete();
|
||||||
@ -344,19 +348,19 @@ class FixtureContext extends BehatContext
|
|||||||
default:
|
default:
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new \InvalidArgumentException(sprintf(
|
||||||
'Invalid state: "%s"', $state
|
'Invalid state: "%s"', $state
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accepts YAML fixture definitions similar to the ones used in SilverStripe unit testing.
|
* Accepts YAML fixture definitions similar to the ones used in SilverStripe unit testing.
|
||||||
*
|
*
|
||||||
* Example: Given there are the following member records:
|
* Example: Given there are the following member records:
|
||||||
* member1:
|
* member1:
|
||||||
* Email: member1@test.com
|
* Email: member1@test.com
|
||||||
* member2:
|
* member2:
|
||||||
* Email: member2@test.com
|
* Email: member2@test.com
|
||||||
*
|
*
|
||||||
* @Given /^there are the following ([^\s]*) records$/
|
* @Given /^there are the following ([^\s]*) records$/
|
||||||
*/
|
*/
|
||||||
public function stepThereAreTheFollowingRecords($dataObject, PyStringNode $string) {
|
public function stepThereAreTheFollowingRecords($dataObject, PyStringNode $string) {
|
||||||
@ -371,26 +375,26 @@ class FixtureContext extends BehatContext
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Example: Given a "member" "Admin" belonging to "Admin Group"
|
* Example: Given a "member" "Admin" belonging to "Admin Group"
|
||||||
*
|
*
|
||||||
* @Given /^(?:(an|a|the) )"member" "(?<id>[^"]+)" belonging to "(?<groupId>[^"]+)"$/
|
* @Given /^(?:(an|a|the) )"member" "(?<id>[^"]+)" belonging to "(?<groupId>[^"]+)"$/
|
||||||
*/
|
*/
|
||||||
public function stepCreateMemberWithGroup($id, $groupId) {
|
public function stepCreateMemberWithGroup($id, $groupId) {
|
||||||
$group = $this->fixtureFactory->get('Group', $groupId);
|
$group = $this->fixtureFactory->get('Group', $groupId);
|
||||||
if(!$group) $group = $this->fixtureFactory->createObject('Group', $groupId);
|
if(!$group) $group = $this->fixtureFactory->createObject('Group', $groupId);
|
||||||
|
|
||||||
$member = $this->fixtureFactory->createObject('Member', $id);
|
$member = $this->fixtureFactory->createObject('Member', $id);
|
||||||
$member->Groups()->add($group);
|
$member->Groups()->add($group);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example: Given a "member" "Admin" belonging to "Admin Group" with "Email"="test@test.com"
|
* Example: Given a "member" "Admin" belonging to "Admin Group" with "Email"="test@test.com"
|
||||||
*
|
*
|
||||||
* @Given /^(?:(an|a|the) )"member" "(?<id>[^"]+)" belonging to "(?<groupId>[^"]+)" with (?<data>.*)$/
|
* @Given /^(?:(an|a|the) )"member" "(?<id>[^"]+)" belonging to "(?<groupId>[^"]+)" with (?<data>.*)$/
|
||||||
*/
|
*/
|
||||||
public function stepCreateMemberWithGroupAndData($id, $groupId, $data) {
|
public function stepCreateMemberWithGroupAndData($id, $groupId, $data) {
|
||||||
$class = 'Member';
|
$class = 'Member';
|
||||||
preg_match_all(
|
preg_match_all(
|
||||||
'/"(?<key>[^"]+)"\s*=\s*"(?<value>[^"]+)"/',
|
'/"(?<key>[^"]+)"\s*=\s*"(?<value>[^"]+)"/',
|
||||||
$data,
|
$data,
|
||||||
$matches
|
$matches
|
||||||
);
|
);
|
||||||
@ -398,7 +402,7 @@ class FixtureContext extends BehatContext
|
|||||||
$class,
|
$class,
|
||||||
array_combine($matches['key'], $matches['value'])
|
array_combine($matches['key'], $matches['value'])
|
||||||
);
|
);
|
||||||
|
|
||||||
$group = $this->fixtureFactory->get('Group', $groupId);
|
$group = $this->fixtureFactory->get('Group', $groupId);
|
||||||
if(!$group) $group = $this->fixtureFactory->createObject('Group', $groupId);
|
if(!$group) $group = $this->fixtureFactory->createObject('Group', $groupId);
|
||||||
|
|
||||||
@ -408,7 +412,7 @@ class FixtureContext extends BehatContext
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Example: Given a "group" "Admin" with permissions "Access to 'Pages' section" and "Access to 'Files' section"
|
* Example: Given a "group" "Admin" with permissions "Access to 'Pages' section" and "Access to 'Files' section"
|
||||||
*
|
*
|
||||||
* @Given /^(?:(an|a|the) )"group" "(?<id>[^"]+)" (?:(with|has)) permissions (?<permissionStr>.*)$/
|
* @Given /^(?:(an|a|the) )"group" "(?<id>[^"]+)" (?:(with|has)) permissions (?<permissionStr>.*)$/
|
||||||
*/
|
*/
|
||||||
public function stepCreateGroupWithPermissions($id, $permissionStr) {
|
public function stepCreateGroupWithPermissions($id, $permissionStr) {
|
||||||
@ -419,7 +423,7 @@ class FixtureContext extends BehatContext
|
|||||||
|
|
||||||
$group = $this->fixtureFactory->get('Group', $id);
|
$group = $this->fixtureFactory->get('Group', $id);
|
||||||
if(!$group) $group = $this->fixtureFactory->createObject('Group', $id);
|
if(!$group) $group = $this->fixtureFactory->createObject('Group', $id);
|
||||||
|
|
||||||
foreach($permissions as $permission) {
|
foreach($permissions as $permission) {
|
||||||
$found = false;
|
$found = false;
|
||||||
foreach($codes as $code => $details) {
|
foreach($codes as $code => $details) {
|
||||||
@ -434,7 +438,7 @@ class FixtureContext extends BehatContext
|
|||||||
if(!$found) {
|
if(!$found) {
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new \InvalidArgumentException(sprintf(
|
||||||
'No permission found for "%s"', $permission
|
'No permission found for "%s"', $permission
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -443,7 +447,7 @@ class FixtureContext extends BehatContext
|
|||||||
* Navigates to a record based on its identifier set during fixture creation,
|
* Navigates to a record based on its identifier set during fixture creation,
|
||||||
* using its RelativeLink() method to map the record to a URL.
|
* using its RelativeLink() method to map the record to a URL.
|
||||||
* Example: Given I go to the "page" "My Page"
|
* Example: Given I go to the "page" "My Page"
|
||||||
*
|
*
|
||||||
* @Given /^I go to (?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)"/
|
* @Given /^I go to (?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)"/
|
||||||
*/
|
*/
|
||||||
public function stepGoToNamedRecord($type, $id) {
|
public function stepGoToNamedRecord($type, $id) {
|
||||||
@ -466,7 +470,7 @@ class FixtureContext extends BehatContext
|
|||||||
/**
|
/**
|
||||||
* Checks that a file or folder exists in the webroot.
|
* Checks that a file or folder exists in the webroot.
|
||||||
* Example: There should be a file "assets/Uploads/test.jpg"
|
* Example: There should be a file "assets/Uploads/test.jpg"
|
||||||
*
|
*
|
||||||
* @Then /^there should be a (?<type>(file|folder) )"(?<path>[^"]*)"/
|
* @Then /^there should be a (?<type>(file|folder) )"(?<path>[^"]*)"/
|
||||||
*/
|
*/
|
||||||
public function stepThereShouldBeAFileOrFolder($type, $path) {
|
public function stepThereShouldBeAFileOrFolder($type, $path) {
|
||||||
@ -486,9 +490,9 @@ class FixtureContext extends BehatContext
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces fixture references in values with their respective database IDs,
|
* Replaces fixture references in values with their respective database IDs,
|
||||||
* with the notation "=><class>.<identifier>". Example: "=>Page.My Page".
|
* with the notation "=><class>.<identifier>". Example: "=>Page.My Page".
|
||||||
*
|
*
|
||||||
* @Transform /^([^"]+)$/
|
* @Transform /^([^"]+)$/
|
||||||
*/
|
*/
|
||||||
public function lookupFixtureReference($string) {
|
public function lookupFixtureReference($string) {
|
||||||
@ -517,28 +521,28 @@ class FixtureContext extends BehatContext
|
|||||||
$date = date("Y-m-d H:i:s",strtotime($time));
|
$date = date("Y-m-d H:i:s",strtotime($time));
|
||||||
$table = \ClassInfo::baseDataClass(get_class($record));
|
$table = \ClassInfo::baseDataClass(get_class($record));
|
||||||
$field = ($mod == 'created') ? 'Created' : 'LastEdited';
|
$field = ($mod == 'created') ? 'Created' : 'LastEdited';
|
||||||
\DB::query(sprintf(
|
DB::query(sprintf(
|
||||||
'UPDATE "%s" SET "%s" = \'%s\' WHERE "ID" = \'%d\'',
|
'UPDATE "%s" SET "%s" = \'%s\' WHERE "ID" = \'%d\'',
|
||||||
$table,
|
$table,
|
||||||
$field,
|
$field,
|
||||||
$date,
|
$date,
|
||||||
$record->ID
|
$record->ID
|
||||||
));
|
));
|
||||||
// Support for Versioned extension, by checking for a "Live" stage
|
// Support for Versioned extension, by checking for a "Live" stage
|
||||||
if(\DB::getConn()->hasTable($table . '_Live')) {
|
if(DB::getConn()->hasTable($table . '_Live')) {
|
||||||
\DB::query(sprintf(
|
DB::query(sprintf(
|
||||||
'UPDATE "%s_Live" SET "%s" = \'%s\' WHERE "ID" = \'%d\'',
|
'UPDATE "%s_Live" SET "%s" = \'%s\' WHERE "ID" = \'%d\'',
|
||||||
$table,
|
$table,
|
||||||
$field,
|
$field,
|
||||||
$date,
|
$date,
|
||||||
$record->ID
|
$record->ID
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares a fixture for use
|
* Prepares a fixture for use
|
||||||
*
|
*
|
||||||
* @param string $class
|
* @param string $class
|
||||||
* @param string $identifier
|
* @param string $identifier
|
||||||
* @param array $data
|
* @param array $data
|
||||||
@ -556,7 +560,7 @@ class FixtureContext extends BehatContext
|
|||||||
$relativeTargetPath = (isset($data['Filename'])) ? $data['Filename'] : $identifier;
|
$relativeTargetPath = (isset($data['Filename'])) ? $data['Filename'] : $identifier;
|
||||||
$relativeTargetPath = preg_replace('/^' . ASSETS_DIR . '\/?/', '', $relativeTargetPath);
|
$relativeTargetPath = preg_replace('/^' . ASSETS_DIR . '\/?/', '', $relativeTargetPath);
|
||||||
$sourcePath = $this->joinPaths($this->getFilesPath(), basename($relativeTargetPath));
|
$sourcePath = $this->joinPaths($this->getFilesPath(), basename($relativeTargetPath));
|
||||||
|
|
||||||
// Create file or folder on filesystem
|
// Create file or folder on filesystem
|
||||||
if($class == 'Folder' || is_subclass_of($class, 'Folder')) {
|
if($class == 'Folder' || is_subclass_of($class, 'Folder')) {
|
||||||
$parent = \Folder::find_or_make($relativeTargetPath);
|
$parent = \Folder::find_or_make($relativeTargetPath);
|
||||||
@ -571,7 +575,7 @@ class FixtureContext extends BehatContext
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
$data['ParentID'] = $parent->ID;
|
$data['ParentID'] = $parent->ID;
|
||||||
|
|
||||||
// Load file into APL and retrieve tuple
|
// Load file into APL and retrieve tuple
|
||||||
$asset = $this->getAssetStore()->setFromLocalFile(
|
$asset = $this->getAssetStore()->setFromLocalFile(
|
||||||
$sourcePath,
|
$sourcePath,
|
||||||
@ -611,8 +615,8 @@ class FixtureContext extends BehatContext
|
|||||||
* Converts a natural language class description to an actual class name.
|
* Converts a natural language class description to an actual class name.
|
||||||
* Respects {@link DataObject::$singular_name} variations.
|
* Respects {@link DataObject::$singular_name} variations.
|
||||||
* Example: "redirector page" -> "RedirectorPage"
|
* Example: "redirector page" -> "RedirectorPage"
|
||||||
*
|
*
|
||||||
* @param String
|
* @param String
|
||||||
* @return String Class name
|
* @return String Class name
|
||||||
*/
|
*/
|
||||||
protected function convertTypeToClass($type) {
|
protected function convertTypeToClass($type) {
|
||||||
@ -620,13 +624,15 @@ class FixtureContext extends BehatContext
|
|||||||
|
|
||||||
// Try direct mapping
|
// Try direct mapping
|
||||||
$class = str_replace(' ', '', ucwords($type));
|
$class = str_replace(' ', '', ucwords($type));
|
||||||
if(class_exists($class) || !($class == 'DataObject' || is_subclass_of($class, 'DataObject'))) {
|
if(class_exists($class) && is_subclass_of($class, 'SilverStripe\\ORM\\DataObject')) {
|
||||||
return $class;
|
return \ClassInfo::class_name($class);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to singular names
|
// Fall back to singular names
|
||||||
foreach(array_values(\ClassInfo::subclassesFor('DataObject')) as $candidate) {
|
foreach(array_values(\ClassInfo::subclassesFor('SilverStripe\\ORM\\DataObject')) as $candidate) {
|
||||||
if(singleton($candidate)->singular_name() == $type) return $candidate;
|
if(strcasecmp(singleton($candidate)->singular_name(), $type) === 0) {
|
||||||
|
return $candidate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new \InvalidArgumentException(sprintf(
|
||||||
@ -638,10 +644,10 @@ class FixtureContext extends BehatContext
|
|||||||
/**
|
/**
|
||||||
* Updates an object with values, resolving aliases set through
|
* Updates an object with values, resolving aliases set through
|
||||||
* {@link DataObject->fieldLabels()}.
|
* {@link DataObject->fieldLabels()}.
|
||||||
*
|
*
|
||||||
* @param String Class name
|
* @param string $class Class name
|
||||||
* @param Array Map of field names or aliases to their values.
|
* @param array $fields Map of field names or aliases to their values.
|
||||||
* @return Array Map of actual object properties to their values.
|
* @return array Map of actual object properties to their values.
|
||||||
*/
|
*/
|
||||||
protected function convertFields($class, $fields) {
|
protected function convertFields($class, $fields) {
|
||||||
$labels = singleton($class)->fieldLabels();
|
$labels = singleton($class)->fieldLabels();
|
||||||
@ -649,7 +655,7 @@ class FixtureContext extends BehatContext
|
|||||||
if($fieldLabelKey = array_search($fieldName, $labels)) {
|
if($fieldLabelKey = array_search($fieldName, $labels)) {
|
||||||
unset($fields[$fieldName]);
|
unset($fields[$fieldName]);
|
||||||
$fields[$labels[$fieldLabelKey]] = $fieldVal;
|
$fields[$labels[$fieldLabelKey]] = $fieldVal;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $fields;
|
return $fields;
|
||||||
@ -663,5 +669,5 @@ class FixtureContext extends BehatContext
|
|||||||
if (substr($args[0], 0, 1) == '/') $paths[0] = '/' . $paths[0];
|
if (substr($args[0], 0, 1) == '/') $paths[0] = '/' . $paths[0];
|
||||||
return join('/', $paths);
|
return join('/', $paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ Behat\Behat\Context\Step,
|
|||||||
Behat\Behat\Exception\PendingException;
|
Behat\Behat\Exception\PendingException;
|
||||||
use Behat\Gherkin\Node\PyStringNode,
|
use Behat\Gherkin\Node\PyStringNode,
|
||||||
Behat\Gherkin\Node\TableNode;
|
Behat\Gherkin\Node\TableNode;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
|
||||||
|
|
||||||
// PHPUnit
|
// PHPUnit
|
||||||
require_once BASE_PATH . '/vendor/phpunit/phpunit/src/Framework/Assert/Functions.php';
|
require_once BASE_PATH . '/vendor/phpunit/phpunit/src/Framework/Assert/Functions.php';
|
||||||
@ -86,7 +88,7 @@ class LoginContext extends BehatContext
|
|||||||
$permission->write();
|
$permission->write();
|
||||||
$group->Permissions()->add($permission);
|
$group->Permissions()->add($permission);
|
||||||
|
|
||||||
$member = \DataObject::get_one('Member', sprintf('"Email" = \'%s\'', "$permCode@example.org"));
|
$member = DataObject::get_one('Member', sprintf('"Email" = \'%s\'', "$permCode@example.org"));
|
||||||
if (!$member) {
|
if (!$member) {
|
||||||
$member = \Injector::inst()->create('Member');
|
$member = \Injector::inst()->create('Member');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user