Skip to content

Commit

Permalink
MDL-42676 mod_assign: Display message fix when using grade override
Browse files Browse the repository at this point in the history
Logic fix in mod_assign locallib.php to correctly set the submissionlockedstatus,
and added associated unit test in test_grade_submission_override()
  • Loading branch information
zig-moodle committed Dec 12, 2017
1 parent 5fdb912 commit ece94bb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
12 changes: 6 additions & 6 deletions mod/assign/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3774,7 +3774,7 @@ protected function view_single_grading_panel($args) {
$grade = $this->get_user_grade($userid, false, $attemptnumber);
$flags = $this->get_user_flags($userid, false);
if ($this->can_view_submission($userid)) {
$gradelocked = ($flags && $flags->locked) || $this->grading_disabled($userid);
$submissionlocked = ($flags && $flags->locked);
$extensionduedate = null;
if ($flags) {
$extensionduedate = $flags->extensionduedate;
Expand All @@ -3791,7 +3791,7 @@ protected function view_single_grading_panel($args) {
$submissiongroup,
$notsubmitted,
$this->is_any_submission_plugin_enabled(),
$gradelocked,
$submissionlocked,
$this->is_graded($userid),
$instance->duedate,
$instance->cutoffdate,
Expand Down Expand Up @@ -3972,7 +3972,7 @@ protected function view_single_grade_page($mform) {
$grade = $this->get_user_grade($userid, false, $attemptnumber);
$flags = $this->get_user_flags($userid, false);
if ($this->can_view_submission($userid)) {
$gradelocked = ($flags && $flags->locked) || $this->grading_disabled($userid);
$submissionlocked = ($flags && $flags->locked);
$extensionduedate = null;
if ($flags) {
$extensionduedate = $flags->extensionduedate;
Expand All @@ -3989,7 +3989,7 @@ protected function view_single_grade_page($mform) {
$submissiongroup,
$notsubmitted,
$this->is_any_submission_plugin_enabled(),
$gradelocked,
$submissionlocked,
$this->is_graded($userid),
$instance->duedate,
$instance->cutoffdate,
Expand Down Expand Up @@ -4946,7 +4946,7 @@ public function get_assign_submission_status_renderable($user, $showlinks) {
($this->is_any_submission_plugin_enabled()) &&
$this->can_edit_submission($user->id);

$gradelocked = ($flags && $flags->locked) || $this->grading_disabled($user->id, false);
$submissionlocked = ($flags && $flags->locked);

// Grading criteria preview.
$gradingmanager = get_grading_manager($this->context, 'mod_assign', 'submissions');
Expand Down Expand Up @@ -4977,7 +4977,7 @@ public function get_assign_submission_status_renderable($user, $showlinks) {
$submissiongroup,
$notsubmitted,
$this->is_any_submission_plugin_enabled(),
$gradelocked,
$submissionlocked,
$this->is_graded($user->id),
$instance->duedate,
$instance->cutoffdate,
Expand Down
47 changes: 47 additions & 0 deletions mod/assign/tests/locallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3096,4 +3096,51 @@ public function test_fix_null_grades($grade, $gradebookvalue) {
// Check that the grade was updated in the gradebook by fix_null_grades.
$this->assertEquals($gradebookvalue, $gradegrade->finalgrade);
}

/**
* Test grade override displays 'Graded' for students
*/
public function test_grade_submission_override() {
global $DB, $PAGE, $OUTPUT;

$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance(array('assignsubmission_onlinetext_enabled' => 1));

$studentid = $this->students[0]->id;

// Simulate adding a grade.
$this->setUser($this->teachers[0]);
$data = new stdClass();
$data->grade = '50.0';
$assign->testable_apply_grade_to_user($data, $studentid, 0);

// Set grade override.
$gradegrade = grade_grade::fetch(array('userid' => $studentid, 'itemid' => $assign->get_grade_item()->id));

// Check that grade submission is not overridden yet.
$this->assertEquals(false, $gradegrade->is_overridden());

// Simulate a submission.
$this->setUser($this->students[0]);
$submission = $assign->get_user_submission($studentid, true);

$PAGE->set_url(new moodle_url('/mod/assign/view.php', array('id' => $assign->get_course_module()->id)));

// Set override grade grade, and check that grade submission has been overridden.
$gradegrade->set_overridden(true);
$this->assertEquals(true, $gradegrade->is_overridden());

// Check that submissionslocked message 'This assignment is not accepting submissions' does not appear for student.
$gradingtable = new assign_grading_table($assign, 1, '', 0, true);
$output = $assign->get_renderer()->render($gradingtable);
$this->assertContains(get_string('submissionstatus_', 'assign'), $output);

$assignsubmissionstatus = $assign->get_assign_submission_status_renderable($this->students[0], true);
$output2 = $assign->get_renderer()->render($assignsubmissionstatus);

// Check that submissionslocked 'This assignment is not accepting submissions' message does not appear for student.
$this->assertNotContains(get_string('submissionslocked', 'assign'), $output2);
// Check that submissionstatus_marked 'Graded' message does appear for student.
$this->assertContains(get_string('submissionstatus_marked', 'assign'), $output2);
}
}

0 comments on commit ece94bb

Please sign in to comment.