Skip to content

Commit

Permalink
MDL-66147 mod_assign: external get_participant supports relative dates
Browse files Browse the repository at this point in the history
  • Loading branch information
snake committed Aug 13, 2019
1 parent c0bb682 commit d0cff23
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mod/assign/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2821,10 +2821,10 @@ public static function get_participant($assignid, $userid, $embeduser) {
'requiregrading' => $participant->requiregrading,
'grantedextension' => $participant->grantedextension,
'blindmarking' => $assign->is_blind_marking(),
'allowsubmissionsfromdate' => $assign->get_instance()->allowsubmissionsfromdate,
'duedate' => $assign->get_instance()->duedate,
'cutoffdate' => $assign->get_instance()->cutoffdate,
'duedatestr' => userdate($assign->get_instance()->duedate, get_string('strftimedatetime', 'langconfig')),
'allowsubmissionsfromdate' => $assign->get_instance($userid)->allowsubmissionsfromdate,
'duedate' => $assign->get_instance($userid)->duedate,
'cutoffdate' => $assign->get_instance($userid)->cutoffdate,
'duedatestr' => userdate($assign->get_instance($userid)->duedate, get_string('strftimedatetime', 'langconfig')),
);

if (!empty($participant->groupid)) {
Expand Down
60 changes: 60 additions & 0 deletions mod/assign/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,66 @@ public function test_get_participant_group_submission() {
$this->assertEquals($group->name, $result['groupname']);
}

/**
* Test get_participant() when relative dates mode is enabled on the course.
*
* @dataProvider get_participant_relative_dates_provider
* @param array $courseconfig the config to use when creating the course.
* @param array $assignconfig the config to use when creating the assignment.
* @param array $enrolconfig the enrolement to create.
* @param array $expectedproperties array of expected assign properties.
*/
public function test_get_participant_relative_dates(array $courseconfig, array $assignconfig, array $enrolconfig,
array $expectedproperties) {
$this->resetAfterTest();

set_config('enablecourserelativedates', true); // Enable relative dates at site level.

$course = $this->getDataGenerator()->create_course($courseconfig);
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
$assignconfig['course'] = $course->id;
$instance = $generator->create_instance($assignconfig);
$cm = get_coursemodule_from_instance('assign', $instance->id);
$context = context_module::instance($cm->id);
$assign = new assign($context, $cm, $course);

$user = $this->getDataGenerator()->create_and_enrol($course, ...array_values($enrolconfig));

$teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher', null, 'manual', time() - 50 * DAYSECS);

$this->setUser($teacher);
$result = mod_assign_external::get_participant($assign->get_instance()->id, $user->id, false);
$result = external_api::clean_returnvalue(mod_assign_external::get_participant_returns(), $result);

foreach ($expectedproperties as $propertyname => $propertyval) {
$this->assertEquals($propertyval, $result[$propertyname]);
}
}

/**
* The test_get_participant_relative_dates data provider.
*/
public function get_participant_relative_dates_provider() {
$timenow = time();

return [
'Student whose enrolment starts after the course start date, relative dates mode enabled' => [
'courseconfig' => ['relativedatesmode' => true, 'startdate' => $timenow - 10 * DAYSECS],
'assignconfig' => ['duedate' => $timenow + 4 * DAYSECS],
'enrolconfig' => ['shortname' => 'student', 'userparams' => null, 'method' => 'manual',
'startdate' => $timenow - 8 * DAYSECS],
'expectedproperties' => ['duedate' => $timenow + 6 * DAYSECS]
],
'Student whose enrolment starts before the course start date, relative dates mode enabled' => [
'courseconfig' => ['relativedatesmode' => true, 'startdate' => $timenow - 10 * DAYSECS],
'assignconfig' => ['duedate' => $timenow + 4 * DAYSECS],
'enrolconfig' => ['shortname' => 'student', 'userparams' => null, 'method' => 'manual',
'startdate' => $timenow - 12 * DAYSECS],
'expectedproperties' => ['duedate' => $timenow + 4 * DAYSECS]
],
];
}

/**
* Test for mod_assign_external::list_participants().
*
Expand Down

0 comments on commit d0cff23

Please sign in to comment.