MDL-62715 mod_assign: Bump submissions back when grading in tests

This commit is contained in:
Andrew Nicols 2018-06-20 12:04:50 +08:00
parent 9e7c397889
commit de06b63344
3 changed files with 13 additions and 14 deletions

View File

@ -119,12 +119,20 @@ trait mod_assign_test_generator {
* @param bool $changeuser Whether to switch user to the user being submitted as.
*/
protected function mark_submission($teacher, $assign, $student, $grade = 50.0, $data = [], $attempt = 0) {
global $DB;
// Mark the submission.
$this->setUser($teacher);
$data = (object) array_merge($data, [
'grade' => $grade,
]);
// Bump all timecreated and timemodified for this user back.
// The old assign_print_overview function includes submissions which have been graded where the grade modified
// date matches the submission modified date.
$DB->execute('UPDATE {assign_submission} SET timecreated = timecreated - 1, timemodified = timemodified - 1 WHERE userid = :userid',
['userid' => $student->id]);
$assign->testable_apply_grade_to_user($data, $student->id, $attempt);
}
}

View File

@ -120,7 +120,7 @@ class mod_assign_lib_testcase extends advanced_testcase {
$this->assertEquals(1, count($overview));
// Submissions without a grade.
$this->assertRegExp('/.*Open Assignment.*/', $overview[$course->id]['assign']);
$this->assertRegExp('/.*Assignment with submissions.*/', $overview[$course->id]['assign']);
$this->assertNotRegExp('/.*Assignment with submissions.*/', $overview[$course->id]['assign']);
$this->setUser($teacher);
$overview = array();
@ -129,7 +129,7 @@ class mod_assign_lib_testcase extends advanced_testcase {
$this->assertEquals(1, count($overview));
// Submissions without a grade.
$this->assertRegExp('/.*Open Assignment.*/', $overview[$course->id]['assign']);
$this->assertRegExp('/.*Assignment with submissions.*/', $overview[$course->id]['assign']);
$this->assertNotRegExp('/.*Assignment with submissions.*/', $overview[$course->id]['assign']);
// Let us grade a submission.
$this->setUser($teacher);
@ -145,20 +145,16 @@ class mod_assign_lib_testcase extends advanced_testcase {
$overview = array();
assign_print_overview($courses, $overview);
$this->assertDebuggingCalledCount(3);
$this->assertEquals(1, count($overview));
// Now assignment 4 should not show up.
$this->assertNotRegExp('/.*Open Assignment.*/', $overview[$course->id]['assign']);
$this->assertRegExp('/.*Assignment with submissions.*/', $overview[$course->id]['assign']);
$this->assertDebuggingCalledCount(3);
$this->assertEmpty($overview);
$this->setUser($teacher);
$overview = array();
assign_print_overview($courses, $overview);
$this->assertDebuggingCalledCount(3);
$this->assertEquals(1, count($overview));
// Now assignment 4 should not show up.
$this->assertNotRegExp('/.*Open Assignment.*/', $overview[$course->id]['assign']);
$this->assertRegExp('/.*Assignment with submissions.*/', $overview[$course->id]['assign']);
$this->assertEmpty($overview);
}
/**

View File

@ -1031,10 +1031,6 @@ class mod_assign_locallib_testcase extends advanced_testcase {
$this->add_submission($student, $assign);
$this->submit_for_grading($student, $assign);
// TODO Find a way to kill this waitForSecond
// This is to make sure the grade happens after the submission because
// we have no control over the timemodified values.
$this->waitForSecond();
$this->mark_submission($teacher, $assign, $student, 50.0);
$data = new stdClass();
@ -1302,7 +1298,6 @@ class mod_assign_locallib_testcase extends advanced_testcase {
$this->add_submission($student, $assign);
$this->submit_for_grading($student, $assign);
$this->waitForSecond();
$this->mark_submission($teacher, $assign, $student, 50.0);
// Although it has been graded, it is still marked as submitted.