award_badge.feature 15 KB
Newer Older
1
@core @core_badges @_file_upload
2
3
4
5
6
7
Feature: Award badges
  In order to award badges to users for their achievements
  As an admin
  I need to add criteria to badges in the system

  @javascript
8
  Scenario: Award profile badge
9
    Given I log in as "admin"
10
    And I navigate to "Add a new badge" node in "Site administration > Badges"
11
    And I set the following fields to these values:
12
      | Name | Profile Badge |
13
14
      | Description | Test badge description |
      | issuername | Test Badge Site |
15
      | issuercontact | testuser@example.com |
16
    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
17
    And I press "Create badge"
18
    And I set the field "type" to "Profile completion"
19
    And I expand all fieldsets
20
21
22
    And I set the field "First name" to "1"
    And I set the field "Email address" to "1"
    And I set the field "Phone" to "1"
23
    And I set the field "id_description" to "Criterion description"
24
25
26
27
    When I press "Save"
    Then I should see "Profile completion"
    And I should see "First name"
    And I should see "Email address"
28
29
    And I should see "Phone"
    And I should see "Criterion description"
30
    And I should not see "Criteria for this badge have not been set up yet."
31
32
    And I press "Enable access"
    And I press "Continue"
33
    And I open my profile in edit mode
34
    And I expand all fieldsets
35
    And I set the field "Phone" to "123456789"
36
    And I press "Update profile"
37
    And I follow "Profile" in the user menu
38
39
    Then I should see "Profile Badge"
    And I should not see "There are no badges available."
40
41

  @javascript
42
  Scenario: Award site badge
43
    Given the following "users" exist:
44
      | username | firstname | lastname | email |
45
46
      | teacher | teacher | 1 | teacher1@example.com |
      | student | student | 1 | student1@example.com |
47
    And I log in as "admin"
48
    And I navigate to "Add a new badge" node in "Site administration > Badges"
49
    And I set the following fields to these values:
50
51
52
      | Name | Site Badge |
      | Description | Site badge description |
      | issuername | Tester of site badge |
53
    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
54
    And I press "Create badge"
55
56
    And I set the field "type" to "Manual issue by role"
    And I set the field "Teacher" to "1"
57
58
59
    And I press "Save"
    And I press "Enable access"
    And I press "Continue"
60
61
    And I follow "Recipients (0)"
    And I press "Award badge"
62
    And I set the field "potentialrecipients[]" to "teacher 1 (teacher1@example.com)"
63
    And I press "Award badge"
64
    And I set the field "potentialrecipients[]" to "student 1 (student1@example.com)"
65
66
67
68
69
    And I press "Award badge"
    When I follow "Site Badge"
    Then I should see "Recipients (2)"
    And I log out
    And I log in as "student"
70
    And I follow "Profile" in the user menu
71
    Then I should see "Site Badge"
72
73
74

  @javascript
  Scenario: Award course badge
75
    Given the following "users" exist:
76
      | username | firstname | lastname | email |
77
78
79
      | teacher1 | Teacher | 1 | teacher1@example.com |
      | student1 | Student | 1 | student1@example.com |
      | student2 | Student | 2 | student2@example.com |
80
    And the following "courses" exist:
81
82
      | fullname | shortname | category | groupmode |
      | Course 1 | C1 | 0 | 1 |
83
    And the following "course enrolments" exist:
84
85
86
87
88
      | user | course | role |
      | teacher1 | C1 | editingteacher |
      | student1 | C1 | student |
      | student2 | C1 | student |
    And I log in as "teacher1"
89
    And I am on "Course 1" course homepage
90
    And I navigate to "Add a new badge" node in "Course administration > Badges"
91
    And I follow "Add a new badge"
92
    And I set the following fields to these values:
93
94
95
      | Name | Course Badge |
      | Description | Course badge description |
      | issuername | Tester of course badge |
96
    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
97
    And I press "Create badge"
98
99
    And I set the field "type" to "Manual issue by role"
    And I set the field "Teacher" to "1"
100
101
102
103
104
    And I press "Save"
    And I press "Enable access"
    And I press "Continue"
    And I follow "Recipients (0)"
    And I press "Award badge"
105
    And I set the field "potentialrecipients[]" to "Student 2 (student2@example.com)"
106
    And I press "Award badge"
107
    And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
108
    When I press "Award badge"
109
    And I follow "Course Badge"
110
111
112
    Then I should see "Recipients (2)"
    And I log out
    And I log in as "student1"
113
    And I follow "Profile" in the user menu
114
    And I click on "Course 1" "link" in the "region-main" "region"
115
    And I should see "Course Badge"
116
117
118

  @javascript
  Scenario: Award badge on activity completion
119
    Given the following "courses" exist:
120
121
      | fullname | shortname | category |
      | Course 1 | C1 | 0 |
122
    And the following "users" exist:
123
      | username | firstname | lastname | email |
124
125
      | teacher1 | Teacher | Frist | teacher1@example.com |
      | student1 | Student | First | student1@example.com |
126
    And the following "course enrolments" exist:
127
128
129
      | user | course | role |
      | teacher1 | C1 | editingteacher |
      | student1 | C1 | student |
130
    And I log in as "teacher1"
131
    And I am on "Course 1" course homepage
132
    And I navigate to "Edit settings" node in "Course administration"
133
    And I set the following fields to these values:
134
      | Enable completion tracking | Yes |
135
    And I press "Save and display"
136
137
138
139
    And I turn editing mode on
    And I add a "Assignment" to section "1" and I fill the form with:
      | Assignment name | Test assignment name |
      | Description | Submit your online text |
140
      | id_completion | 1                     |
141
    And I am on "Course 1" course homepage
142
    And I navigate to "Add a new badge" node in "Course administration > Badges"
143
    And I follow "Add a new badge"
144
    And I set the following fields to these values:
145
146
147
      | Name | Course Badge |
      | Description | Course badge description |
      | issuername | Tester of course badge |
148
    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
149
    And I press "Create badge"
150
151
    And I set the field "type" to "Activity completion"
    And I set the field "Test assignment name" to "1"
152
153
154
155
156
    And I press "Save"
    And I press "Enable access"
    When I press "Continue"
    And I log out
    And I log in as "student1"
157
    And I follow "Profile" in the user menu
158
    And I click on "Course 1" "link" in the "region-main" "region"
159
    Then I should not see "badges"
160
    And I am on "Course 1" course homepage
161
    And I click on "Not completed: Test assignment name" "icon"
162
    And I follow "Profile" in the user menu
163
    And I click on "Course 1" "link" in the "region-main" "region"
164
165
166
167
    Then I should see "Course Badge"

  @javascript
  Scenario: Award badge on course completion
168
    Given the following "courses" exist:
169
170
      | fullname | shortname | category |
      | Course 1 | C1 | 0 |
171
    And the following "users" exist:
172
      | username | firstname | lastname | email |
173
174
      | teacher1 | Teacher | Frist | teacher1@example.com |
      | student1 | Student | First | student1@example.com |
175
    And the following "course enrolments" exist:
176
177
178
      | user | course | role |
      | teacher1 | C1 | editingteacher |
      | student1 | C1 | student |
179
    And I log in as "teacher1"
180
    And I am on "Course 1" course homepage
181
    And I navigate to "Edit settings" node in "Course administration"
182
    And I set the following fields to these values:
183
      | Enable completion tracking | Yes |
184
    And I press "Save and display"
185
186
187
188
189
    And I turn editing mode on
    And I add a "Assignment" to section "1" and I fill the form with:
      | Assignment name | Test assignment name |
      | Description | Submit your online text |
      | assignsubmission_onlinetext_enabled | 1 |
190
      | id_completion | 1                     |
191
    And I navigate to "Course completion" node in "Course administration"
192
    And I set the field "id_overall_aggregation" to "2"
193
    And I click on "Condition: Activity completion" "link"
194
    And I set the field "Assignment - Test assignment name" to "1"
195
    And I press "Save changes"
196
    And I am on "Course 1" course homepage
197
    And I navigate to "Add a new badge" node in "Course administration > Badges"
198
    And I follow "Add a new badge"
199
    And I set the following fields to these values:
200
201
202
      | Name | Course Badge |
      | Description | Course badge description |
      | issuername | Tester of course badge |
203
    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
204
    And I press "Create badge"
205
    And I set the field "type" to "Course completion"
206
    And I set the field with xpath ".//*[contains(., 'Minimum grade required')]/ancestor::*[contains(concat(' ', @class, ' '), ' fitem ')]//input[1]" to "0"
207
208
209
210
211
    And I press "Save"
    And I press "Enable access"
    When I press "Continue"
    And I log out
    And I log in as "student1"
212
    And I follow "Profile" in the user menu
213
    And I click on "Course 1" "link" in the "region-main" "region"
214
    Then I should not see "badges"
215
    And I am on "Course 1" course homepage
216
    And I click on "Not completed: Test assignment name" "icon"
217
    And I log out
218
219
220
221
222
223
224
    # Completion cron won't mark the whole course completed unless the
    # individual criteria was marked completed more than a second ago. So
    # run it twice, first to mark the criteria and second for the course.
    And I run the scheduled task "core\task\completion_regular_task"
    And I wait "1" seconds
    And I run the scheduled task "core\task\completion_regular_task"
    # The student should now see their badge.
225
    And I log in as "student1"
226
    And I follow "Profile" in the user menu
227
    Then I should see "Course Badge"
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244

  @javascript
  Scenario: All of the selected roles can award badges
    Given the following "users" exist:
      | username | firstname | lastname | email |
      | teacher1 | Teacher | 1 | teacher1@example.com |
      | student1 | Student | 1 | student1@example.com |
      | student2 | Student | 2 | student2@example.com |
    And the following "courses" exist:
      | fullname | shortname | category | groupmode |
      | Course 1 | C1 | 0 | 1 |
    And the following "course enrolments" exist:
      | user | course | role |
      | teacher1 | C1 | editingteacher |
      | student1 | C1 | student |
      | student2 | C1 | student |
    And I log in as "teacher1"
245
    And I am on "Course 1" course homepage
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
    # Create course badge 1.
    And I navigate to "Add a new badge" node in "Course administration > Badges"
    And I follow "Add a new badge"
    And I set the following fields to these values:
      | Name | Course Badge 1 |
      | Description | Course badge description |
      | issuername | Tester of course badge |
    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
    And I press "Create badge"
    And I set the field "type" to "Manual issue by role"
    And I expand all fieldsets
    # Set to ANY of the roles awards badge.
    And I set the field "Teacher" to "1"
    And I set the field "Any of the selected roles awards the badge" to "1"
    And I press "Save"
    And I press "Enable access"
    And I press "Continue"
    And I follow "Recipients (0)"
    And I press "Award badge"
    # Award course badge 1 to student 1.
    And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
    When I press "Award badge"
    And I follow "Course Badge 1"
    And I follow "Recipients (1)"
    Then I should see "Recipients (1)"
    # Add course badge 2.
    And I navigate to "Add a new badge" node in "Course administration > Badges"
    And I follow "Add a new badge"
    And I set the following fields to these values:
      | Name | Course Badge 2 |
      | Description | Course badge description |
      | issuername | Tester of course badge |
    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
    And I press "Create badge"
    And I set the field "type" to "Manual issue by role"
    And I expand all fieldsets
    # Set to ALL of the selected roles award badge.
    And I set the field "Teacher" to "1"
    And I set the field "All of the selected roles award the badge" to "1"
    And I press "Save"
    And I press "Enable access"
    And I press "Continue"
    And I follow "Recipients (0)"
    And I press "Award badge"
    # Award course badge 2 to student 2.
    And I set the field "potentialrecipients[]" to "Student 2 (student2@example.com)"
    When I press "Award badge"
    And I follow "Course Badge 2"
    And I follow "Recipients (1)"
    Then I should see "Recipients (1)"
    And I log out
    And I trigger cron
    # Student 1 should have just course badge 1.
    And I log in as "student1"
    And I follow "Profile" in the user menu
301
    When I click on "Course 1" "link" in the "region-main" "region"
302
303
304
305
306
307
    Then I should see "Course Badge 1"
    And I should not see "Course Badge 2"
    And I log out
    # Student 2 should have just course badge 2.
    And I log in as "student2"
    And I follow "Profile" in the user menu
308
    When I click on "Course 1" "link" in the "region-main" "region"
309
310
    Then I should see "Course Badge 2"
    Then I should not see "Course Badge 1"
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327

  @javascript
  Scenario: Revoke badge
    Given the following "users" exist:
      | username | firstname | lastname | email |
      | teacher1 | Teacher | 1 | teacher1@example.com |
      | student1 | Student | 1 | student1@example.com |
      | student2 | Student | 2 | student2@example.com |
    And the following "courses" exist:
      | fullname | shortname | category | groupmode |
      | Course 1 | C1 | 0 | 1 |
    And the following "course enrolments" exist:
      | user | course | role |
      | teacher1 | C1 | editingteacher |
      | student1 | C1 | student |
      | student2 | C1 | student |
    And I log in as "teacher1"
328
    And I am on "Course 1" course homepage
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
    And I navigate to "Add a new badge" node in "Course administration > Badges"
    And I follow "Add a new badge"
    And I set the following fields to these values:
      | Name | Course Badge |
      | Description | Course badge description |
      | issuername | Tester of course badge |
    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
    And I press "Create badge"
    And I set the field "type" to "Manual issue by role"
    And I set the field "Teacher" to "1"
    And I press "Save"
    And I press "Enable access"
    And I press "Continue"
    And I follow "Recipients (0)"
    And I press "Award badge"
    And I set the field "potentialrecipients[]" to "Student 2 (student2@example.com)"
    And I press "Award badge"
    And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
    When I press "Award badge"
348
    And I follow "Course Badge"
349
350
351
352
    Then I should see "Recipients (2)"
    And I follow "Recipients (2)"
    And I press "Award badge"
    And I set the field "existingrecipients[]" to "Student 2 (student2@example.com)"
353
    And I press "Revoke badge"
354
    And I set the field "existingrecipients[]" to "Student 1 (student1@example.com)"
355
    When I press "Revoke badge"
356
    And I follow "Course Badge"
357
    Then I should see "Recipients (0)"