mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-61811 enrol_manual: fixed updating of 'notifyall' field
When updating a manual enrolment instance, the value of 'notifyall' field must be calculated automatically based on the value of 'expirynotify' field. The relevant plugin's method missed that, thus, the value of 'notifyall' field was never updated when editing a manual enrolment instance and changing the 'expirynotify' setting. A functional test has been added to test the entire behaviour of the relevant plugin's method.
This commit is contained in:
parent
bc67d4491c
commit
db8e366ed9
@ -173,6 +173,9 @@ class enrol_manual_plugin extends enrol_plugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data->notifyall = $data->expirynotify == 2 ? 1 : 0;
|
||||
|
||||
return parent::update_instance($instance, $data);
|
||||
}
|
||||
|
||||
|
@ -647,4 +647,118 @@ class lib_test extends \advanced_testcase {
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests an enrolment instance is updated properly.
|
||||
*
|
||||
* @covers \enrol_manual::update_instance
|
||||
* @dataProvider update_enrolment_instance_data_provider
|
||||
*
|
||||
* @param stdClass $expectation
|
||||
* @param stdClass $updatedata
|
||||
*/
|
||||
public function test_enrolment_instance_is_updated(stdClass $expectation, stdClass $updatedata): void {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$generator = $this->getDataGenerator();
|
||||
|
||||
$studentroles = get_archetype_roles('student');
|
||||
$studentrole = array_shift($studentroles);
|
||||
|
||||
// Given the plugin is globally configured with the following settings.
|
||||
$plugin = enrol_get_plugin('manual');
|
||||
$plugin->set_config('status', ENROL_INSTANCE_ENABLED);
|
||||
$plugin->set_config('roleid', $studentrole->id);
|
||||
$plugin->set_config('enrolperiod', 30 * DAYSECS);
|
||||
$plugin->set_config('expirynotify', 1);
|
||||
$plugin->set_config('expirythreshold', 2 * DAYSECS);
|
||||
|
||||
// And a course is created with the default enrolment instance.
|
||||
$course = $generator->create_course();
|
||||
|
||||
// When the enrolment instance is being updated.
|
||||
$enrolinstance = $DB->get_record('enrol', ['courseid' => $course->id, 'enrol' => 'manual']);
|
||||
$successfullyupdated = $plugin->update_instance($enrolinstance, $updatedata);
|
||||
|
||||
// Then the update is successful.
|
||||
$this->assertTrue($successfullyupdated);
|
||||
|
||||
// And the updated enrolment instance contains the expected values.
|
||||
$enrolinstance = $DB->get_record('enrol', ['id' => $enrolinstance->id]);
|
||||
$this->assertEquals($expectation->status, $enrolinstance->status);
|
||||
$this->assertEquals($expectation->roleid, $enrolinstance->roleid);
|
||||
$this->assertEquals($expectation->enrolperiod, $enrolinstance->enrolperiod);
|
||||
$this->assertEquals($expectation->expirynotify, $enrolinstance->expirynotify);
|
||||
$this->assertEquals($expectation->notifyall, $enrolinstance->notifyall);
|
||||
$this->assertEquals($expectation->expirythreshold, $enrolinstance->expirythreshold);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_enrolment_instance_is_updated().
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function update_enrolment_instance_data_provider(): array {
|
||||
$studentroles = get_archetype_roles('student');
|
||||
$studentrole = array_shift($studentroles);
|
||||
|
||||
$teacherroles = get_archetype_roles('teacher');
|
||||
$teacherrole = array_shift($teacherroles);
|
||||
|
||||
return [
|
||||
'disabled, all the others are default' => [
|
||||
'expectation' => (object) [
|
||||
'status' => ENROL_INSTANCE_DISABLED,
|
||||
'roleid' => $studentrole->id,
|
||||
'enrolperiod' => 30 * DAYSECS,
|
||||
'expirynotify' => 1,
|
||||
'notifyall' => 0,
|
||||
'expirythreshold' => 2 * DAYSECS,
|
||||
],
|
||||
'update data' => (object) [
|
||||
'status' => ENROL_INSTANCE_DISABLED,
|
||||
'roleid' => $studentrole->id,
|
||||
'enrolperiod' => 30 * DAYSECS,
|
||||
'expirynotify' => 1,
|
||||
'expirythreshold' => 2 * DAYSECS,
|
||||
],
|
||||
],
|
||||
'enabled, teacher role, no duration set, notify no one on expiry, 0 notification threshold' => [
|
||||
'expectation' => (object) [
|
||||
'status' => ENROL_INSTANCE_ENABLED,
|
||||
'roleid' => $teacherrole->id,
|
||||
'enrolperiod' => 0,
|
||||
'expirynotify' => 0,
|
||||
'notifyall' => 0,
|
||||
'expirythreshold' => 0,
|
||||
],
|
||||
'update data' => (object) [
|
||||
'status' => ENROL_INSTANCE_ENABLED,
|
||||
'roleid' => $teacherrole->id,
|
||||
'enrolperiod' => 0,
|
||||
'expirynotify' => 0,
|
||||
'expirythreshold' => 0,
|
||||
],
|
||||
],
|
||||
'notify enroller and enrolled on expiry, all the others are default' => [
|
||||
'expectation' => (object) [
|
||||
'status' => ENROL_INSTANCE_ENABLED,
|
||||
'roleid' => $studentrole->id,
|
||||
'enrolperiod' => 30 * DAYSECS,
|
||||
'expirynotify' => 2,
|
||||
'notifyall' => 1,
|
||||
'expirythreshold' => 2 * DAYSECS,
|
||||
],
|
||||
'update data' => (object) [
|
||||
'status' => ENROL_INSTANCE_ENABLED,
|
||||
'roleid' => $studentrole->id,
|
||||
'enrolperiod' => 30 * DAYSECS,
|
||||
'expirynotify' => 2,
|
||||
'expirythreshold' => 2 * DAYSECS,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user