Skip to content

Commit

Permalink
MDL-60396 mod_workshop: Add checks for maximum gradeover
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva authored and stronk7 committed Oct 10, 2017
1 parent f4594a2 commit 011c5ae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mod/workshop/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -2058,6 +2058,11 @@ public static function evaluate_submission($submissionid, $feedbacktext = '', $f
$feedbackform = $workshop->get_feedbackauthor_form(null, $submission, $options);

$errors = $feedbackform->validation((array) $data, array());
// Extra checks for the new grade (if set).
if (is_numeric($data->gradeover) && $data->gradeover > $workshop->grade) {
$errors['gradeover'] = 'The new grade cannot be higher than the maximum grade for submission.';
}

// We can get several errors, return them in warnings.
if (!empty($errors)) {
$status = false;
Expand Down
22 changes: 22 additions & 0 deletions mod/workshop/tests/external_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1844,4 +1844,26 @@ public function test_evaluate_submission_no_permissions() {
$this->expectException('moodle_exception');
mod_workshop_external::evaluate_submission($submissionid, $feedbacktext, $feedbackformat, $published, $gradeover);
}

/**
* Test evaluate_submission_invalid_grade.
*/
public function test_evaluate_submission_invalid_grade() {
global $DB;

$workshopgenerator = $this->getDataGenerator()->get_plugin_generator('mod_workshop');
$submissionid = $workshopgenerator->create_submission($this->workshop->id, $this->student->id);
$DB->set_field('workshop', 'phase', workshop::PHASE_EVALUATION, array('id' => $this->workshop->id));

$this->setUser($this->teacher);
$feedbacktext = 'The feedback';
$feedbackformat = FORMAT_MOODLE;
$published = 1;
$gradeover = 150;
$result = mod_workshop_external::evaluate_submission($submissionid, $feedbacktext, $feedbackformat, $published, $gradeover);
$result = external_api::clean_returnvalue(mod_workshop_external::evaluate_submission_returns(), $result);
$this->assertCount(1, $result['warnings']);
$this->assertFalse($result['status']);
$this->assertEquals('gradeover', $result['warnings'][0]['item']);
}
}

0 comments on commit 011c5ae

Please sign in to comment.