mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
Merge branch 'MDL-64648-401_enrol_manual_expirynotify_default_in_enrol_instance' of https://github.com/vtos/moodle into MOODLE_401_STABLE
This commit is contained in:
commit
4c6e5c977d
@ -127,18 +127,13 @@ class enrol_manual_plugin extends enrol_plugin {
|
||||
*/
|
||||
public function add_default_instance($course) {
|
||||
$expirynotify = $this->get_config('expirynotify', 0);
|
||||
if ($expirynotify == 2) {
|
||||
$expirynotify = 1;
|
||||
$notifyall = 1;
|
||||
} else {
|
||||
$notifyall = 0;
|
||||
}
|
||||
|
||||
$fields = array(
|
||||
'status' => $this->get_config('status'),
|
||||
'roleid' => $this->get_config('roleid', 0),
|
||||
'enrolperiod' => $this->get_config('enrolperiod', 0),
|
||||
'expirynotify' => $expirynotify,
|
||||
'notifyall' => $notifyall,
|
||||
'notifyall' => $expirynotify == 2 ? 1 : 0,
|
||||
'expirythreshold' => $this->get_config('expirythreshold', 86400),
|
||||
);
|
||||
return $this->add_instance($course, $fields);
|
||||
|
@ -25,6 +25,7 @@
|
||||
namespace enrol_manual;
|
||||
|
||||
use course_enrolment_manager;
|
||||
use stdClass;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@ -543,4 +544,107 @@ class lib_test extends \advanced_testcase {
|
||||
// Manual enrol has 2 enrol actions -- edit and unenrol.
|
||||
$this->assertCount(2, $actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test how the default enrolment instance inherits its settings from the global plugin settings.
|
||||
*
|
||||
* @dataProvider default_enrolment_instance_data_provider
|
||||
* @param stdClass $expectation
|
||||
* @param stdClass $globalsettings
|
||||
* @covers \enrol_manual::add_default_instance
|
||||
*/
|
||||
public function test_default_enrolment_instance_acquires_correct_settings(stdClass $expectation, stdClass $globalsettings) {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$generator = $this->getDataGenerator();
|
||||
|
||||
// Given the plugin is globally configured with the following settings.
|
||||
$plugin = enrol_get_plugin('manual');
|
||||
$plugin->set_config('status', $globalsettings->status);
|
||||
$plugin->set_config('roleid', $globalsettings->roleid);
|
||||
$plugin->set_config('enrolperiod', $globalsettings->enrolperiod);
|
||||
$plugin->set_config('expirynotify', $globalsettings->expirynotify);
|
||||
$plugin->set_config('expirythreshold', $globalsettings->expirythreshold);
|
||||
|
||||
// When creating a course.
|
||||
$course = $generator->create_course();
|
||||
|
||||
// Then the default manual enrolment instance being created is properly configured.
|
||||
$enrolinstance = $DB->get_record('enrol', ['courseid' => $course->id, 'enrol' => 'manual']);
|
||||
$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_default_enrolment_instance_acquires_correct_settings().
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function default_enrolment_instance_data_provider(): array {
|
||||
$studentroles = get_archetype_roles('student');
|
||||
$studentrole = array_shift($studentroles);
|
||||
|
||||
$teacherroles = get_archetype_roles('teacher');
|
||||
$teacherrole = array_shift($teacherroles);
|
||||
|
||||
return [
|
||||
'enabled, student role, no duration set, notify no one on expiry, 12 hours notification threshold' => [
|
||||
'expectation' => (object) [
|
||||
'status' => ENROL_INSTANCE_ENABLED,
|
||||
'roleid' => $studentrole->id,
|
||||
'enrolperiod' => 0,
|
||||
'expirynotify' => 0,
|
||||
'notifyall' => 0,
|
||||
'expirythreshold' => 12 * HOURSECS,
|
||||
],
|
||||
'global settings' => (object) [
|
||||
'status' => ENROL_INSTANCE_ENABLED,
|
||||
'roleid' => $studentrole->id,
|
||||
'enrolperiod' => 0,
|
||||
'expirynotify' => 0,
|
||||
'expirythreshold' => 12 * HOURSECS,
|
||||
],
|
||||
],
|
||||
'enabled, student role, 72 hours duration, notify enroller only on expiry, 1 day notification threshold' => [
|
||||
'expectation' => (object) [
|
||||
'status' => ENROL_INSTANCE_ENABLED,
|
||||
'roleid' => $studentrole->id,
|
||||
'enrolperiod' => 72 * HOURSECS,
|
||||
'expirynotify' => 1,
|
||||
'notifyall' => 0,
|
||||
'expirythreshold' => DAYSECS,
|
||||
],
|
||||
'global settings' => (object) [
|
||||
'status' => ENROL_INSTANCE_ENABLED,
|
||||
'roleid' => $studentrole->id,
|
||||
'enrolperiod' => 72 * HOURSECS,
|
||||
'expirynotify' => 1,
|
||||
'expirythreshold' => DAYSECS,
|
||||
],
|
||||
],
|
||||
'disabled, teacher role, no duration set, notify enroller and enrolled on expiry, 0 notification threshold' => [
|
||||
'expectation' => (object) [
|
||||
'status' => ENROL_INSTANCE_DISABLED,
|
||||
'roleid' => $teacherrole->id,
|
||||
'enrolperiod' => 0,
|
||||
'expirynotify' => 2,
|
||||
'notifyall' => 1,
|
||||
'expirythreshold' => 0
|
||||
],
|
||||
'global settings' => (object) [
|
||||
'status' => ENROL_INSTANCE_DISABLED,
|
||||
'roleid' => $teacherrole->id,
|
||||
'enrolperiod' => 0,
|
||||
'expirynotify' => 2,
|
||||
'expirythreshold' => 0,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user