Skip to content

Commit

Permalink
Merge branch 'MDL-32426-master-1' of git://git.luns.net.uk/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Apr 15, 2012
2 parents f295ffe + f15d451 commit e3a660a
Showing 1 changed file with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion lib/phpunit/generatorlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class phpunit_data_generator {
protected $categorycount = 0;
protected $coursecount = 0;
protected $scalecount = 0;
protected $groupcount = 0;
protected $groupingcount = 0;

/** @var array list of plugin generators */
protected $generators = array();
Expand Down Expand Up @@ -403,6 +405,80 @@ public function create_module($modulename, $record=null, array $options=null) {
return $generator->create_instance($record, $options);
}

/**
* Create a test group for the specified course
*
* @param array|stdClass $recrd
* @return stdClass group record
*/
public function create_group($record) {
global $DB, $CFG;

require_once($CFG->dirroot . '/group/lib.php');

$this->groupcount++;
$i = $this->groupcount;

$record = (array)$record;

if (empty($record['courseid'])) {
throw new coding_exception('courseid must be present in phpunit_util::create_group() $record');
}

if (!isset($record['name'])) {
$record['name'] = 'group-' . $i;
}

if (!isset($record['description'])) {
$record['description'] = "Test Group $i\n{$this->loremipsum}";
}

if (!isset($record['descriptionformat'])) {
$record['descriptionformat'] = FORMAT_MOODLE;
}

$id = groups_create_group((object)$record);

return $DB->get_record('groups', array('id'=>$id));
}

/**
* Create a test grouping for the specified course
*
* @param array|stdClass $recrd
* @return stdClass grouping record
*/
public function create_grouping($record) {
global $DB, $CFG;

require_once($CFG->dirroot . '/group/lib.php');

$this->groupingcount++;
$i = $this->groupingcount;

$record = (array)$record;

if (empty($record['courseid'])) {
throw new coding_exception('courseid must be present in phpunit_util::create_grouping() $record');
}

if (!isset($record['name'])) {
$record['name'] = 'grouping-' . $i;
}

if (!isset($record['description'])) {
$record['description'] = "Test Grouping $i\n{$this->loremipsum}";
}

if (!isset($record['descriptionformat'])) {
$record['descriptionformat'] = FORMAT_MOODLE;
}

$id = groups_create_grouping((object)$record);

return $DB->get_record('groupings', array('id'=>$id));
}

/**
* Create a test scale
* @param array|stdClass $record
Expand Down Expand Up @@ -641,4 +717,4 @@ protected function prepare_record(stdClass $record) {
* @return stdClass activity record
*/
abstract public function create_instance($record = null, array $options = null);
}
}

0 comments on commit e3a660a

Please sign in to comment.