| 1 | efrain | 1 | @enrol @enrol_manual
 | 
        
           |  |  | 2 | Feature: Teacher can search and enrol users one by one into the course
 | 
        
           |  |  | 3 |   In order to quickly enrol particular students into my course
 | 
        
           |  |  | 4 |   As a teacher
 | 
        
           |  |  | 5 |   I can search for the students and enrol them into the course
 | 
        
           |  |  | 6 |   | 
        
           |  |  | 7 |   Background:
 | 
        
           |  |  | 8 |     Given the following "custom profile fields" exist:
 | 
        
           |  |  | 9 |       | datatype | shortname  | name           |
 | 
        
           |  |  | 10 |       | text     | customid   | Custom user id |
 | 
        
           |  |  | 11 |     And the following "users" exist:
 | 
        
           |  |  | 12 |       | username    | firstname | lastname | email                   | profile_field_customid |
 | 
        
           |  |  | 13 |       | teacher001  | Teacher   | 001      | teacher001@example.com  |                        |
 | 
        
           |  |  | 14 |       | student001  | Student   | 001      | student001@example.com  | Q994                   |
 | 
        
           |  |  | 15 |       | student002  | Student   | 002      | student002@example.com  | Q008                   |
 | 
        
           |  |  | 16 |       | student003  | Student   | 003      | student003@example.com  | Z442                   |
 | 
        
           |  |  | 17 |       | student004  | Student   | 004      | student004@example.com  |                        |
 | 
        
           |  |  | 18 |       | student005  | Student   | 005      | student005@example.com  |                        |
 | 
        
           |  |  | 19 |       | student006  | Student   | 006      | student006@example.com  |                        |
 | 
        
           |  |  | 20 |       | student007  | Student   | 007      | student007@example.com  |                        |
 | 
        
           |  |  | 21 |       | student008  | Student   | 008      | student008@example.com  |                        |
 | 
        
           |  |  | 22 |       | student009  | Student   | 009      | student009@example.com  |                        |
 | 
        
           |  |  | 23 |       | student010  | Student   | 010      | student010@example.com  |                        |
 | 
        
           |  |  | 24 |       | student011  | Student   | 011      | student011@example.com  |                        |
 | 
        
           |  |  | 25 |       | student012  | Student   | 012      | student012@example.com  |                        |
 | 
        
           |  |  | 26 |       | student013  | Student   | 013      | student013@example.com  |                        |
 | 
        
           |  |  | 27 |       | student014  | Student   | 014      | student014@example.com  |                        |
 | 
        
           |  |  | 28 |       | student015  | Student   | 015      | student015@example.com  |                        |
 | 
        
           |  |  | 29 |       | student016  | Student   | 016      | student016@example.com  |                        |
 | 
        
           |  |  | 30 |       | student017  | Student   | 017      | student017@example.com  |                        |
 | 
        
           |  |  | 31 |       | student018  | Student   | 018      | student018@example.com  |                        |
 | 
        
           |  |  | 32 |       | student019  | Student   | 019      | student019@example.com  |                        |
 | 
        
           |  |  | 33 |       | student020  | Student   | 020      | student020@example.com  |                        |
 | 
        
           |  |  | 34 |       | student021  | Student   | 021      | student021@example.com  |                        |
 | 
        
           |  |  | 35 |       | student022  | Student   | 022      | student022@example.com  |                        |
 | 
        
           |  |  | 36 |       | student023  | Student   | 023      | student023@example.com  |                        |
 | 
        
           |  |  | 37 |       | student024  | Student   | 024      | student024@example.com  |                        |
 | 
        
           |  |  | 38 |       | student025  | Student   | 025      | student025@example.com  |                        |
 | 
        
           |  |  | 39 |       | student026  | Student   | 026      | student026@example.com  |                        |
 | 
        
           |  |  | 40 |       | student027  | Student   | 027      | student027@example.com  |                        |
 | 
        
           |  |  | 41 |       | student028  | Student   | 028      | student028@example.com  |                        |
 | 
        
           |  |  | 42 |       | student029  | Student   | 029      | student029@example.com  |                        |
 | 
        
           |  |  | 43 |       | student030  | Student   | 030      | student030@example.com  |                        |
 | 
        
           |  |  | 44 |       | student031  | Student   | 031      | student031@example.com  |                        |
 | 
        
           |  |  | 45 |       | student032  | Student   | 032      | student032@example.com  |                        |
 | 
        
           |  |  | 46 |       | student033  | Student   | 033      | student033@example.com  |                        |
 | 
        
           |  |  | 47 |       | student034  | Student   | 034      | student034@example.com  |                        |
 | 
        
           |  |  | 48 |       | student035  | Student   | 035      | student035@example.com  |                        |
 | 
        
           |  |  | 49 |       | student036  | Student   | 036      | student036@example.com  |                        |
 | 
        
           |  |  | 50 |       | student037  | Student   | 037      | student037@example.com  |                        |
 | 
        
           |  |  | 51 |       | student038  | Student   | 038      | student038@example.com  |                        |
 | 
        
           |  |  | 52 |       | student039  | Student   | 039      | student039@example.com  |                        |
 | 
        
           |  |  | 53 |       | student040  | Student   | 040      | student040@example.com  |                        |
 | 
        
           |  |  | 54 |       | student041  | Student   | 041      | student041@example.com  |                        |
 | 
        
           |  |  | 55 |       | student042  | Student   | 042      | student042@example.com  |                        |
 | 
        
           |  |  | 56 |       | student043  | Student   | 043      | student043@example.com  |                        |
 | 
        
           |  |  | 57 |       | student044  | Student   | 044      | student044@example.com  |                        |
 | 
        
           |  |  | 58 |       | student045  | Student   | 045      | student045@example.com  |                        |
 | 
        
           |  |  | 59 |       | student046  | Student   | 046      | student046@example.com  |                        |
 | 
        
           |  |  | 60 |       | student047  | Student   | 047      | student047@example.com  |                        |
 | 
        
           |  |  | 61 |       | student048  | Student   | 048      | student048@example.com  |                        |
 | 
        
           |  |  | 62 |       | student049  | Student   | 049      | student049@example.com  |                        |
 | 
        
           |  |  | 63 |       | student050  | Student   | 050      | student050@example.com  |                        |
 | 
        
           |  |  | 64 |       | student051  | Student   | 051      | student051@example.com  |                        |
 | 
        
           |  |  | 65 |       | student052  | Student   | 052      | student052@example.com  |                        |
 | 
        
           |  |  | 66 |       | student053  | Student   | 053      | student053@example.com  |                        |
 | 
        
           |  |  | 67 |       | student054  | Student   | 054      | student054@example.com  |                        |
 | 
        
           |  |  | 68 |       | student055  | Student   | 055      | student055@example.com  |                        |
 | 
        
           |  |  | 69 |       | student056  | Student   | 056      | student056@example.com  |                        |
 | 
        
           |  |  | 70 |       | student057  | Student   | 057      | student057@example.com  |                        |
 | 
        
           |  |  | 71 |       | student058  | Student   | 058      | student058@example.com  |                        |
 | 
        
           |  |  | 72 |       | student059  | Student   | 059      | student059@example.com  |                        |
 | 
        
           |  |  | 73 |       | student060  | Student   | 060      | student060@example.com  |                        |
 | 
        
           |  |  | 74 |       | student061  | Student   | 061      | student061@example.com  |                        |
 | 
        
           |  |  | 75 |       | student062  | Student   | 062      | student062@example.com  |                        |
 | 
        
           |  |  | 76 |       | student063  | Student   | 063      | student063@example.com  |                        |
 | 
        
           |  |  | 77 |       | student064  | Student   | 064      | student064@example.com  |                        |
 | 
        
           |  |  | 78 |       | student065  | Student   | 065      | student065@example.com  |                        |
 | 
        
           |  |  | 79 |       | student066  | Student   | 066      | student066@example.com  |                        |
 | 
        
           |  |  | 80 |       | student067  | Student   | 067      | student067@example.com  |                        |
 | 
        
           |  |  | 81 |       | student068  | Student   | 068      | student068@example.com  |                        |
 | 
        
           |  |  | 82 |       | student069  | Student   | 069      | student069@example.com  |                        |
 | 
        
           |  |  | 83 |       | student070  | Student   | 070      | student070@example.com  |                        |
 | 
        
           |  |  | 84 |       | student071  | Student   | 071      | student071@example.com  |                        |
 | 
        
           |  |  | 85 |       | student072  | Student   | 072      | student072@example.com  |                        |
 | 
        
           |  |  | 86 |       | student073  | Student   | 073      | student073@example.com  |                        |
 | 
        
           |  |  | 87 |       | student074  | Student   | 074      | student074@example.com  |                        |
 | 
        
           |  |  | 88 |       | student075  | Student   | 075      | student075@example.com  |                        |
 | 
        
           |  |  | 89 |       | student076  | Student   | 076      | student076@example.com  |                        |
 | 
        
           |  |  | 90 |       | student077  | Student   | 077      | student077@example.com  |                        |
 | 
        
           |  |  | 91 |       | student078  | Student   | 078      | student078@example.com  |                        |
 | 
        
           |  |  | 92 |       | student079  | Student   | 079      | student079@example.com  |                        |
 | 
        
           |  |  | 93 |       | student080  | Student   | 080      | student080@example.com  |                        |
 | 
        
           |  |  | 94 |       | student081  | Student   | 081      | student081@example.com  |                        |
 | 
        
           |  |  | 95 |       | student082  | Student   | 082      | student082@example.com  |                        |
 | 
        
           |  |  | 96 |       | student083  | Student   | 083      | student083@example.com  |                        |
 | 
        
           |  |  | 97 |       | student084  | Student   | 084      | student084@example.com  |                        |
 | 
        
           |  |  | 98 |       | student085  | Student   | 085      | student085@example.com  |                        |
 | 
        
           |  |  | 99 |       | student086  | Student   | 086      | student086@example.com  |                        |
 | 
        
           |  |  | 100 |       | student087  | Student   | 087      | student087@example.com  |                        |
 | 
        
           |  |  | 101 |       | student088  | Student   | 088      | student088@example.com  |                        |
 | 
        
           |  |  | 102 |       | student089  | Student   | 089      | student089@example.com  |                        |
 | 
        
           |  |  | 103 |       | student090  | Student   | 090      | student090@example.com  |                        |
 | 
        
           |  |  | 104 |       | student091  | Student   | 091      | student091@example.com  |                        |
 | 
        
           |  |  | 105 |       | student092  | Student   | 092      | student092@example.com  |                        |
 | 
        
           |  |  | 106 |       | student093  | Student   | 093      | student093@example.com  |                        |
 | 
        
           |  |  | 107 |       | student094  | Student   | 094      | student094@example.com  |                        |
 | 
        
           |  |  | 108 |       | student095  | Student   | 095      | student095@example.com  |                        |
 | 
        
           |  |  | 109 |       | student096  | Student   | 096      | student096@example.com  |                        |
 | 
        
           |  |  | 110 |       | student097  | Student   | 097      | student097@example.com  |                        |
 | 
        
           |  |  | 111 |       | student098  | Student   | 098      | student098@example.com  |                        |
 | 
        
           |  |  | 112 |       | student099  | Student   | 099      | student099@example.com  |                        |
 | 
        
           |  |  | 113 |     And the following "courses" exist:
 | 
        
           |  |  | 114 |       | fullname   | shortname | format | startdate       |
 | 
        
           |  |  | 115 |       | Course 001 | C001      | weeks  | ##1 month ago## |
 | 
        
           |  |  | 116 |     And the following "course enrolments" exist:
 | 
        
           |  |  | 117 |       | user       | course | role           | timestart       |
 | 
        
           |  |  | 118 |       | teacher001 | C001   | editingteacher | ##1 month ago## |
 | 
        
           |  |  | 119 |     And I log in as "teacher001"
 | 
        
           |  |  | 120 |     And I am on "Course 001" course homepage
 | 
        
           |  |  | 121 |   | 
        
           |  |  | 122 |   @javascript
 | 
        
           |  |  | 123 |   Scenario: Teacher can search and enrol one particular student
 | 
        
           |  |  | 124 |     Given I navigate to course participants
 | 
        
           |  |  | 125 |     And I press "Enrol users"
 | 
        
           |  |  | 126 |     When I set the field "Select users" to "student001"
 | 
        
           |  |  | 127 |     And I should see "Student 001"
 | 
        
           |  |  | 128 |     And I click on "Enrol users" "button" in the "Enrol users" "dialogue"
 | 
        
           |  |  | 129 |     Then I should see "Active" in the "Student 001" "table_row"
 | 
        
           |  |  | 130 |     And I should see "1 enrolled users"
 | 
        
           |  |  | 131 |   | 
        
           |  |  | 132 |   @javascript
 | 
        
           |  |  | 133 |   Scenario: Searching for a non-existing user
 | 
        
           |  |  | 134 |     Given I navigate to course participants
 | 
        
           |  |  | 135 |     And I press "Enrol users"
 | 
        
           |  |  | 136 |     And I click on "Select users" "field"
 | 
        
           |  |  | 137 |     And I type "qwertyuiop"
 | 
        
           |  |  | 138 |     Then I should see "No suggestions"
 | 
        
           |  |  | 139 |   | 
        
           |  |  | 140 |   @javascript
 | 
        
           |  |  | 141 |   Scenario: If there are less than 100 matching users, all are displayed for selection
 | 
        
           |  |  | 142 |     Given I navigate to course participants
 | 
        
           |  |  | 143 |     And I press "Enrol users"
 | 
        
           |  |  | 144 |     When I click on "Select users" "field"
 | 
        
           |  |  | 145 |     And I type "example.com"
 | 
        
           |  |  | 146 |     Then "Student 099" "autocomplete_suggestions" should exist
 | 
        
           |  |  | 147 |   | 
        
           |  |  | 148 |   @javascript
 | 
        
           |  |  | 149 |   Scenario: If there are more than 100 matching users, inform there are too many.
 | 
        
           |  |  | 150 |     Given the following "users" exist:
 | 
        
           |  |  | 151 |       | username    | firstname | lastname | email                   |
 | 
        
           |  |  | 152 |       | student100  | Student   | 100      | student100@example.com  |
 | 
        
           |  |  | 153 |       | student101  | Student   | 101      | student101@example.com  |
 | 
        
           |  |  | 154 |     And I navigate to course participants
 | 
        
           |  |  | 155 |     And I press "Enrol users"
 | 
        
           |  |  | 156 |     When I click on "Select users" "field"
 | 
        
           |  |  | 157 |     And I type "example.com"
 | 
        
           |  |  | 158 |     Then I should see "Too many users (>100) to show"
 | 
        
           |  |  | 159 |   | 
        
           |  |  | 160 |   @javascript
 | 
        
           |  |  | 161 |   Scenario: Changing the Maximum users per page setting affects the enrolment pop-up.
 | 
        
           |  |  | 162 |     Given the following config values are set as admin:
 | 
        
           |  |  | 163 |       | maxusersperpage | 5 |
 | 
        
           |  |  | 164 |     And I navigate to course participants
 | 
        
           |  |  | 165 |     And I press "Enrol users"
 | 
        
           |  |  | 166 |     When I click on "Select users" "field"
 | 
        
           |  |  | 167 |     And I type "student00"
 | 
        
           |  |  | 168 |     Then I should see "Too many users (>5) to show"
 | 
        
           |  |  | 169 |   | 
        
           |  |  | 170 |   @javascript
 | 
        
           |  |  | 171 |   Scenario: Change the Show user identity setting affects the enrolment pop-up.
 | 
        
           |  |  | 172 |     Given I log out
 | 
        
           |  |  | 173 |     When I log in as "admin"
 | 
        
           |  |  | 174 |     Then the following "users" exist:
 | 
        
           |  |  | 175 |       | username    | firstname | lastname | email                   | phone1     | phone2     | department | institution | city    | country  |
 | 
        
           |  |  | 176 |       | student100  | Student   | 100      | student100@example.com  | 1234567892 | 1234567893 | ABC1       | ABC2        | CITY1   | GB       |
 | 
        
           |  |  | 177 |     And the following config values are set as admin:
 | 
        
           |  |  | 178 |       | showuseridentity | idnumber,email,city,country,phone1,phone2,department,institution |
 | 
        
           |  |  | 179 |     When I am on "Course 001" course homepage
 | 
        
           |  |  | 180 |     Then I navigate to course participants
 | 
        
           |  |  | 181 |     And I press "Enrol users"
 | 
        
           |  |  | 182 |     And I click on "Select users" "field"
 | 
        
           |  |  | 183 |     And I type "student100@example.com"
 | 
        
           |  |  | 184 |     Then I should see "student100@example.com, CITY1, GB, 1234567892, 1234567893, ABC1, ABC2"
 | 
        
           |  |  | 185 |     # Remove identity field in setting User policies
 | 
        
           |  |  | 186 |     And the following config values are set as admin:
 | 
        
           |  |  | 187 |       | showuseridentity | idnumber,email,phone1,phone2,department,institution |
 | 
        
           |  |  | 188 |     And I am on "Course 001" course homepage
 | 
        
           |  |  | 189 |     And I navigate to course participants
 | 
        
           |  |  | 190 |     And I press "Enrol users"
 | 
        
           |  |  | 191 |     And I click on "Select users" "field"
 | 
        
           |  |  | 192 |     And I type "student100@example.com"
 | 
        
           |  |  | 193 |     And I should see "student100@example.com, 1234567892, 1234567893, ABC1, ABC2"
 | 
        
           |  |  | 194 |   | 
        
           |  |  | 195 |   @javascript
 | 
        
           |  |  | 196 |   Scenario: Custom user profile fields work for search and display, if user has permission
 | 
        
           |  |  | 197 |     Given the following config values are set as admin:
 | 
        
           |  |  | 198 |       | showuseridentity | email,profile_field_customid |
 | 
        
           |  |  | 199 |     And I navigate to course participants
 | 
        
           |  |  | 200 |     And I press "Enrol users"
 | 
        
           |  |  | 201 |     When I set the field "Select users" to "Q994"
 | 
        
           |  |  | 202 |     Then I should see "student001@example.com, Q994"
 | 
        
           |  |  | 203 |     And I click on "Cancel" "button" in the "Enrol users" "dialogue"
 | 
        
           |  |  | 204 |     And the following "permission overrides" exist:
 | 
        
           |  |  | 205 |       | capability                   | permission | role           | contextlevel | reference |
 | 
        
           |  |  | 206 |       | moodle/site:viewuseridentity | Prevent    | editingteacher | Course       | C001      |
 | 
        
           |  |  | 207 |     And I press "Enrol users"
 | 
        
           |  |  | 208 |     # Do this by keyboard because the 'I set the field' step doesn't let you set it to a missing value.
 | 
        
           |  |  | 209 |     And I press tab
 | 
        
           |  |  | 210 |     And I press tab
 | 
        
           |  |  | 211 |     And I press tab
 | 
        
           |  |  | 212 |     And I type "Q994"
 | 
        
           |  |  | 213 |     And I should see "No suggestions"
 | 
        
           |  |  | 214 |   | 
        
           |  |  | 215 | # The following tests are commented out as a result of MDL-66339.
 | 
        
           |  |  | 216 | #  @javascript
 | 
        
           |  |  | 217 | #  Scenario: Enrol user from participants page
 | 
        
           |  |  | 218 | #    Given I navigate to course participants
 | 
        
           |  |  | 219 | #    # Enrol user to course
 | 
        
           |  |  | 220 | #    And I press "Enrol users"
 | 
        
           |  |  | 221 | #    And I set the field "Select users" to "example.com"
 | 
        
           |  |  | 222 | #    And I expand the "Select users" autocomplete
 | 
        
           |  |  | 223 | #    When I click on "Student 099" item in the autocomplete list
 | 
        
           |  |  | 224 | #    Then I should see "Student 099" in the list of options for the "Select users" autocomplete
 | 
        
           |  |  | 225 | #    And I click on "Show more" "button"
 | 
        
           |  |  | 226 | #    # Fill data to input duration
 | 
        
           |  |  | 227 | #    And "input[name='timeend[enabled]'][checked=checked]" "css_element" should not exist
 | 
        
           |  |  | 228 | #    And the "Enrolment duration" "select" should be enabled
 | 
        
           |  |  | 229 | #    And I set the field "duration" to "2"
 | 
        
           |  |  | 230 | #    # Fill data to input end time
 | 
        
           |  |  | 231 | #    And I set the field "Starting from" to "2"
 | 
        
           |  |  | 232 | #    And I set the field "timeend[enabled]" to "1"
 | 
        
           |  |  | 233 | #    And I set the field "timeend[day]" to "10"
 | 
        
           |  |  | 234 | #    And the "Enrolment duration" "select" should be disabled
 | 
        
           |  |  | 235 | #    And I click on "Enrol users" "button" in the "Enrol users" "dialogue"
 | 
        
           |  |  | 236 | #    And I am on "Course 001" course homepage
 | 
        
           |  |  | 237 | #    And I navigate to course participants
 | 
        
           |  |  | 238 | #    And I should see "Student 099" in the "participants" "table"
 | 
        
           |  |  | 239 | #    And I click on "Edit enrolment" "icon" in the "Student 099" "table_row"
 | 
        
           |  |  | 240 | #    And the field "timeend[day]" matches value "10"
 | 
        
           |  |  | 241 | #
 | 
        
           |  |  | 242 | #  @javascript
 | 
        
           |  |  | 243 | #  Scenario: Update Enrol user
 | 
        
           |  |  | 244 | #    Given I am on "Course 001" course homepage
 | 
        
           |  |  | 245 | #    And I navigate to course participants
 | 
        
           |  |  | 246 | #    When I click on "Edit enrolment" "icon" in the "Teacher 001" "table_row"
 | 
        
           |  |  | 247 | #    Then the "Enrolment duration" "select" should be enabled
 | 
        
           |  |  | 248 | #    # Fill duration
 | 
        
           |  |  | 249 | #    And "input[name='timeend[enabled]'][checked=checked]" "css_element" should not exist
 | 
        
           |  |  | 250 | #    And the "Enrolment duration" "select" should be enabled
 | 
        
           |  |  | 251 | #    And I set the field "duration" to "2"
 | 
        
           |  |  | 252 | #    # Fill end time
 | 
        
           |  |  | 253 | #    And I set the field "timeend[enabled]" to "1"
 | 
        
           |  |  | 254 | #    And I set the field "timeend[day]" to "28"
 | 
        
           |  |  | 255 | #    And the "Enrolment duration" "select" should be disabled
 | 
        
           |  |  | 256 | #    And I press "Save changes"
 | 
        
           |  |  | 257 | #    And I click on "Edit enrolment" "icon" in the "Teacher 001" "table_row"
 | 
        
           |  |  | 258 | #    And the field "timeend[day]" matches value "28"
 |