mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-46524: Auto-create groups from existing group or grouping membership
This commit is contained in:
parent
40f0ad21a3
commit
e4ebf7ef0f
6 changed files with 165 additions and 11 deletions
|
@ -108,4 +108,34 @@ Feature: Automatic creation of groups
|
|||
And I set the field "Ignore users in groups" to "1"
|
||||
And I press "Submit"
|
||||
And the "groups" select box should contain "Group A (3)"
|
||||
And the "groups" select box should contain "Group B (3)"
|
||||
And the "groups" select box should contain "Group B (3)"
|
||||
|
||||
@javascript
|
||||
Scenario: Split users into groups based on existing groups or groupings
|
||||
Given I set the following fields to these values:
|
||||
| Naming scheme | Group @ |
|
||||
| Auto create based on | Number of groups |
|
||||
| Group/member count | 2 |
|
||||
| Grouping of auto-created groups | No grouping |
|
||||
And I press "Submit"
|
||||
And I press "Auto-create groups"
|
||||
And I set the following fields to these values:
|
||||
| Naming scheme | Test @ |
|
||||
| Auto create based on | Number of groups |
|
||||
| Group/member count | 2 |
|
||||
| groupid | Group A |
|
||||
| Grouping of auto-created groups | New grouping |
|
||||
| Grouping name | Sub Grouping |
|
||||
And I press "Submit"
|
||||
And the "groups" select box should contain "Test A (3)"
|
||||
And the "groups" select box should contain "Test B (2)"
|
||||
And I press "Auto-create groups"
|
||||
And I set the following fields to these values:
|
||||
| Naming scheme | Test # |
|
||||
| Auto create based on | Number of groups |
|
||||
| Group/member count | 2 |
|
||||
| Select members from grouping | Sub Grouping |
|
||||
| Grouping of auto-created groups | No grouping |
|
||||
And I press "Submit"
|
||||
And the "groups" select box should contain "Test 1 (3)"
|
||||
And the "groups" select box should contain "Test 2 (2)"
|
|
@ -406,4 +406,57 @@ class core_group_lib_testcase extends advanced_testcase {
|
|||
$this->assertTrue($DB->record_exists('groupings', array('id' => $grouping1c2->id, 'courseid' => $course2->id)));
|
||||
$this->assertFalse($DB->record_exists('groupings_groups', array('groupid' => $group1->id, 'groupingid' => $grouping1->id)));
|
||||
}
|
||||
|
||||
public function test_groups_create_autogroups () {
|
||||
global $DB;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
|
||||
$group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
|
||||
$group3 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
|
||||
$grouping1 = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id));
|
||||
$this->getDataGenerator()->create_grouping_group(array('groupid' => $group2->id, 'groupingid' => $grouping1->id));
|
||||
$this->getDataGenerator()->create_grouping_group(array('groupid' => $group3->id, 'groupingid' => $grouping1->id));
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$user3 = $this->getDataGenerator()->create_user();
|
||||
$user4 = $this->getDataGenerator()->create_user();
|
||||
$this->getDataGenerator()->enrol_user($user1->id, $course->id);
|
||||
$this->getDataGenerator()->enrol_user($user2->id, $course->id);
|
||||
$this->getDataGenerator()->enrol_user($user3->id, $course->id);
|
||||
$this->getDataGenerator()->enrol_user($user4->id, $course->id);
|
||||
$this->getDataGenerator()->create_group_member(array('groupid' => $group1->id, 'userid' => $user1->id));
|
||||
$this->getDataGenerator()->create_group_member(array('groupid' => $group1->id, 'userid' => $user2->id));
|
||||
$this->getDataGenerator()->create_group_member(array('groupid' => $group2->id, 'userid' => $user3->id));
|
||||
$this->getDataGenerator()->create_group_member(array('groupid' => $group3->id, 'userid' => $user4->id));
|
||||
|
||||
// Test autocreate group based on all course users.
|
||||
$users = groups_get_potential_members($course->id);
|
||||
$group4 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
|
||||
foreach ($users as $user) {
|
||||
$this->getDataGenerator()->create_group_member(array('groupid' => $group4->id, 'userid' => $user->id));
|
||||
}
|
||||
$this->assertEquals(4, $DB->count_records('groups_members', array('groupid' => $group4->id)));
|
||||
|
||||
// Test autocreate group based on existing group.
|
||||
$source = array();
|
||||
$source['groupid'] = $group1->id;
|
||||
$users = groups_get_potential_members($course->id, 0, $source);
|
||||
$group5 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
|
||||
foreach ($users as $user) {
|
||||
$this->getDataGenerator()->create_group_member(array('groupid' => $group5->id, 'userid' => $user->id));
|
||||
}
|
||||
$this->assertEquals(2, $DB->count_records('groups_members', array('groupid' => $group5->id)));
|
||||
|
||||
// Test autocreate group based on existing grouping.
|
||||
$source = array();
|
||||
$source['groupingid'] = $grouping1->id;
|
||||
$users = groups_get_potential_members($course->id, 0, $source);
|
||||
$group6 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
|
||||
foreach ($users as $user) {
|
||||
$this->getDataGenerator()->create_group_member(array('groupid' => $group6->id, 'userid' => $user->id));
|
||||
}
|
||||
$this->assertEquals(2, $DB->count_records('groups_members', array('groupid' => $group6->id)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue