MDL-49380 enrol_cohort: Fixing matches
Tiny fix as the group name was not properly generated when incrementing the captured generated number. Also adding unit test for this case.
This commit is contained in:
@@ -350,7 +350,7 @@ function enrol_cohort_create_new_group($courseid, $cohortid) {
|
||||
if (!preg_match('/(.*?)\(([0-9]+)\)$/', $groupname, $matches)) {
|
||||
$a->increment = '(2)';
|
||||
} else {
|
||||
$a->increment = '(' . $matches[2]+1 . ')';
|
||||
$a->increment = '(' . ($matches[2] + 1) . ')';
|
||||
}
|
||||
$newshortname = get_string('defaultgroupnametext', 'enrol_cohort', $a);
|
||||
$groupname = $newshortname;
|
||||
@@ -362,4 +362,4 @@ function enrol_cohort_create_new_group($courseid, $cohortid) {
|
||||
$groupid = groups_create_group($groupdata);
|
||||
|
||||
return $groupid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* Cohort enrolment sync functional test.
|
||||
*
|
||||
* @package enrol_cohort
|
||||
* @category phpunit
|
||||
* @category test
|
||||
* @copyright 2015 Adrian Greeve <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -60,7 +60,7 @@ class enrol_cohort_lib_testcase extends advanced_testcase {
|
||||
// Group course id should match the course id.
|
||||
$this->assertEquals($course->id, $group->courseid);
|
||||
|
||||
// Create a group that will have the same name as the cohort
|
||||
// Create a group that will have the same name as the cohort.
|
||||
$groupdata = new stdClass();
|
||||
$groupdata->courseid = $course2->id;
|
||||
$groupdata->name = $cohort->name . ' cohort';
|
||||
@@ -70,5 +70,17 @@ class enrol_cohort_lib_testcase extends advanced_testcase {
|
||||
$groupinfo = $DB->get_record('groups', array('id' => $groupid));
|
||||
// Check that the group name has been changed.
|
||||
$this->assertEquals($cohort->name . ' cohort(2)', $groupinfo->name);
|
||||
|
||||
// Create another group that will have the same name as a generated cohort.
|
||||
$groupdata = new stdClass();
|
||||
$groupdata->courseid = $course2->id;
|
||||
$groupdata->name = $cohort->name . ' cohort(2)';
|
||||
groups_create_group($groupdata);
|
||||
// Create a group for the cohort in course 2.
|
||||
$groupid = enrol_cohort_create_new_group($course2->id, $cohort->id);
|
||||
$groupinfo = $DB->get_record('groups', array('id' => $groupid));
|
||||
// Check that the group name has been changed.
|
||||
$this->assertEquals($cohort->name . ' cohort(3)', $groupinfo->name);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user