diff --git a/lib/testing/generator/data_generator.php b/lib/testing/generator/data_generator.php index 7f99a93dfe8..b6927aba865 100644 --- a/lib/testing/generator/data_generator.php +++ b/lib/testing/generator/data_generator.php @@ -472,6 +472,37 @@ EOD; return $DB->get_record('groups', array('id'=>$id)); } + /** + * Create a test group member + * @param array|stdClass $record + * @throws coding_exception + * @return boolean + */ + public function create_group_member($record) { + global $DB, $CFG; + + require_once($CFG->dirroot . '/group/lib.php'); + + $record = (array)$record; + + if (empty($record['userid'])) { + throw new coding_exception('user must be present in testing_util::create_group_member() $record'); + } + + if (!isset($record['groupid'])) { + throw new coding_exception('group must be present in testing_util::create_group_member() $record'); + } + + if (!isset($record['component'])) { + $record['component'] = null; + } + if (!isset($record['itemid'])) { + $record['itemid'] = 0; + } + + return groups_add_member($record['groupid'], $record['userid'], $record['component'], $record['itemid']); + } + /** * Create a test grouping for the specified course * @@ -515,6 +546,30 @@ EOD; return $DB->get_record('groupings', array('id'=>$id)); } + /** + * Create a test grouping group + * @param array|stdClass $record + * @throws coding_exception + * @return boolean + */ + public function create_grouping_group($record) { + global $DB, $CFG; + + require_once($CFG->dirroot . '/group/lib.php'); + + $record = (array)$record; + + if (empty($record['groupingid'])) { + throw new coding_exception('grouping must be present in testing::create_grouping_group() $record'); + } + + if (!isset($record['groupid'])) { + throw new coding_exception('group must be present in testing_util::create_grouping_group() $record'); + } + + return groups_assign_grouping($record['groupingid'], $record['groupid']); + } + /** * Create a test scale * @param array|stdClass $record