mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 04:22:07 +02:00
Merge branch 'MDL-79692' of https://github.com/paulholden/moodle
This commit is contained in:
commit
b684ef329e
@ -173,8 +173,8 @@ class enrol_meta_handler {
|
||||
$ue->userid = $userid;
|
||||
$ue->enrolid = $instance->id;
|
||||
$ue->status = $parentstatus;
|
||||
if ($instance->customint2) {
|
||||
groups_add_member($instance->customint2, $userid, 'enrol_meta', $instance->id);
|
||||
if ($instance->customint2 && $group = $DB->get_record('groups', ['id' => $instance->customint2])) {
|
||||
groups_add_member($group, $userid, 'enrol_meta', $instance->id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -346,8 +346,8 @@ function enrol_meta_sync($courseid = NULL, $verbose = false) {
|
||||
$ue->timestart = ($ue->timestart == 9999999999) ? 0 : (int)$ue->timestart;
|
||||
|
||||
$meta->enrol_user($instance, $ue->userid, null, $ue->timestart, $ue->timeend, $ue->status);
|
||||
if ($instance->customint2) {
|
||||
groups_add_member($instance->customint2, $ue->userid, 'enrol_meta', $instance->id);
|
||||
if ($instance->customint2 && $group = $DB->get_record('groups', ['id' => $instance->customint2])) {
|
||||
groups_add_member($group, $ue->userid, 'enrol_meta', $instance->id);
|
||||
}
|
||||
if ($verbose) {
|
||||
mtrace(" enrolling: $ue->userid ==> $instance->courseid");
|
||||
|
@ -17,6 +17,9 @@
|
||||
namespace enrol_meta;
|
||||
use core\plugininfo\enrol;
|
||||
|
||||
use context_course;
|
||||
use enrol_meta_plugin;
|
||||
|
||||
/**
|
||||
* Meta enrolment sync functional test.
|
||||
*
|
||||
@ -595,6 +598,40 @@ class plugin_test extends \advanced_testcase {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test enrolling users in a course, where the customint2 (group) property of the instance points to an invalid group
|
||||
*
|
||||
* @covers \enrol_meta_handler::sync_with_parent_course
|
||||
* @covers ::enrol_meta_sync
|
||||
*/
|
||||
public function test_add_to_group_invalid(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->enable_plugin();
|
||||
|
||||
$courseone = $this->getDataGenerator()->create_course();
|
||||
$coursetwo = $this->getDataGenerator()->create_course();
|
||||
|
||||
/** @var enrol_meta_plugin $plugin */
|
||||
$plugin = enrol_get_plugin('meta');
|
||||
$plugin->add_instance($coursetwo, ['customint1' => $courseone->id, 'customint2' => 42]);
|
||||
|
||||
// Ensure the event observer works for invalid groups.
|
||||
$userone = $this->getDataGenerator()->create_and_enrol($courseone);
|
||||
|
||||
// Now disable the plugin, add another enrolment.
|
||||
$this->disable_plugin();
|
||||
$usertwo = $this->getDataGenerator()->create_and_enrol($courseone);
|
||||
|
||||
// Re-enable the plugin, run sync task - should also work for invalid groups.
|
||||
$this->enable_plugin();
|
||||
enrol_meta_sync($coursetwo->id);
|
||||
|
||||
$coursetwocontext = context_course::instance($coursetwo->id);
|
||||
$this->assertTrue(is_enrolled($coursetwocontext, $userone));
|
||||
$this->assertTrue(is_enrolled($coursetwocontext, $usertwo));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test user_enrolment_created event.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user