award_badge.feature 14.7 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 click on "Admin User" "link"
34
    And I choose "Profile" in the open action menu
35
36
    And I follow "Edit profile"
    And I expand all fieldsets
37
    And I set the field "Phone" to "123456789"
38
    And I press "Update profile"
39
    And I follow "Profile" in the user menu
40
41
    Then I should see "Profile Badge"
    And I should not see "There are no badges available."
42
43

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

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

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

  @javascript
  Scenario: Award badge on course completion
170
    Given the following "courses" exist:
171
172
      | fullname | shortname | category |
      | Course 1 | C1 | 0 |
173
    And the following "users" exist:
174
      | username | firstname | lastname | email |
175
176
      | teacher1 | Teacher | Frist | teacher1@example.com |
      | student1 | Student | First | student1@example.com |
177
    And the following "course enrolments" exist:
178
179
180
      | user | course | role |
      | teacher1 | C1 | editingteacher |
      | student1 | C1 | student |
181
    And I log in as "teacher1"
182
183
    And I follow "Course 1"
    And I follow "Edit settings"
184
    And I set the following fields to these values:
185
      | Enable completion tracking | Yes |
186
    And I press "Save and display"
187
188
189
190
191
192
    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 |
    And I follow "Course completion"
193
    And I set the field "id_overall_aggregation" to "2"
194
    And I click on "Condition: Activity completion" "link"
195
    And I set the field "Assignment - Test assignment name" to "1"
196
197
    And I press "Save changes"
    And I follow "Course 1"
198
    And I navigate to "Add a new badge" node in "Course administration > Badges"
199
    And I follow "Add a new badge"
200
    And I set the following fields to these values:
201
202
203
      | Name | Course Badge |
      | Description | Course badge description |
      | issuername | Tester of course badge |
204
    And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
205
    And I press "Create badge"
206
    And I set the field "type" to "Course completion"
207
    And I set the field with xpath ".//*[contains(., 'Minimum grade required')]/ancestor::*[contains(concat(' ', @class, ' '), ' fitem ')]//input[1]" to "0"
208
209
210
211
212
    And I press "Save"
    And I press "Enable access"
    When I press "Continue"
    And I log out
    And I log in as "student1"
213
    And I follow "Profile" in the user menu
214
    And I follow "Course 1"
215
216
    Then I should not see "badges"
    And I am on homepage
217
218
219
    And I follow "Course 1"
    And I press "Mark as complete: Test assignment name"
    And I log out
220
221
222
223
224
225
226
    # 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.
227
    And I log in as "student1"
228
    And I follow "Profile" in the user menu
229
    Then I should see "Course Badge"
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
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
301
302
303
304
305
306
307
308
309
310
311
312

  @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"
    And I follow "Course 1"
    # 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
    When I follow "Course 1"
    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
    When I follow "Course 1"
    Then I should see "Course Badge 2"
    Then I should not see "Course Badge 1"
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

  @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"
    And I follow "Course 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 |
      | 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"
    And I follow "Course Badge"
    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)"
    And I press "Remove badge"
    And I set the field "existingrecipients[]" to "Student 1 (student1@example.com)"
    When I press "Award badge"
    And I follow "Remove Badge"
    Then I should see "Recipients (0)"
    And I log out
    And I log in as "student1"
    And I follow "Profile" in the user menu
    And I follow "Course 1"
    And I should see "Course Badge"