Skip to content

Commit

Permalink
MDL-42536 enrol_self: Added groups/lib.php required file
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajesh Taneja committed Oct 25, 2013
1 parent 4e47920 commit 735c3a7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion enrol/self/lib.php
Expand Up @@ -180,7 +180,7 @@ public function get_newinstance_link($courseid) {
* @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)) {
Expand All @@ -205,6 +205,8 @@ public function enrol_self(stdClass $instance, $data = null) {
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;
}
Expand Down
24 changes: 24 additions & 0 deletions enrol/self/tests/behat/self_enrolment.feature
Expand Up @@ -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"

0 comments on commit 735c3a7

Please sign in to comment.