Merge branch 'wip-mdl-42536' of git://github.com/rajeshtaneja/moodle

This commit is contained in:
Dan Poltawski 2013-10-25 15:55:27 +08:00
commit 534c356a87
2 changed files with 27 additions and 1 deletions

View File

@ -180,7 +180,7 @@ class enrol_self_plugin extends enrol_plugin {
* @return bool|array true if enroled else eddor code and messege
*/
public function enrol_self(stdClass $instance, $data = null) {
global $DB, $USER;
global $DB, $USER, $CFG;
// Don't enrol user if password is not passed when required.
if ($instance->password && !isset($data->enrolpassword)) {
@ -205,6 +205,8 @@ class enrol_self_plugin extends enrol_plugin {
continue;
}
if ($group->enrolmentkey === $data->enrolpassword) {
// Add user to group.
require_once($CFG->dirroot.'/group/lib.php');
groups_add_member($group->id, $USER->id);
break;
}

View File

@ -51,3 +51,27 @@ Feature: Users can auto-enrol themself in courses where self enrolment is allowe
Given I log in as "student1"
When I follow "Course 1"
Then I should see "You can not enrol yourself in this course"
@javascript
Scenario: Self-enrolment enabled requiring a group enrolment key
Given I log in as "teacher1"
And I follow "Course 1"
When I add "Self enrolment" enrolment method with:
| Custom instance name | Test student enrolment |
| Enrolment key | moodle_rules |
| Use group enrolment keys | Yes |
And I follow "Groups"
And I press "Create group"
And I fill the moodle form with:
| Group name | Group 1 |
| Enrolment key | testgroupenrolkey |
And I press "Save changes"
And I log out
And I log in as "student1"
And I follow "Course 1"
And I fill the moodle form with:
| Enrolment key | testgroupenrolkey |
And I press "Enrol me"
Then I should see "Topic 1"
And I should not see "Enrolment options"
And I should not see "Enrol me in this course"