Permalink
Browse files

Merge branch 'MDL-60348-master' of git://github.com/jleyva/moodle

  • Loading branch information...
dmonllao committed Oct 30, 2017
2 parents 6065875 + 7336f85 commit 860d33c90acfbc99844de804857adde5a21b5c58
Showing with 37 additions and 9 deletions.
  1. +12 −0 mod/workshop/classes/external.php
  2. +25 −9 mod/workshop/tests/external_test.php
@@ -1728,6 +1728,18 @@ public static function evaluate_assessment($assessmentid, $feedbacktext = '', $f
$feedbackform = $workshop->get_feedbackreviewer_form(null, $assessment, $options);
$errors = $feedbackform->validation((array) $data, array());
// Extra checks for the new grade and weight.
$possibleweights = workshop::available_assessment_weights_list();
if ($data->weight < 0 || $data->weight > max(array_keys($possibleweights))) {
$errors['weight'] = 'The new weight must be higher or equal to 0 and cannot be higher than the maximum weight for
assessment.';
}
if (is_numeric($data->gradinggradeover) &&
($data->gradinggradeover < 0 || $data->gradinggradeover > $workshop->gradinggrade)) {
$errors['gradinggradeover'] = 'The new grade must be higher or equal to 0 and cannot be higher than the maximum grade
for assessment.';
}
// We can get several errors, return them in warnings.
if (!empty($errors)) {
$status = false;
@@ -1612,13 +1612,13 @@ public function test_evaluate_assessment() {
$submissionid = $workshopgenerator->create_submission($this->workshop->id, $this->student->id);
$assessmentid = $workshopgenerator->create_assessment($submissionid, $this->anotherstudentg1->id, array(
'weight' => 3,
'grade' => 95,
'grade' => 20,
));
$this->setUser($this->teacher);
$feedbacktext = 'The feedback';
$feedbackformat = FORMAT_MOODLE;
$weight = 25;
$weight = 10;
$gradinggradeover = 10;
$result = mod_workshop_external::evaluate_assessment($assessmentid, $feedbacktext, $feedbackformat, $weight,
$gradinggradeover);
@@ -1627,7 +1627,23 @@ public function test_evaluate_assessment() {
$assessment = $DB->get_record('workshop_assessments', array('id' => $assessmentid));
$this->assertEquals('The feedback', $assessment->feedbackreviewer);
$this->assertEquals(25, $assessment->weight);
$this->assertEquals(10, $assessment->weight);
// Now test passing incorrect weight and grade values.
$weight = 17;
$gradinggradeover = 100;
$result = mod_workshop_external::evaluate_assessment($assessmentid, $feedbacktext, $feedbackformat, $weight,
$gradinggradeover);
$result = external_api::clean_returnvalue(mod_workshop_external::evaluate_assessment_returns(), $result);
$this->assertFalse($result['status']);
$this->assertCount(2, $result['warnings']);
$found = 0;
foreach ($result['warnings'] as $warning) {
if ($warning['item'] == 'weight' || $warning['item'] == 'gradinggradeover') {
$found++;
}
}
$this->assertEquals(2, $found);
}
/**
@@ -1638,7 +1654,7 @@ public function test_evaluate_assessment_ignore_parameters() {
$submissionid = $workshopgenerator->create_submission($this->workshop->id, $this->student->id);
$assessmentid = $workshopgenerator->create_assessment($submissionid, $this->anotherstudentg1->id, array(
'weight' => 3,
'grade' => 95,
'grade' => 20,
));
assign_capability('mod/workshop:allocate', CAP_PROHIBIT, $this->teacherrole->id, $this->context->id);
@@ -1648,16 +1664,16 @@ public function test_evaluate_assessment_ignore_parameters() {
$this->setUser($this->teacher);
$feedbacktext = 'The feedback';
$feedbackformat = FORMAT_MOODLE;
$weight = 25;
$gradinggradeover = 1000;
$weight = 10;
$gradinggradeover = 19;
$result = mod_workshop_external::evaluate_assessment($assessmentid, $feedbacktext, $feedbackformat, $weight,
$gradinggradeover);
$result = external_api::clean_returnvalue(mod_workshop_external::evaluate_assessment_returns(), $result);
$this->assertTrue($result['status']);
$result = mod_workshop_external::get_assessment($assessmentid);
$result = external_api::clean_returnvalue(mod_workshop_external::get_assessment_returns(), $result);
$this->assertNotEquals(25, $result['assessment']['weight']);
$this->assertNotEquals(10, $result['assessment']['weight']);
}
/**
@@ -1668,13 +1684,13 @@ public function test_evaluate_assessment_no_permissions() {
$submissionid = $workshopgenerator->create_submission($this->workshop->id, $this->student->id);
$assessmentid = $workshopgenerator->create_assessment($submissionid, $this->anotherstudentg1->id, array(
'weight' => 3,
'grade' => 95,
'grade' => 20,
));
$this->setUser($this->student);
$feedbacktext = 'The feedback';
$feedbackformat = FORMAT_MOODLE;
$weight = 25;
$weight = 10;
$gradinggradeover = 50;
$this->expectException('moodle_exception');
mod_workshop_external::evaluate_assessment($assessmentid, $feedbacktext, $feedbackformat, $weight, $gradinggradeover);

0 comments on commit 860d33c

Please sign in to comment.