MDL-46503 behat: cohort generator allows to create cohort in category

This commit is contained in:
Marina Glancy 2014-07-24 10:03:36 +08:00
parent 40f0ad21a3
commit 5f079af450
2 changed files with 41 additions and 0 deletions

View file

@ -217,6 +217,25 @@ class behat_data_generators extends behat_base {
return $data;
}
/**
* If contextlevel and reference are specified for cohort, transform them to the contextid.
*
* @param array $data
* @return array
*/
protected function preprocess_cohort($data) {
if (isset($data['contextlevel'])) {
if (!isset($data['reference'])) {
throw new Exception('If field contextlevel is specified, field reference must also be present');
}
$context = $this->get_context($data['contextlevel'], $data['reference']);
unset($data['contextlevel']);
unset($data['reference']);
$data['contextid'] = $context->id;
}
return $data;
}
/**
* Adapter to modules generator
* @throws Exception Custom exception for test writers