award_badge.feature 17.6 KB
Newer Older
1
@core @core_badges @_file_upload
2
3
4
5
6
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

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  @javascript
  Scenario: Award badge on other badges as criteria
    Given the following "users" exist:
      | username | firstname | lastname | email |
      | teacher1 | Teacher | 1 | teacher1@example.com |
      | student1 | Student | 1 | student1@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 |
    And I log in as "teacher1"
    And I am on "Course 1" course homepage
    # 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 1 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"
    # 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 2 description |
      | issuername | Tester of course badge |
    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
    And I press "Create badge"
    # Set "course badge 1" as criteria
    And I set the field "type" to "Awarded badges"
    And I set the field "id_badge_badges" to "Course Badge 1"
    And I press "Save"
    And I press "Enable access"
    And I press "Continue"
    And I follow "Manage badges"
    And I follow "Course Badge 1"
    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)"
    And I log out
    # Student 1 should have both badges.
    And I log in as "student1"
    And I follow "Profile" in the user menu
    When I click on "Course 1" "link" in the "region-main" "region"
    Then I should see "Course Badge 1"
    And I should see "Course Badge 2"

72
  @javascript
73
  Scenario: Award profile badge
74
    Given I log in as "admin"
75
    And I navigate to "Add a new badge" node in "Site administration > Badges"
76
    And I set the following fields to these values:
77
      | Name | Profile Badge |
78
79
      | Description | Test badge description |
      | issuername | Test Badge Site |
80
      | issuercontact | testuser@example.com |
81
    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
82
    And I press "Create badge"
83
    And I set the field "type" to "Profile completion"
84
    And I expand all fieldsets
85
86
87
    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"
88
    And I set the field "id_description" to "Criterion description"
89
90
91
92
    When I press "Save"
    Then I should see "Profile completion"
    And I should see "First name"
    And I should see "Email address"
93
94
    And I should see "Phone"
    And I should see "Criterion description"
95
    And I should not see "Criteria for this badge have not been set up yet."
96
97
    And I press "Enable access"
    And I press "Continue"
98
    And I open my profile in edit mode
99
    And I expand all fieldsets
100
    And I set the field "Phone" to "123456789"
101
    And I press "Update profile"
102
    And I follow "Profile" in the user menu
103
104
    Then I should see "Profile Badge"
    And I should not see "There are no badges available."
105
106

  @javascript
107
  Scenario: Award site badge
108
    Given the following "users" exist:
109
      | username | firstname | lastname | email |
110
111
      | teacher | teacher | 1 | teacher1@example.com |
      | student | student | 1 | student1@example.com |
112
    And I log in as "admin"
113
    And I navigate to "Add a new badge" node in "Site administration > Badges"
114
    And I set the following fields to these values:
115
116
117
      | Name | Site Badge |
      | Description | Site badge description |
      | issuername | Tester of site badge |
118
    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
119
    And I press "Create badge"
120
121
    And I set the field "type" to "Manual issue by role"
    And I set the field "Teacher" to "1"
122
123
124
    And I press "Save"
    And I press "Enable access"
    And I press "Continue"
125
126
    And I follow "Recipients (0)"
    And I press "Award badge"
127
    And I set the field "potentialrecipients[]" to "teacher 1 (teacher1@example.com)"
128
    And I press "Award badge"
129
    And I set the field "potentialrecipients[]" to "student 1 (student1@example.com)"
130
131
132
133
134
    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"
135
    And I follow "Profile" in the user menu
136
    Then I should see "Site Badge"
137
138
139

  @javascript
  Scenario: Award course badge
140
    Given the following "users" exist:
141
      | username | firstname | lastname | email |
142
143
144
      | teacher1 | Teacher | 1 | teacher1@example.com |
      | student1 | Student | 1 | student1@example.com |
      | student2 | Student | 2 | student2@example.com |
145
    And the following "courses" exist:
146
147
      | fullname | shortname | category | groupmode |
      | Course 1 | C1 | 0 | 1 |
148
    And the following "course enrolments" exist:
149
150
151
152
153
      | user | course | role |
      | teacher1 | C1 | editingteacher |
      | student1 | C1 | student |
      | student2 | C1 | student |
    And I log in as "teacher1"
154
    And I am on "Course 1" course homepage
155
    And I navigate to "Add a new badge" node in "Course administration > Badges"
156
    And I follow "Add a new badge"
157
    And I set the following fields to these values:
158
159
160
      | Name | Course Badge |
      | Description | Course badge description |
      | issuername | Tester of course badge |
161
    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
162
    And I press "Create badge"
163
164
    And I set the field "type" to "Manual issue by role"
    And I set the field "Teacher" to "1"
165
166
167
168
169
    And I press "Save"
    And I press "Enable access"
    And I press "Continue"
    And I follow "Recipients (0)"
    And I press "Award badge"
170
    And I set the field "potentialrecipients[]" to "Student 2 (student2@example.com)"
171
    And I press "Award badge"
172
    And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
173
    When I press "Award badge"
174
    And I follow "Course Badge"
175
176
177
    Then I should see "Recipients (2)"
    And I log out
    And I log in as "student1"
178
    And I follow "Profile" in the user menu
179
    And I click on "Course 1" "link" in the "region-main" "region"
180
    And I should see "Course Badge"
181
182
183

  @javascript
  Scenario: Award badge on activity completion
184
    Given the following "courses" exist:
185
186
      | fullname | shortname | category |
      | Course 1 | C1 | 0 |
187
    And the following "users" exist:
188
      | username | firstname | lastname | email |
189
190
      | teacher1 | Teacher | Frist | teacher1@example.com |
      | student1 | Student | First | student1@example.com |
191
    And the following "course enrolments" exist:
192
193
194
      | user | course | role |
      | teacher1 | C1 | editingteacher |
      | student1 | C1 | student |
195
    And I log in as "teacher1"
196
    And I am on "Course 1" course homepage
197
    And I navigate to "Edit settings" node in "Course administration"
198
    And I set the following fields to these values:
199
      | Enable completion tracking | Yes |
200
    And I press "Save and display"
201
202
203
204
    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 |
205
      | id_completion | 1                     |
206
    And I am on "Course 1" course homepage
207
    And I navigate to "Add a new badge" node in "Course administration > Badges"
208
    And I follow "Add a new badge"
209
    And I set the following fields to these values:
210
211
212
      | Name | Course Badge |
      | Description | Course badge description |
      | issuername | Tester of course badge |
213
    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
214
    And I press "Create badge"
215
216
    And I set the field "type" to "Activity completion"
    And I set the field "Test assignment name" to "1"
217
218
219
220
221
    And I press "Save"
    And I press "Enable access"
    When I press "Continue"
    And I log out
    And I log in as "student1"
222
    And I follow "Profile" in the user menu
223
    And I click on "Course 1" "link" in the "region-main" "region"
224
    Then I should not see "badges"
225
    And I am on "Course 1" course homepage
226
    And I click on "Not completed: Test assignment name" "icon"
227
    And I follow "Profile" in the user menu
228
    And I click on "Course 1" "link" in the "region-main" "region"
229
230
231
232
    Then I should see "Course Badge"

  @javascript
  Scenario: Award badge on course completion
233
    Given the following "courses" exist:
234
235
      | fullname | shortname | category |
      | Course 1 | C1 | 0 |
236
    And the following "users" exist:
237
      | username | firstname | lastname | email |
238
239
      | teacher1 | Teacher | Frist | teacher1@example.com |
      | student1 | Student | First | student1@example.com |
240
    And the following "course enrolments" exist:
241
242
243
      | user | course | role |
      | teacher1 | C1 | editingteacher |
      | student1 | C1 | student |
244
    And I log in as "teacher1"
245
    And I am on "Course 1" course homepage
246
    And I navigate to "Edit settings" node in "Course administration"
247
    And I set the following fields to these values:
248
      | Enable completion tracking | Yes |
249
    And I press "Save and display"
250
251
252
253
254
    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 |
255
      | id_completion | 1                     |
256
    And I navigate to "Course completion" node in "Course administration"
257
    And I set the field "id_overall_aggregation" to "2"
258
    And I click on "Condition: Activity completion" "link"
259
    And I set the field "Assignment - Test assignment name" to "1"
260
    And I press "Save changes"
261
    And I am on "Course 1" course homepage
262
    And I navigate to "Add a new badge" node in "Course administration > Badges"
263
    And I follow "Add a new badge"
264
    And I set the following fields to these values:
265
266
267
      | Name | Course Badge |
      | Description | Course badge description |
      | issuername | Tester of course badge |
268
    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
269
    And I press "Create badge"
270
    And I set the field "type" to "Course completion"
271
    And I set the field with xpath ".//*[contains(., 'Minimum grade required')]/ancestor::*[contains(concat(' ', @class, ' '), ' fitem ')]//input[1]" to "0"
272
273
274
275
276
    And I press "Save"
    And I press "Enable access"
    When I press "Continue"
    And I log out
    And I log in as "student1"
277
    And I follow "Profile" in the user menu
278
    And I click on "Course 1" "link" in the "region-main" "region"
279
    Then I should not see "badges"
280
    And I am on "Course 1" course homepage
281
    And I click on "Not completed: Test assignment name" "icon"
282
    And I log out
283
284
285
286
287
288
289
    # 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.
290
    And I log in as "student1"
291
    And I follow "Profile" in the user menu
292
    Then I should see "Course Badge"
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309

  @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"
310
    And I am on "Course 1" course homepage
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
    # 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
366
    When I click on "Course 1" "link" in the "region-main" "region"
367
368
369
370
371
372
    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
373
    When I click on "Course 1" "link" in the "region-main" "region"
374
375
    Then I should see "Course Badge 2"
    Then I should not see "Course Badge 1"
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392

  @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"
393
    And I am on "Course 1" course homepage
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
    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"
413
    And I follow "Course Badge"
414
415
416
417
    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)"
418
    And I press "Revoke badge"
419
    And I set the field "existingrecipients[]" to "Student 1 (student1@example.com)"
420
    When I press "Revoke badge"
421
    And I follow "Course Badge"
422
    Then I should see "Recipients (0)"