MDL-37659 testing: New data generators

- Grouping groups
- Group members
This commit is contained in:
David Monllao 2013-01-25 15:13:14 +08:00 committed by Dan Poltawski
parent 2a090a1581
commit 87bb583cbc

View File

@ -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