MDL-60396 mod_workshop: Add checks for maximum gradeover

This commit is contained in:
Juan Leyva 2017-10-04 21:01:50 +02:00 committed by Eloy Lafuente (stronk7)
parent f4594a22ec
commit 011c5ae476
2 changed files with 27 additions and 0 deletions

View File

@ -2058,6 +2058,11 @@ class mod_workshop_external extends external_api {
$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;

View File

@ -1844,4 +1844,26 @@ class mod_workshop_external_testcase extends externallib_advanced_testcase {
$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']);
}
}