mirror of
https://github.com/moodle/moodle.git
synced 2025-04-25 10:26:17 +02:00
MDL-49852 mod_assign: Unit tests for activity completion.
This commit is contained in:
parent
9569b01cc9
commit
0cf8082a8f
mod/assign/tests
@ -90,7 +90,7 @@ class mod_assign_base_testcase extends advanced_testcase {
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$this->teachers = array();
|
||||
for ($i = 0; $i < self::DEFAULT_TEACHER_COUNT; $i++) {
|
||||
array_push($this->teachers, $this->getDataGenerator()->create_user());
|
||||
@ -350,4 +350,18 @@ class testable_assign extends assign {
|
||||
|
||||
return $mform;
|
||||
}
|
||||
|
||||
public function testable_update_activity_completion_records($teamsubmission,
|
||||
$requireallteammemberssubmit,
|
||||
$submission,
|
||||
$userid,
|
||||
$complete,
|
||||
$completion) {
|
||||
return parent::update_activity_completion_records($teamsubmission,
|
||||
$requireallteammemberssubmit,
|
||||
$submission,
|
||||
$userid,
|
||||
$complete,
|
||||
$completion);
|
||||
}
|
||||
}
|
||||
|
@ -2631,4 +2631,94 @@ Anchor link 2:<a title=\"bananas\" href=\"../logo-240x60.gif\">Link text</a>
|
||||
$grade = $assign->get_user_grade($this->students[0]->id, false);
|
||||
$this->assertEquals('30.0', $grade->grade);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updating activity completion when submitting an assessment.
|
||||
*/
|
||||
public function test_update_activity_completion_records_solitary_submission() {
|
||||
$assign = $this->create_instance(array('grade' => 100,
|
||||
'completion' => COMPLETION_TRACKING_AUTOMATIC,
|
||||
'requireallteammemberssubmit' => 0));
|
||||
|
||||
$cm = $assign->get_course_module();
|
||||
|
||||
$student = $this->students[0];
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
|
||||
|
||||
$this->setUser($student);
|
||||
|
||||
// Simulate a submission.
|
||||
$data = new stdClass();
|
||||
$data->onlinetext_editor = array(
|
||||
'itemid' => file_get_unused_draft_itemid(),
|
||||
'text' => 'Student submission text',
|
||||
'format' => FORMAT_MOODLE
|
||||
);
|
||||
$completion = new completion_info($this->course);
|
||||
|
||||
$notices = array();
|
||||
$assign->save_submission($data, $notices);
|
||||
|
||||
$submission = $assign->get_user_submission($student->id, true);
|
||||
|
||||
// Check that completion is not met yet.
|
||||
$completiondata = $completion->get_data($cm, false, $student->id);
|
||||
$this->assertEquals(0, $completiondata->completionstate);
|
||||
$assign->testable_update_activity_completion_records(0, 0, $submission,
|
||||
$student->id, COMPLETION_COMPLETE, $completion);
|
||||
// Completion should now be met.
|
||||
$completiondata = $completion->get_data($cm, false, $student->id);
|
||||
$this->assertEquals(1, $completiondata->completionstate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updating activity completion when submitting an assessment.
|
||||
*/
|
||||
public function test_update_activity_completion_records_team_submission() {
|
||||
$assign = $this->create_instance(array('grade' => 100,
|
||||
'completion' => COMPLETION_TRACKING_AUTOMATIC,
|
||||
'teamsubmission' => 1));
|
||||
|
||||
$cm = $assign->get_course_module();
|
||||
|
||||
$student1 = $this->students[0];
|
||||
$student2 = $this->students[1];
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
|
||||
|
||||
// Put both users into a group.
|
||||
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $this->course->id));
|
||||
$this->getDataGenerator()->create_group_member(array('groupid' => $group1->id, 'userid' => $student1->id));
|
||||
$this->getDataGenerator()->create_group_member(array('groupid' => $group1->id, 'userid' => $student2->id));
|
||||
|
||||
$this->setUser($student1);
|
||||
|
||||
// Simulate a submission.
|
||||
$data = new stdClass();
|
||||
$data->onlinetext_editor = array(
|
||||
'itemid' => file_get_unused_draft_itemid(),
|
||||
'text' => 'Student submission text',
|
||||
'format' => FORMAT_MOODLE
|
||||
);
|
||||
$completion = new completion_info($this->course);
|
||||
|
||||
$notices = array();
|
||||
$assign->save_submission($data, $notices);
|
||||
|
||||
$submission = $assign->get_user_submission($student1->id, true);
|
||||
$submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
|
||||
$submission->groupid = $group1->id;
|
||||
|
||||
// Check that completion is not met yet.
|
||||
$completiondata = $completion->get_data($cm, false, $student1->id);
|
||||
$this->assertEquals(0, $completiondata->completionstate);
|
||||
$completiondata = $completion->get_data($cm, false, $student2->id);
|
||||
$this->assertEquals(0, $completiondata->completionstate);
|
||||
$assign->testable_update_activity_completion_records(1, 0, $submission, $student1->id,
|
||||
COMPLETION_COMPLETE, $completion);
|
||||
// Completion should now be met.
|
||||
$completiondata = $completion->get_data($cm, false, $student1->id);
|
||||
$this->assertEquals(1, $completiondata->completionstate);
|
||||
$completiondata = $completion->get_data($cm, false, $student2->id);
|
||||
$this->assertEquals(1, $completiondata->completionstate);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user