Merge branch 'MDL-55046-master' of git://github.com/dpalou/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2016-07-26 19:40:52 +02:00
commit e23faa4c81
2 changed files with 65 additions and 0 deletions

View File

@ -473,6 +473,13 @@ class mod_assign_external extends external_api {
}
}
if ($module->requiresubmissionstatement) {
// Submission statement is required, return the submission statement value.
$adminconfig = get_config('assign');
list($assignment['submissionstatement'], $assignment['submissionstatementformat']) = external_format_text(
$adminconfig->submissionstatement, FORMAT_MOODLE, $context->id, 'mod_assign', '', 0);
}
$assignmentarray[] = $assignment;
}
}
@ -527,6 +534,8 @@ class mod_assign_external extends external_api {
'markingallocation' => new external_value(PARAM_INT, 'enable marking allocation'),
'requiresubmissionstatement' => new external_value(PARAM_INT, 'student must accept submission statement'),
'preventsubmissionnotingroup' => new external_value(PARAM_INT, 'Prevent submission not in group', VALUE_OPTIONAL),
'submissionstatement' => new external_value(PARAM_RAW, 'Submission statement formatted.', VALUE_OPTIONAL),
'submissionstatementformat' => new external_format_value('submissionstatement', VALUE_OPTIONAL),
'configs' => new external_multiple_structure(self::get_assignments_config_structure(), 'configuration settings'),
'intro' => new external_value(PARAM_RAW,
'assignment intro, not allways returned because it deppends on the activity configuration', VALUE_OPTIONAL),

View File

@ -300,6 +300,62 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
$this->assertEquals(0, $assignment['preventsubmissionnotingroup']);
}
/**
* Test get_assignments with submissionstatement.
*/
public function test_get_assignments_with_submissionstatement() {
global $DB, $USER, $CFG;
$this->resetAfterTest(true);
// Setup test data. Create 2 assigns, one with requiresubmissionstatement and the other without it.
$course = $this->getDataGenerator()->create_course();
$assign = $this->getDataGenerator()->create_module('assign', array(
'course' => $course->id,
'requiresubmissionstatement' => 1
));
$assign2 = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
// Create student.
$student = self::getDataGenerator()->create_user();
// Users enrolments.
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->getDataGenerator()->enrol_user($student->id, $course->id, $studentrole->id, 'manual');
// Update the submissionstatement.
$submissionstatement = 'This is a fake submission statement.';
set_config('submissionstatement', $submissionstatement, 'assign');
$this->setUser($student);
$result = mod_assign_external::get_assignments();
// We need to execute the return values cleaning process to simulate the web service server.
$result = external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
// Check that the amount of courses and assignments is right.
$this->assertCount(1, $result['courses']);
$assignmentsret = $result['courses'][0]['assignments'];
$this->assertCount(2, $assignmentsret);
// Order the returned assignments by ID.
usort($assignmentsret, function($a, $b) {
return strcmp($a['id'], $b['id']);
});
// Check that the first assign contains the submission statement.
$assignmentret = $assignmentsret[0];
$this->assertEquals($assign->id, $assignmentret['id']);
$this->assertEquals(1, $assignmentret['requiresubmissionstatement']);
$this->assertEquals($submissionstatement, $assignmentret['submissionstatement']);
// Check that the second assign does NOT contain the submission statement.
$assignmentret = $assignmentsret[1];
$this->assertEquals($assign2->id, $assignmentret['id']);
$this->assertEquals(0, $assignmentret['requiresubmissionstatement']);
$this->assertArrayNotHasKey('submissionstatement', $assignmentret);
}
/**
* Test get_submissions
*/