Moodle release 2.9beta
[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 |
15 | issuercontact | testuser@test-badge-site.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
AA
33 And I click on "Admin User" "link"
34 And I follow "My 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"
ae0bf677 39 And I follow "My 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
JM
46 | username | firstname | lastname | email |
47 | teacher | teacher | 1 | teacher1@asd.com |
48 | student | student | 1 | student1@asd.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"
f083d614 64 And I set the field "potentialrecipients[]" to "teacher 1 (teacher1@asd.com)"
844d74d7 65 And I press "Award badge"
f083d614 66 And I set the field "potentialrecipients[]" to "student 1 (student1@asd.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"
ae0bf677 72 And I follow "My 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
JM
78 | username | firstname | lastname | email |
79 | teacher1 | Teacher | 1 | teacher1@asd.com |
80 | student1 | Student | 1 | student1@asd.com |
81 | student2 | Student | 2 | student2@asd.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"
f083d614 107 And I set the field "potentialrecipients[]" to "Student 2 (student2@asd.com)"
68c13c68 108 And I press "Award badge"
f083d614 109 And I set the field "potentialrecipients[]" to "Student 1 (student1@asd.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"
ae0bf677 115 And I follow "My 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
JM
125 | username | firstname | lastname | email |
126 | teacher1 | Teacher | Frist | teacher1@asd.com |
127 | student1 | Student | First | student1@asd.com |
759b323e 128 And the following "course enrolments" exist:
066ef320
JM
129 | user | course | role |
130 | teacher1 | C1 | editingteacher |
131 | student1 | C1 | student |
bed97c39
RT
132 And the following config values are set as admin:
133 | enablecompletion | 1 |
134 And I log in as "teacher1"
066ef320
JM
135 And I follow "Course 1"
136 And I follow "Edit settings"
f083d614 137 And I set the following fields to these values:
066ef320 138 | Enable completion tracking | Yes |
38ea5e0a 139 And I press "Save and display"
066ef320
JM
140 And I turn editing mode on
141 And I add a "Assignment" to section "1" and I fill the form with:
142 | Assignment name | Test assignment name |
143 | Description | Submit your online text |
066ef320 144 And I follow "Course 1"
004d7e35 145 And I navigate to "Add a new badge" node in "Course administration > Badges"
066ef320 146 And I follow "Add a new badge"
f083d614 147 And I set the following fields to these values:
066ef320
JM
148 | Name | Course Badge |
149 | Description | Course badge description |
150 | issuername | Tester of course badge |
07622451 151 And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
066ef320 152 And I press "Create badge"
f083d614
DM
153 And I set the field "type" to "Activity completion"
154 And I set the field "Test assignment name" to "1"
066ef320
JM
155 And I press "Save"
156 And I press "Enable access"
157 When I press "Continue"
158 And I log out
159 And I log in as "student1"
ae0bf677 160 And I follow "My profile" in the user menu
066ef320 161 And I follow "Course 1"
ae0bf677
AA
162 Then I should not see "badges"
163 And I am on homepage
066ef320
JM
164 And I follow "Course 1"
165 And I press "Mark as complete: Test assignment name"
ae0bf677
AA
166 And I follow "My profile" in the user menu
167 And I follow "Course 1"
066ef320
JM
168 Then I should see "Course Badge"
169
170 @javascript
171 Scenario: Award badge on course completion
759b323e 172 Given the following "courses" exist:
066ef320
JM
173 | fullname | shortname | category |
174 | Course 1 | C1 | 0 |
759b323e 175 And the following "users" exist:
066ef320
JM
176 | username | firstname | lastname | email |
177 | teacher1 | Teacher | Frist | teacher1@asd.com |
178 | student1 | Student | First | student1@asd.com |
759b323e 179 And the following "course enrolments" exist:
066ef320
JM
180 | user | course | role |
181 | teacher1 | C1 | editingteacher |
182 | student1 | C1 | student |
bed97c39
RT
183 And the following config values are set as admin:
184 | enablecompletion | 1 |
185 And I log in as "teacher1"
066ef320
JM
186 And I follow "Course 1"
187 And I follow "Edit settings"
f083d614 188 And I set the following fields to these values:
066ef320 189 | Enable completion tracking | Yes |
38ea5e0a 190 And I press "Save and display"
066ef320
JM
191 And I turn editing mode on
192 And I add a "Assignment" to section "1" and I fill the form with:
193 | Assignment name | Test assignment name |
194 | Description | Submit your online text |
195 | assignsubmission_onlinetext_enabled | 1 |
196 And I follow "Course completion"
f083d614 197 And I set the field "id_overall_aggregation" to "2"
066ef320 198 And I click on "Condition: Activity completion" "link"
f083d614 199 And I set the field "Assign - Test assignment name" to "1"
066ef320 200 And I press "Save changes"
066ef320 201 And I follow "Course 1"
004d7e35 202 And I navigate to "Add a new badge" node in "Course administration > Badges"
066ef320 203 And I follow "Add a new badge"
f083d614 204 And I set the following fields to these values:
066ef320
JM
205 | Name | Course Badge |
206 | Description | Course badge description |
207 | issuername | Tester of course badge |
07622451 208 And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
066ef320 209 And I press "Create badge"
f083d614 210 And I set the field "type" to "Course completion"
6c396b6b 211 And I set the field with xpath "//fieldset/input[1]" to "0"
066ef320
JM
212 And I press "Save"
213 And I press "Enable access"
214 When I press "Continue"
215 And I log out
216 And I log in as "student1"
ae0bf677 217 And I follow "My profile" in the user menu
066ef320 218 And I follow "Course 1"
ae0bf677
AA
219 Then I should not see "badges"
220 And I am on homepage
066ef320
JM
221 And I follow "Course 1"
222 And I press "Mark as complete: Test assignment name"
223 And I log out
224 And I log in as "admin"
225 # We can't wait for cron to happen, so the admin manually triggers it.
226 And I trigger cron
227 # The admin needs to trigger cron twice to see the completion status as completed.
b71419ae
DM
228 # We wait more than 1 minute because of the next cron run scheduled time.
229 And I wait "61" seconds
066ef320
JM
230 And I trigger cron
231 # Finally the admin goes back to homepage to continue the user story.
ae0bf677 232 And I am on site homepage
066ef320
JM
233 And I log out
234 And I log in as "student1"
ae0bf677 235 And I follow "My profile" in the user menu
a57263d1 236 Then I should see "Course Badge"