mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
New step: "record last edited at relative date"
Thanks to @srizzling for getting this started in https://github.com/silverstripe/silverstripe-cms/pull/896
This commit is contained in:
parent
1c950f07de
commit
1166991d49
@ -420,6 +420,35 @@ class FixtureContext extends BehatContext
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Given /^(?:(an|a|the) )"(?<type>[^"]*)" "(?<id>[^"]*)" was (?<mod>(created|last edited)) "(?<time>[^"]*)"$/
|
||||||
|
*/
|
||||||
|
public function aRecordWasLastEditedRelative($type, $id, $mod, $time) {
|
||||||
|
$class = $this->convertTypeToClass($type);
|
||||||
|
$fields = array();
|
||||||
|
$record = $this->fixtureFactory->createObject($class, $id, $fields);
|
||||||
|
$date = date("Y-m-d H:i:s",strtotime($time));
|
||||||
|
$table = \ClassInfo::baseDataClass(get_class($record));
|
||||||
|
$field = ($mod == 'created') ? 'Created' : 'LastEdited';
|
||||||
|
\DB::query(sprintf(
|
||||||
|
'UPDATE "%s" SET "%s" = \'%s\' WHERE "ID" = \'%d\'',
|
||||||
|
$table,
|
||||||
|
$field,
|
||||||
|
$date,
|
||||||
|
$record->ID
|
||||||
|
));
|
||||||
|
// Support for Versioned extension, by checking for a "Live" stage
|
||||||
|
if(\DB::getConn()->hasTable($table . '_Live')) {
|
||||||
|
\DB::query(sprintf(
|
||||||
|
'UPDATE "%s_Live" SET "%s" = \'%s\' WHERE "ID" = \'%d\'',
|
||||||
|
$table,
|
||||||
|
$field,
|
||||||
|
$date,
|
||||||
|
$record->ID
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function prepareAsset($class, $identifier, $data = null) {
|
protected function prepareAsset($class, $identifier, $data = null) {
|
||||||
if(!$data) $data = array();
|
if(!$data) $data = array();
|
||||||
$relativeTargetPath = (isset($data['Filename'])) ? $data['Filename'] : $identifier;
|
$relativeTargetPath = (isset($data['Filename'])) ? $data['Filename'] : $identifier;
|
||||||
|
Loading…
Reference in New Issue
Block a user