d277721b33584cd87bde90e4dd7e02dc66ec6a3a
[moodle.git] / badges / tests / behat / award_badge.feature
1 @core @core_badges @_file_upload
2 Feature: 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
7   @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       | Description | Test badge description |
14       | issuername | Test Badge Site |
15       | issuercontact | testuser@test-badge-site.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 set the field "First name" to "1"
20     And I set the field "Email address" to "1"
21     And I set the field "Phone" to "1"
22     When I press "Save"
23     Then I should see "Profile completion"
24     And I should see "First name"
25     And I should see "Email address"
26     And I should not see "Criteria for this badge have not been set up yet."
27     And I press "Enable access"
28     And I press "Continue"
29     And I expand "My profile settings" node
30     And I follow "Edit profile"
31     And I expand all fieldsets
32     And I set the field "Phone" to "123456789"
33     And I press "Update profile"
34     And I follow "My badges"
35     Then I should see "Profile Badge"
36     And I should not see "There are no badges available."
38   @javascript
39   Scenario: Award site badge
40     Given the following "users" exist:
41       | username | firstname | lastname | email |
42       | teacher | teacher | 1 | teacher1@asd.com |
43       | student | student | 1 | student1@asd.com |
44     And I log in as "admin"
45     And I navigate to "Add a new badge" node in "Site administration > Badges"
46     And I set the following fields to these values:
47       | Name | Site Badge |
48       | Description | Site badge description |
49       | issuername | Tester of site badge |
50     And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
51     And I press "Create badge"
52     And I set the field "type" to "Manual issue by role"
53     And I set the field "Teacher" to "1"
54     And I press "Save"
55     And I press "Enable access"
56     And I press "Continue"
57     And I follow "Recipients (0)"
58     And I press "Award badge"
59     And I set the field "potentialrecipients[]" to "teacher 1 (teacher1@asd.com)"
60     And I press "Award badge"
61     And I set the field "potentialrecipients[]" to "student 1 (student1@asd.com)"
62     And I press "Award badge"
63     When I follow "Site Badge"
64     Then I should see "Recipients (2)"
65     And I log out
66     And I log in as "student"
67     And I expand "My profile" node
68     And I follow "My badges"
69     Then I should see "Site Badge"
71   @javascript
72   Scenario: Award course badge
73     Given the following "users" exist:
74       | username | firstname | lastname | email |
75       | teacher1 | Teacher | 1 | teacher1@asd.com |
76       | student1 | Student | 1 | student1@asd.com |
77       | student2 | Student | 2 | student2@asd.com |
78     And the following "courses" exist:
79       | fullname | shortname | category | groupmode |
80       | Course 1 | C1 | 0 | 1 |
81     And the following "course enrolments" exist:
82       | user | course | role |
83       | teacher1 | C1 | editingteacher |
84       | student1 | C1 | student |
85       | student2 | C1 | student |
86     And I log in as "teacher1"
87     And I follow "Course 1"
88     And I navigate to "Add a new badge" node in "Course administration > Badges"
89     And I follow "Add a new badge"
90     And I set the following fields to these values:
91       | Name | Course Badge |
92       | Description | Course badge description |
93       | issuername | Tester of course badge |
94     And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
95     And I press "Create badge"
96     And I set the field "type" to "Manual issue by role"
97     And I set the field "Teacher" to "1"
98     And I press "Save"
99     And I press "Enable access"
100     And I press "Continue"
101     And I follow "Recipients (0)"
102     And I press "Award badge"
103     And I set the field "potentialrecipients[]" to "Student 2 (student2@asd.com)"
104     And I press "Award badge"
105     And I set the field "potentialrecipients[]" to "Student 1 (student1@asd.com)"
106     When I press "Award badge"
107     And I follow "Course Badge"
108     Then I should see "Recipients (2)"
109     And I log out
110     And I log in as "student1"
111     And I follow "Course 1"
112     And I expand "My profile" node
113     And I follow "My badges"
114     Then I should see "Course Badge"
116   @javascript
117   Scenario: Award badge on activity completion
118     Given the following "courses" exist:
119       | fullname | shortname | category |
120       | Course 1 | C1 | 0 |
121     And the following "users" exist:
122       | username | firstname | lastname | email |
123       | teacher1 | Teacher | Frist | teacher1@asd.com |
124       | student1 | Student | First | student1@asd.com |
125     And the following "course enrolments" exist:
126       | user | course | role |
127       | teacher1 | C1 | editingteacher |
128       | student1 | C1 | student |
129     And I log in as "admin"
130     And I set the following administration settings values:
131       | Enable completion tracking | 1 |
132     And I follow "Home"
133     And I follow "Course 1"
134     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 changes"
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 |
142     And I log out
143     And I log in as "teacher1"
144     And I follow "Course 1"
145     And I navigate to "Add a new badge" node in "Course administration > Badges"
146     And I follow "Add a new badge"
147     And I set the following fields to these values:
148       | Name | Course Badge |
149       | Description | Course badge description |
150       | issuername | Tester of course badge |
151     And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
152     And I press "Create badge"
153     And I set the field "type" to "Activity completion"
154     And I set the field "Test assignment name" to "1"
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"
160     And I follow "Course 1"
161     And I expand "My profile" node
162     And I follow "My badges"
163     Then I should see "There are no badges available."
164     And I follow "Home"
165     And I follow "Course 1"
166     And I press "Mark as complete: Test assignment name"
167     And I expand "My profile" node
168     And I follow "My badges"
169     Then I should see "Course Badge"
171   @javascript
172   Scenario: Award badge on course completion
173     Given the following "courses" exist:
174       | fullname | shortname | category |
175       | Course 1 | C1 | 0 |
176     And the following "users" exist:
177       | username | firstname | lastname | email |
178       | teacher1 | Teacher | Frist | teacher1@asd.com |
179       | student1 | Student | First | student1@asd.com |
180     And the following "course enrolments" exist:
181       | user | course | role |
182       | teacher1 | C1 | editingteacher |
183       | student1 | C1 | student |
184     And I log in as "admin"
185     And I set the following administration settings values:
186       | Enable completion tracking | 1 |
187     And I follow "Home"
188     And I follow "Course 1"
189     And I follow "Edit settings"
190     And I set the following fields to these values:
191       | Enable completion tracking | Yes |
192     And I press "Save changes"
193     And I turn editing mode on
194     And I add a "Assignment" to section "1" and I fill the form with:
195       | Assignment name | Test assignment name |
196       | Description | Submit your online text |
197       | assignsubmission_onlinetext_enabled | 1 |
198     And I follow "Course completion"
199     And I set the field "id_overall_aggregation" to "2"
200     And I click on "Condition: Activity completion" "link"
201     And I set the field "Assign - Test assignment name" to "1"
202     And I press "Save changes"
203     And I log out
204     And I log in as "teacher1"
205     And I follow "Course 1"
206     And I navigate to "Add a new badge" node in "Course administration > Badges"
207     And I follow "Add a new badge"
208     And I set the following fields to these values:
209       | Name | Course Badge |
210       | Description | Course badge description |
211       | issuername | Tester of course badge |
212     And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
213     And I press "Create badge"
214     And I set the field "type" to "Course completion"
215     And I set the field with xpath "//fieldset/input[1]" to "0"
216     And I press "Save"
217     And I press "Enable access"
218     When I press "Continue"
219     And I log out
220     And I log in as "student1"
221     And I follow "Course 1"
222     And I expand "My profile" node
223     And I follow "My badges"
224     Then I should see "There are no badges available."
225     And I follow "Home"
226     And I follow "Course 1"
227     And I press "Mark as complete: Test assignment name"
228     And I log out
229     And I log in as "admin"
230     # We can't wait for cron to happen, so the admin manually triggers it.
231     And I trigger cron
232     # The admin needs to trigger cron twice to see the completion status as completed.
233     # We wait more than 1 minute because of the next cron run scheduled time.
234     And I wait "61" seconds
235     And I trigger cron
236     # Finally the admin goes back to homepage to continue the user story.
237     And I am on homepage
238     And I log out
239     And I log in as "student1"
240     And I expand "My profile" node
241     And I follow "My badges"
242     Then I should see "Course Badge"