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:
Sriram Venkatesh 2013-11-15 14:07:39 +01:00 committed by Ingo Schommer
parent 1c950f07de
commit 1166991d49
1 changed files with 29 additions and 0 deletions

View File

@ -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) {
if(!$data) $data = array();
$relativeTargetPath = (isset($data['Filename'])) ? $data['Filename'] : $identifier;