mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
MDL-31936 workshop: Generator able to create submissions and assessments
This is a basic implementation of the actual content generation in the workshop generator. Note the we do not generate actual grading form data (which is what the grading strategy plugins would do), just their results.
This commit is contained in:
parent
f2639dca1d
commit
6073131713
@ -97,4 +97,63 @@ class mod_workshop_generator extends testing_module_generator {
|
||||
|
||||
return parent::create_instance($record, (array)$options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a submission authored by the given user.
|
||||
*
|
||||
* @param int $workshopid Workshop instance id.
|
||||
* @param int $authorid Author user id.
|
||||
* @param stdClass|array $options Optional explicit properties.
|
||||
* @return int The new submission id.
|
||||
*/
|
||||
public function create_submission($workshopid, $authorid, $options = null) {
|
||||
global $DB;
|
||||
|
||||
$timenow = time();
|
||||
$options = (array)$options;
|
||||
|
||||
$record = $options + array(
|
||||
'workshopid' => $workshopid,
|
||||
'example' => 0,
|
||||
'authorid' => $authorid,
|
||||
'timecreated' => $timenow,
|
||||
'timemodified' => $timenow,
|
||||
'title' => 'Generated submission',
|
||||
'content' => 'Generated content',
|
||||
'contentformat' => FORMAT_MARKDOWN,
|
||||
'contenttrust' => 0,
|
||||
);
|
||||
|
||||
$id = $DB->insert_record('workshop_submissions', $record);
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an allocation of the given submission for peer-assessment by the given user
|
||||
*
|
||||
* @param int $submissionid Submission id.
|
||||
* @param int $reviewerid Reviewer's user id.
|
||||
* @param stdClass|array $options Optional explicit properties.
|
||||
* @return int The new assessment id.
|
||||
*/
|
||||
public function create_assessment($submissionid, $reviewerid, $options = null) {
|
||||
global $DB;
|
||||
|
||||
$timenow = time();
|
||||
$options = (array)$options;
|
||||
|
||||
$record = $options + array(
|
||||
'submissionid' => $submissionid,
|
||||
'reviewerid' => $reviewerid,
|
||||
'weight' => 1,
|
||||
'timecreated' => $timenow,
|
||||
'timemodified' => $timenow,
|
||||
'grade' => null,
|
||||
);
|
||||
|
||||
$id = $DB->insert_record('workshop_assessments', $record);
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
|
@ -52,4 +52,57 @@ class mod_workshop_generator_testcase extends advanced_testcase {
|
||||
$this->assertEquals(2, count($records));
|
||||
$this->assertEquals('Another workshop', $records[$workshop->id]->name);
|
||||
}
|
||||
|
||||
public function test_create_submission() {
|
||||
global $DB;
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$workshop = $this->getDataGenerator()->create_module('workshop', array('course' => $course));
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id);
|
||||
$workshopgenerator = $this->getDataGenerator()->get_plugin_generator('mod_workshop');
|
||||
|
||||
$id = $workshopgenerator->create_submission($workshop->id, $user->id, array(
|
||||
'title' => 'My custom title',
|
||||
));
|
||||
|
||||
$submissions = $DB->get_records('workshop_submissions', array('workshopid' => $workshop->id));
|
||||
$this->assertEquals(1, count($submissions));
|
||||
$this->assertTrue(isset($submissions[$id]));
|
||||
$this->assertEquals($submissions[$id]->authorid, $user->id);
|
||||
$this->assertSame('My custom title', $submissions[$id]->title);
|
||||
}
|
||||
|
||||
public function test_create_assessment() {
|
||||
global $DB;
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$workshop = $this->getDataGenerator()->create_module('workshop', array('course' => $course));
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$this->getDataGenerator()->enrol_user($user1->id, $course->id);
|
||||
$this->getDataGenerator()->enrol_user($user2->id, $course->id);
|
||||
$workshopgenerator = $this->getDataGenerator()->get_plugin_generator('mod_workshop');
|
||||
|
||||
$submissionid1 = $workshopgenerator->create_submission($workshop->id, $user1->id);
|
||||
$submissionid2 = $workshopgenerator->create_submission($workshop->id, $user2->id);
|
||||
|
||||
$assessmentid1 = $workshopgenerator->create_assessment($submissionid1, $user2->id, array(
|
||||
'weight' => 3,
|
||||
'grade' => 95.00000,
|
||||
));
|
||||
$assessmentid2 = $workshopgenerator->create_assessment($submissionid2, $user1->id);
|
||||
|
||||
$assessments = $DB->get_records('workshop_assessments');
|
||||
$this->assertTrue(isset($assessments[$assessmentid1]));
|
||||
$this->assertTrue(isset($assessments[$assessmentid2]));
|
||||
$this->assertEquals(3, $assessments[$assessmentid1]->weight);
|
||||
$this->assertEquals(95.00000, $assessments[$assessmentid1]->grade);
|
||||
$this->assertEquals(1, $assessments[$assessmentid2]->weight);
|
||||
$this->assertNull($assessments[$assessmentid2]->grade);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user