first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+112
View File
@@ -0,0 +1,112 @@
@enrol @enrol_meta @javascript
Feature: Enrolments are synchronised with meta courses
In order to simplify enrolments in parent courses
As a teacher
I need to be able to set up meta enrolments
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@asd.com |
| student2 | Student | 2 | student2@asd.com |
| student3 | Student | 3 | student3@asd.com |
| student4 | Student | 4 | student4@asd.com |
And the following "courses" exist:
| fullname | shortname |
| Course 1 | C1C1 |
| Course 2 | C2C2 |
| Course 3 | C3C3 |
| Course 4 | C4C4 |
And the following "groups" exist:
| name | course | idnumber |
| Groupcourse 1 | C3C3 | G1 |
| Groupcourse 2 | C3C3 | G2 |
And the following "course enrolments" exist:
| user | course | role | status |
| student1 | C1C1 | student | 0 |
| student2 | C1C1 | student | 0 |
| student3 | C1C1 | student | 0 |
| student4 | C1C1 | student | 0 |
| student1 | C2C2 | student | 0 |
| student2 | C2C2 | student | 0 |
| student1 | C4C4 | student | 0 |
| student2 | C4C4 | student | 1 |
And the following config values are set as admin:
| enableasyncbackup | 0 |
And I log in as "admin"
And I navigate to "Plugins > Enrolments > Manage enrol plugins" in site administration
And I click on "Enable" "link" in the "Course meta link" "table_row"
And I am on course index
Scenario: Add meta enrolment instance without groups
When I add "Course meta link" enrolment method in "Course 3" with:
| Link course | C1C1 |
And I am on the "Course 3" "enrolled users" page
Then I should see "No groups" in the "Student 1" "table_row"
And I should see "No groups" in the "Student 4" "table_row"
Scenario: Add meta enrolment instance with groups
When I add "Course meta link" enrolment method in "Course 3" with:
| Link course | C1C1 |
| Add to group | Groupcourse 1 |
And I add "Course meta link" enrolment method in "Course 3" with:
| Link course | C2C2 |
| Add to group | Groupcourse 2 |
And I am on the "Course 3" "enrolled users" page
Then I should see "Groupcourse 1" in the "Student 1" "table_row"
And I should see "Groupcourse 1" in the "Student 2" "table_row"
And I should see "Groupcourse 1" in the "Student 3" "table_row"
And I should see "Groupcourse 1" in the "Student 4" "table_row"
And I should see "Groupcourse 2" in the "Student 1" "table_row"
And I should see "Groupcourse 2" in the "Student 2" "table_row"
And I should not see "Groupcourse 2" in the "Student 3" "table_row"
And I should not see "Groupcourse 2" in the "Student 4" "table_row"
Scenario: Add meta enrolment instance with auto-created groups
When I add "Course meta link" enrolment method in "Course 3" with:
| Link course | C1C1 |
| Add to group | Create new group |
And I am on the "Course 3" "enrolled users" page
Then I should see "Course 1 course" in the "Student 1" "table_row"
And I should see "Course 1 course" in the "Student 2" "table_row"
And I should see "Course 1 course" in the "Student 3" "table_row"
And I should see "Course 1 course" in the "Student 4" "table_row"
And I am on the "Course 3" "groups" page
And the "Groups" select box should contain "Course 1 course (4)"
Scenario: Backup and restore of meta enrolment instance
When I add "Course meta link" enrolment method in "Course 3" with:
| Link course | C1C1 |
| Add to group | Groupcourse 1 |
And I add "Course meta link" enrolment method in "Course 3" with:
| Link course | C2C2 |
When I backup "Course 3" course using this options:
| Confirmation | Filename | test_backup.mbz |
And I click on "Restore" "link" in the "test_backup.mbz" "table_row"
And I press "Continue"
And I set the field "targetid" to "1"
And I click on "Continue" "button" in the ".bcs-new-course" "css_element"
And I press "Next"
And I set the field "Course name" to "Course 5"
And I press "Next"
And I press "Perform restore"
And I trigger cron
And I am on the "Course 5 copy 1" "enrolment methods" page
Then I should see "Course meta link (Course 1)"
And I should see "Course meta link (Course 2)"
And I am on the "Course 5 copy 1" "enrolled users" page
And I should see "Groupcourse 1" in the "Student 1" "table_row"
And I should see "Groupcourse 1" in the "Student 2" "table_row"
And I should see "Groupcourse 1" in the "Student 3" "table_row"
And I should see "Groupcourse 1" in the "Student 4" "table_row"
And I click on "[data-enrolinstancename='Course meta link (Course 2)'] a[data-action=showdetails]" "css_element" in the "Student 1" "table_row"
And I should see "Course meta link (Course 2)" in the "Enrolment method" "table_row"
Scenario: Unenrol a user from the course participants page that was enrolled via course meta link.
Given I add "Course meta link" enrolment method in "Course 3" with:
| Link course | C4C4 |
And I navigate to course participants
# Suspended users can be unenrolled.
When I click on "//a[@data-action='unenrol']" "xpath_element" in the "student2" "table_row"
And I click on "Unenrol" "button" in the "Unenrol" "dialogue"
Then I should not see "Student 2" in the "participants" "table"
+152
View File
@@ -0,0 +1,152 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace enrol_meta\external;
use core_external\external_api;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
/**
* Tests for add_instances external class
*
* @package enrol_meta
* @group enrol_meta
* @category test
* @copyright 2021 WKS KV Bildung
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class add_instances_test extends \externallib_advanced_testcase {
/**
* Test setup
*/
public function setUp(): void {
$this->resetAfterTest();
$this->setAdminUser();
}
/**
* Test add_instances no instances.
*/
public function test_add_instances_no_instances(): void {
$this->expectException(\invalid_parameter_exception::class);
add_instances::execute([]);
}
/**
* Test add_instances missing courses.
*/
public function test_add_instances_missing_courses(): void {
$course = self::getDataGenerator()->create_course();
// Missing meta course.
try {
add_instances::execute([['metacourseid' => 1000, 'courseid' => $course->id]]);
$this->fail('Exception expected');
} catch (\moodle_exception $e) {
$this->assertStringContainsString(get_string('wsinvalidmetacourse', 'enrol_meta', 1000), $e->getMessage());
}
// Missing linked course.
try {
add_instances::execute([['metacourseid' => $course->id, 'courseid' => 1000]]);
$this->fail('Exception expected');
} catch (\moodle_exception $e) {
$this->assertStringContainsString(get_string('wsinvalidcourse', 'enrol_meta', 1000), $e->getMessage());
}
}
/**
* Test add_instances missing capabilities.
*/
public function test_add_instances_missing_capabilities(): void {
$metacourse = self::getDataGenerator()->create_course();
$course = self::getDataGenerator()->create_course();
$user = self::getDataGenerator()->create_user();
$this::setUser($user);
// Missing rights in meta course.
try {
add_instances::execute([['metacourseid' => $metacourse->id, 'courseid' => $course->id]]);
$this->fail('Exception expected');
} catch (\moodle_exception $e) {
$this->assertStringContainsString(get_string('wsinvalidmetacourse', 'enrol_meta', $metacourse->id), $e->getMessage());
}
// Add rights for metacourse.
$metacontext = \context_course::instance($metacourse->id);
$roleid = $this->assignUserCapability('enrol/meta:config', $metacontext->id);
$this->assignUserCapability('moodle/course:view', $metacontext->id, $roleid);
$this->assignUserCapability('moodle/course:enrolconfig', $metacontext->id, $roleid);
// Missing rights for linked course.
try {
add_instances::execute([['metacourseid' => $metacourse->id, 'courseid' => $course->id]]);
$this->fail('Exception expected');
} catch (\moodle_exception $e) {
$this->assertStringContainsString(get_string('wsinvalidcourse', 'enrol_meta', $course->id), $e->getMessage());
}
// Add rights for linked course.
$context = \context_course::instance($course->id);
$this->assignUserCapability('moodle/course:view', $context->id, $roleid);
$this->assignUserCapability('enrol/meta:selectaslinked', $context->id, $roleid);
$result = add_instances::execute([['metacourseid' => $metacourse->id, 'courseid' => $course->id]]);
$this->assertNotEmpty($result);
}
/**
* Test add_instances.
*/
public function test_add_instances(): void {
global $DB;
$metacourse = self::getDataGenerator()->create_course();
$course = self::getDataGenerator()->create_course();
// Sanity check.
$enrolrecords = $DB->count_records('enrol',
['enrol' => 'meta', 'courseid' => $metacourse->id, 'customint1' => $course->id]);
$this->assertEquals(0, $enrolrecords);
// Add instance.
$result = add_instances::execute([['metacourseid' => $metacourse->id, 'courseid' => $course->id]]);
$result = external_api::clean_returnvalue(add_instances::execute_returns(), $result);
$this->assertEquals($result[0]['metacourseid'], $metacourse->id);
$this->assertEquals($result[0]['courseid'], $course->id);
$this->assertEquals($result[0]['status'], 1);
// Check instance was created.
$enrolrecords = $DB->count_records('enrol',
['enrol' => 'meta', 'courseid' => $result[0]['metacourseid'], 'customint1' => $result[0]['courseid']]);
$this->assertEquals(1, $enrolrecords);
// Add same instance.
$result = add_instances::execute([['metacourseid' => $metacourse->id, 'courseid' => $course->id]]);
$result = external_api::clean_returnvalue(add_instances::execute_returns(), $result);
$this->assertEquals($result[0]['metacourseid'], $metacourse->id);
$this->assertEquals($result[0]['courseid'], $course->id);
$this->assertEquals($result[0]['status'], 0);
// Check no new instance was created.
$enrolrecords = $DB->count_records('enrol',
['enrol' => 'meta', 'courseid' => $result[0]['metacourseid'], 'customint1' => $result[0]['courseid']]);
$this->assertEquals(1, $enrolrecords);
}
}
+142
View File
@@ -0,0 +1,142 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace enrol_meta\external;
use core_external\external_api;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
/**
* Tests for delete_instances external class
*
* @package enrol_meta
* @group enrol_meta
* @category test
* @copyright 2021 WKS KV Bildung
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class delete_instances_test extends \externallib_advanced_testcase {
/**
* Test setup
*/
public function setUp(): void {
$this->resetAfterTest();
$this->setAdminUser();
}
/**
* Test delete_instances no instances.
*/
public function test_delete_instances_no_instances(): void {
$this->expectException(\invalid_parameter_exception::class);
delete_instances::execute([]);
}
/**
* Test delete_instances missing courses.
*/
public function test_delete_instances_missing_courses(): void {
$course = self::getDataGenerator()->create_course();
// Missing meta course.
try {
delete_instances::execute([['metacourseid' => 1000, 'courseid' => $course->id]]);
$this->fail('Exception expected');
} catch (\moodle_exception $e) {
$this->assertStringContainsString(get_string('wsinvalidmetacourse', 'enrol_meta', 1000), $e->getMessage());
}
// Missing linked course.
try {
delete_instances::execute([['metacourseid' => $course->id, 'courseid' => 1000]]);
$this->fail('Exception expected');
} catch (\moodle_exception $e) {
$this->assertStringContainsString(get_string('wsinvalidcourse', 'enrol_meta', 1000), $e->getMessage());
}
}
/**
* Test delete_instances missing capabilities.
*/
public function test_delete_instances_missing_capabilities(): void {
$metacourse = self::getDataGenerator()->create_course();
$course = self::getDataGenerator()->create_course();
$user = self::getDataGenerator()->create_user();
$this::setUser($user);
// Missing rights in meta course.
try {
delete_instances::execute([['metacourseid' => $metacourse->id, 'courseid' => $course->id]]);
$this->fail('Exception expected');
} catch (\moodle_exception $e) {
$this->assertStringContainsString(get_string('wsinvalidmetacourse', 'enrol_meta', $metacourse->id), $e->getMessage());
}
// Add rights for metacourse.
$metacontext = \context_course::instance($metacourse->id);
$roleid = $this->assignUserCapability('enrol/meta:config', $metacontext->id);
$this->assignUserCapability('moodle/course:view', $metacontext->id, $roleid);
$this->assignUserCapability('moodle/course:enrolconfig', $metacontext->id, $roleid);
$result = delete_instances::execute([['metacourseid' => $metacourse->id, 'courseid' => $course->id]]);
$this->assertNotEmpty($result);
}
/**
* Test delete_instances.
*/
public function test_delete_instances(): void {
global $DB;
$metacourse = self::getDataGenerator()->create_course();
$course = self::getDataGenerator()->create_course();
// Create instance.
$enrolplugin = enrol_get_plugin('meta');
$fields = [
'customint1' => $course->id,
'customint2' => 0,
];
$enrolplugin->add_instance($metacourse, $fields);
// Sanity check.
$enrolrecords = $DB->count_records('enrol',
['enrol' => 'meta', 'courseid' => $metacourse->id, 'customint1' => $course->id]);
$this->assertEquals(1, $enrolrecords);
// Delete instance.
$result = delete_instances::execute([['metacourseid' => $metacourse->id, 'courseid' => $course->id]]);
$result = external_api::clean_returnvalue(add_instances::execute_returns(), $result);
$this->assertEquals($result[0]['metacourseid'], $metacourse->id);
$this->assertEquals($result[0]['courseid'], $course->id);
$this->assertEquals($result[0]['status'], 1);
// Check instance was deleted.
$enrolrecords = $DB->count_records('enrol',
['enrol' => 'meta', 'courseid' => $result[0]['metacourseid'], 'customint1' => $result[0]['courseid']]);
$this->assertEquals(0, $enrolrecords);
// Delete same instance.
$result = delete_instances::execute([['metacourseid' => $metacourse->id, 'courseid' => $course->id]]);
$result = external_api::clean_returnvalue(add_instances::execute_returns(), $result);
$this->assertEquals($result[0]['metacourseid'], $metacourse->id);
$this->assertEquals($result[0]['courseid'], $course->id);
$this->assertEquals($result[0]['status'], 0);
}
}
File diff suppressed because it is too large Load Diff
+303
View File
@@ -0,0 +1,303 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Base class for unit tests for enrol_meta.
*
* @package enrol_meta
* @category test
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace enrol_meta\privacy;
defined('MOODLE_INTERNAL') || die();
use core_privacy\local\request\writer;
use core_privacy\local\request\approved_contextlist;
use enrol_meta\privacy\provider;
/**
* Unit tests for the enrol_meta implementation of the privacy API.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider_test extends \core_privacy\tests\provider_testcase {
/**
* Enable enrol_meta plugin.
*/
protected function enable_plugin() {
$enabled = enrol_get_plugins(true);
$enabled['meta'] = true;
$enabled = array_keys($enabled);
set_config('enrol_plugins_enabled', implode(',', $enabled));
}
/**
* Test getting the context for the user ID related to this plugin.
*/
public function test_get_contexts_for_userid(): void {
global $DB;
$this->resetAfterTest();
$metaplugin = enrol_get_plugin('meta');
$user1 = $this->getDataGenerator()->create_user();
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course1->id));
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->enable_plugin();
$metaplugin->add_instance($course1, array('customint1' => $course2->id, 'customint2' => $group1->id));
$this->getDataGenerator()->enrol_user($user1->id, $course2->id, $studentrole->id);
// Check if user1 is enrolled into course1 in group 1.
$this->assertTrue(groups_is_member($group1->id, $user1->id));
$this->assertTrue($DB->record_exists('groups_members',
array(
'groupid' => $group1->id,
'userid' => $user1->id,
'component' => 'enrol_meta'
)
));
// Check context course fro provider to user1.
$context = \context_course::instance($course1->id);
$contextlist = provider::get_contexts_for_userid($user1->id);
$this->assertEquals($context->id, $contextlist->current()->id);
}
/**
* Test that user data is exported correctly.
*/
public function test_export_user_data(): void {
global $DB;
$this->resetAfterTest();
$metaplugin = enrol_get_plugin('meta');
$user1 = $this->getDataGenerator()->create_user();
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course1->id));
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->enable_plugin();
$metaplugin->add_instance($course1, array('customint1' => $course2->id, 'customint2' => $group1->id));
$this->getDataGenerator()->enrol_user($user1->id, $course2->id, $studentrole->id);
$this->setUser($user1);
$contextlist = provider::get_contexts_for_userid($user1->id);
$approvedcontextlist = new approved_contextlist($user1, 'enrol_meta', $contextlist->get_contextids());
provider::export_user_data($approvedcontextlist);
foreach ($contextlist as $context) {
/** @var \core_privacy\tests\request\content_writer $writer */
$writer = writer::with_context($context);
$data = $writer->get_data([
get_string('pluginname', 'enrol_meta'),
get_string('groups', 'core_group')
]);
$this->assertTrue($writer->has_any_data());
if ($context->contextlevel == CONTEXT_COURSE) {
$exportedgroups = $data->groups;
// User1 only belongs to group1 via enrol_meta.
$this->assertCount(1, $exportedgroups);
$exportedgroup = reset($exportedgroups);
$this->assertEquals($group1->name, $exportedgroup->name);
}
}
}
/**
* Test for provider::delete_data_for_all_users_in_context().
*/
public function test_delete_data_for_all_users_in_context(): void {
global $DB;
$this->resetAfterTest();
$metaplugin = enrol_get_plugin('meta');
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$user3 = $this->getDataGenerator()->create_user();
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course1->id));
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->enable_plugin();
$metaplugin->add_instance($course1, array('customint1' => $course2->id, 'customint2' => $group1->id));
$this->getDataGenerator()->enrol_user($user1->id, $course2->id, $studentrole->id);
$this->getDataGenerator()->enrol_user($user2->id, $course2->id, $studentrole->id);
$this->getDataGenerator()->enrol_user($user3->id, $course2->id, $studentrole->id);
$this->assertEquals(
3,
$DB->count_records_sql("SELECT COUNT(gm.id)
FROM {groups_members} gm
JOIN {groups} g ON gm.groupid = g.id
WHERE g.courseid = ?", [$course1->id])
);
$coursecontext1 = \context_course::instance($course1->id);
provider::delete_data_for_all_users_in_context($coursecontext1);
$this->assertEquals(
0,
$DB->count_records_sql("SELECT COUNT(gm.id)
FROM {groups_members} gm
JOIN {groups} g ON gm.groupid = g.id
WHERE g.courseid = ?", [$course1->id])
);
}
/**
* Test for provider::delete_data_for_user().
*/
public function test_delete_data_for_user(): void {
global $DB;
$this->resetAfterTest();
$metaplugin = enrol_get_plugin('meta');
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$user3 = $this->getDataGenerator()->create_user();
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course1->id));
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->enable_plugin();
$metaplugin->add_instance($course1, array('customint1' => $course2->id, 'customint2' => $group1->id));
$this->getDataGenerator()->enrol_user($user1->id, $course2->id, $studentrole->id);
$this->getDataGenerator()->enrol_user($user2->id, $course2->id, $studentrole->id);
$this->getDataGenerator()->enrol_user($user3->id, $course2->id, $studentrole->id);
$this->assertEquals(
3,
$DB->count_records_sql("SELECT COUNT(gm.id)
FROM {groups_members} gm
JOIN {groups} g ON gm.groupid = g.id
WHERE g.courseid = ?", [$course1->id])
);
$this->setUser($user1);
$coursecontext1 = \context_course::instance($course1->id);
$coursecontext2 = \context_course::instance($course2->id);
$approvedcontextlist = new \core_privacy\tests\request\approved_contextlist($user1, 'enrol_meta',
[$coursecontext1->id]);
provider::delete_data_for_user($approvedcontextlist);
// Check we have 2 users in groups because we are deleted user1.
$this->assertEquals(
2,
$DB->count_records_sql("SELECT COUNT(gm.id)
FROM {groups_members} gm
JOIN {groups} g ON gm.groupid = g.id
WHERE g.courseid = ?", [$course1->id])
);
}
/**
* Test for provider::delete_data_for_users().
*/
public function test_delete_data_for_users(): void {
global $DB;
$this->resetAfterTest();
$metaplugin = enrol_get_plugin('meta');
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$user3 = $this->getDataGenerator()->create_user();
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course1->id));
$this->enable_plugin();
$metaplugin->add_instance($course1, array('customint1' => $course2->id, 'customint2' => $group1->id));
$this->getDataGenerator()->enrol_user($user1->id, $course2->id, 'student');
$this->getDataGenerator()->enrol_user($user2->id, $course2->id, 'student');
$this->getDataGenerator()->enrol_user($user3->id, $course2->id, 'student');
$this->assertEquals(
3,
$DB->count_records_sql("SELECT COUNT(gm.id)
FROM {groups_members} gm
JOIN {groups} g ON gm.groupid = g.id
WHERE g.courseid = ?", [$course1->id])
);
$coursecontext1 = \context_course::instance($course1->id);
$approveduserlist = new \core_privacy\local\request\approved_userlist($coursecontext1, 'enrol_meta',
[$user1->id, $user2->id]);
provider::delete_data_for_users($approveduserlist);
// Check we have 1 user in groups because we have deleted user1 and user2.
$this->assertEquals(
1,
$DB->count_records_sql("SELECT COUNT(gm.id)
FROM {groups_members} gm
JOIN {groups} g ON gm.groupid = g.id
WHERE g.courseid = ?", [$course1->id])
);
}
/**
* Test for provider::get_users_in_context().
*/
public function test_get_users_in_context(): void {
global $DB;
$this->resetAfterTest();
$metaplugin = enrol_get_plugin('meta');
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$user3 = $this->getDataGenerator()->create_user();
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course1->id));
$this->enable_plugin();
$metaplugin->add_instance($course1, array('customint1' => $course2->id, 'customint2' => $group1->id));
$this->getDataGenerator()->enrol_user($user1->id, $course2->id, 'student');
$this->getDataGenerator()->enrol_user($user2->id, $course2->id, 'student');
// Check if user1 is enrolled into course1 in group 1.
$this->assertTrue(groups_is_member($group1->id, $user1->id));
$this->assertTrue($DB->record_exists('groups_members',
array(
'groupid' => $group1->id,
'userid' => $user1->id,
'component' => 'enrol_meta'
)
));
$context = \context_course::instance($course1->id);
$userlist = new \core_privacy\local\request\userlist($context, 'enrol_meta');
\enrol_meta\privacy\provider::get_users_in_context($userlist);
$this->assertEqualsCanonicalizing(
[$user1->id, $user2->id],
$userlist->get_userids());
}
}