MDL-53893 core_badges: Add strictness to manual badge criteria
[moodle.git] / badges / tests / behat / award_badge.feature
CommitLineData
561e9bb9 1@core @core_badges @_file_upload
27806552
YB
2Feature: Award badges
3 In order to award badges to users for their achievements
4 As an admin
5 I need to add criteria to badges in the system
6
27806552 7 @javascript
844d74d7 8 Scenario: Award profile badge
d1e55a47 9 Given I log in as "admin"
1f631c7c 10 And I navigate to "Add a new badge" node in "Site administration > Badges"
f083d614 11 And I set the following fields to these values:
844d74d7 12 | Name | Profile Badge |
27806552
YB
13 | Description | Test badge description |
14 | issuername | Test Badge Site |
0fe86bbd 15 | issuercontact | testuser@example.com |
07622451 16 And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
27806552 17 And I press "Create badge"
f083d614 18 And I set the field "type" to "Profile completion"
0b6ba27a 19 And I expand all fieldsets
f083d614
DM
20 And I set the field "First name" to "1"
21 And I set the field "Email address" to "1"
22 And I set the field "Phone" to "1"
0b6ba27a 23 And I set the field "id_description" to "Criterion description"
27806552
YB
24 When I press "Save"
25 Then I should see "Profile completion"
26 And I should see "First name"
27 And I should see "Email address"
0b6ba27a
Y
28 And I should see "Phone"
29 And I should see "Criterion description"
27806552 30 And I should not see "Criteria for this badge have not been set up yet."
844d74d7
JM
31 And I press "Enable access"
32 And I press "Continue"
ae0bf677 33 And I click on "Admin User" "link"
4887d152 34 And I follow "Profile" in the open menu
844d74d7
JM
35 And I follow "Edit profile"
36 And I expand all fieldsets
f083d614 37 And I set the field "Phone" to "123456789"
844d74d7 38 And I press "Update profile"
4887d152 39 And I follow "Profile" in the user menu
844d74d7
JM
40 Then I should see "Profile Badge"
41 And I should not see "There are no badges available."
27806552
YB
42
43 @javascript
844d74d7 44 Scenario: Award site badge
759b323e 45 Given the following "users" exist:
844d74d7 46 | username | firstname | lastname | email |
0fe86bbd
RT
47 | teacher | teacher | 1 | teacher1@example.com |
48 | student | student | 1 | student1@example.com |
d1e55a47 49 And I log in as "admin"
1f631c7c 50 And I navigate to "Add a new badge" node in "Site administration > Badges"
f083d614 51 And I set the following fields to these values:
844d74d7
JM
52 | Name | Site Badge |
53 | Description | Site badge description |
54 | issuername | Tester of site badge |
07622451 55 And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
27806552 56 And I press "Create badge"
f083d614
DM
57 And I set the field "type" to "Manual issue by role"
58 And I set the field "Teacher" to "1"
27806552
YB
59 And I press "Save"
60 And I press "Enable access"
61 And I press "Continue"
844d74d7
JM
62 And I follow "Recipients (0)"
63 And I press "Award badge"
0fe86bbd 64 And I set the field "potentialrecipients[]" to "teacher 1 (teacher1@example.com)"
844d74d7 65 And I press "Award badge"
0fe86bbd 66 And I set the field "potentialrecipients[]" to "student 1 (student1@example.com)"
844d74d7
JM
67 And I press "Award badge"
68 When I follow "Site Badge"
69 Then I should see "Recipients (2)"
70 And I log out
71 And I log in as "student"
4887d152 72 And I follow "Profile" in the user menu
844d74d7 73 Then I should see "Site Badge"
68c13c68
JM
74
75 @javascript
76 Scenario: Award course badge
759b323e 77 Given the following "users" exist:
68c13c68 78 | username | firstname | lastname | email |
0fe86bbd
RT
79 | teacher1 | Teacher | 1 | teacher1@example.com |
80 | student1 | Student | 1 | student1@example.com |
81 | student2 | Student | 2 | student2@example.com |
759b323e 82 And the following "courses" exist:
68c13c68
JM
83 | fullname | shortname | category | groupmode |
84 | Course 1 | C1 | 0 | 1 |
759b323e 85 And the following "course enrolments" exist:
68c13c68
JM
86 | user | course | role |
87 | teacher1 | C1 | editingteacher |
88 | student1 | C1 | student |
89 | student2 | C1 | student |
68c13c68
JM
90 And I log in as "teacher1"
91 And I follow "Course 1"
004d7e35 92 And I navigate to "Add a new badge" node in "Course administration > Badges"
68c13c68 93 And I follow "Add a new badge"
f083d614 94 And I set the following fields to these values:
68c13c68
JM
95 | Name | Course Badge |
96 | Description | Course badge description |
97 | issuername | Tester of course badge |
07622451 98 And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
68c13c68 99 And I press "Create badge"
f083d614
DM
100 And I set the field "type" to "Manual issue by role"
101 And I set the field "Teacher" to "1"
68c13c68
JM
102 And I press "Save"
103 And I press "Enable access"
104 And I press "Continue"
105 And I follow "Recipients (0)"
106 And I press "Award badge"
0fe86bbd 107 And I set the field "potentialrecipients[]" to "Student 2 (student2@example.com)"
68c13c68 108 And I press "Award badge"
0fe86bbd 109 And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
68c13c68
JM
110 When I press "Award badge"
111 And I follow "Course Badge"
112 Then I should see "Recipients (2)"
113 And I log out
114 And I log in as "student1"
4887d152 115 And I follow "Profile" in the user menu
68c13c68 116 And I follow "Course 1"
ae0bf677 117 And I should see "Course Badge"
066ef320
JM
118
119 @javascript
120 Scenario: Award badge on activity completion
759b323e 121 Given the following "courses" exist:
066ef320
JM
122 | fullname | shortname | category |
123 | Course 1 | C1 | 0 |
759b323e 124 And the following "users" exist:
066ef320 125 | username | firstname | lastname | email |
0fe86bbd
RT
126 | teacher1 | Teacher | Frist | teacher1@example.com |
127 | student1 | Student | First | student1@example.com |
759b323e 128 And the following "course enrolments" exist:
066ef320
JM
129 | user | course | role |
130 | teacher1 | C1 | editingteacher |
131 | student1 | C1 | student |
bed97c39 132 And I log in as "teacher1"
066ef320
JM
133 And I follow "Course 1"
134 And I follow "Edit settings"
f083d614 135 And I set the following fields to these values:
066ef320 136 | Enable completion tracking | Yes |
38ea5e0a 137 And I press "Save and display"
066ef320
JM
138 And I turn editing mode on
139 And I add a "Assignment" to section "1" and I fill the form with:
140 | Assignment name | Test assignment name |
141 | Description | Submit your online text |
066ef320 142 And I follow "Course 1"
004d7e35 143 And I navigate to "Add a new badge" node in "Course administration > Badges"
066ef320 144 And I follow "Add a new badge"
f083d614 145 And I set the following fields to these values:
066ef320
JM
146 | Name | Course Badge |
147 | Description | Course badge description |
148 | issuername | Tester of course badge |
07622451 149 And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
066ef320 150 And I press "Create badge"
f083d614
DM
151 And I set the field "type" to "Activity completion"
152 And I set the field "Test assignment name" to "1"
066ef320
JM
153 And I press "Save"
154 And I press "Enable access"
155 When I press "Continue"
156 And I log out
157 And I log in as "student1"
4887d152 158 And I follow "Profile" in the user menu
066ef320 159 And I follow "Course 1"
ae0bf677
AA
160 Then I should not see "badges"
161 And I am on homepage
066ef320
JM
162 And I follow "Course 1"
163 And I press "Mark as complete: Test assignment name"
4887d152 164 And I follow "Profile" in the user menu
ae0bf677 165 And I follow "Course 1"
066ef320
JM
166 Then I should see "Course Badge"
167
168 @javascript
169 Scenario: Award badge on course completion
759b323e 170 Given the following "courses" exist:
066ef320
JM
171 | fullname | shortname | category |
172 | Course 1 | C1 | 0 |
759b323e 173 And the following "users" exist:
066ef320 174 | username | firstname | lastname | email |
0fe86bbd
RT
175 | teacher1 | Teacher | Frist | teacher1@example.com |
176 | student1 | Student | First | student1@example.com |
759b323e 177 And the following "course enrolments" exist:
066ef320
JM
178 | user | course | role |
179 | teacher1 | C1 | editingteacher |
180 | student1 | C1 | student |
bed97c39 181 And I log in as "teacher1"
066ef320
JM
182 And I follow "Course 1"
183 And I follow "Edit settings"
f083d614 184 And I set the following fields to these values:
066ef320 185 | Enable completion tracking | Yes |
38ea5e0a 186 And I press "Save and display"
066ef320
JM
187 And I turn editing mode on
188 And I add a "Assignment" to section "1" and I fill the form with:
189 | Assignment name | Test assignment name |
190 | Description | Submit your online text |
191 | assignsubmission_onlinetext_enabled | 1 |
192 And I follow "Course completion"
f083d614 193 And I set the field "id_overall_aggregation" to "2"
066ef320 194 And I click on "Condition: Activity completion" "link"
99018b28 195 And I set the field "Assignment - Test assignment name" to "1"
066ef320 196 And I press "Save changes"
066ef320 197 And I follow "Course 1"
004d7e35 198 And I navigate to "Add a new badge" node in "Course administration > Badges"
066ef320 199 And I follow "Add a new badge"
f083d614 200 And I set the following fields to these values:
066ef320
JM
201 | Name | Course Badge |
202 | Description | Course badge description |
203 | issuername | Tester of course badge |
07622451 204 And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
066ef320 205 And I press "Create badge"
f083d614 206 And I set the field "type" to "Course completion"
6c396b6b 207 And I set the field with xpath "//fieldset/input[1]" to "0"
066ef320
JM
208 And I press "Save"
209 And I press "Enable access"
210 When I press "Continue"
211 And I log out
212 And I log in as "student1"
4887d152 213 And I follow "Profile" in the user menu
066ef320 214 And I follow "Course 1"
ae0bf677
AA
215 Then I should not see "badges"
216 And I am on homepage
066ef320
JM
217 And I follow "Course 1"
218 And I press "Mark as complete: Test assignment name"
219 And I log out
a4ce565f 220 # Completion cron won't mark the whole course completed unless the
221 # individual criteria was marked completed more than a second ago. So
222 # run it twice, first to mark the criteria and second for the course.
223 And I run the scheduled task "core\task\completion_regular_task"
224 And I wait "1" seconds
225 And I run the scheduled task "core\task\completion_regular_task"
226 # The student should now see their badge.
066ef320 227 And I log in as "student1"
4887d152 228 And I follow "Profile" in the user menu
a57263d1 229 Then I should see "Course Badge"