Merge branch 'MDL-63968-master' of git://github.com/andrewnicols/moodle
[moodle.git] / grade / tests / behat / grade_natural_exclude_empty_20150619.feature
blob39578ff9a3842932f63057a0ace3a34e08043013
1 @core @core_grades
2 Feature: Gradebook calculations for extra credit items before the fix 20150619
3   In order to make sure the grades are not changed after upgrade
4   As a teacher
5   I need to be able to freeze gradebook calculations
7   Background:
8     Given the following "courses" exist:
9       | fullname | shortname | category | groupmode |
10       | Course 1 | C1 | 0 | 1 |
11     And gradebook calculations for the course "C1" are frozen at version "20150619"
12     And the following "users" exist:
13       | username | firstname | lastname | email                | idnumber |
14       | teacher1 | Teacher   | 1        | teacher1@example.com | t1       |
15       | student1 | Student   | 1        | student1@example.com | s1       |
16     And the following "course enrolments" exist:
17       | user | course | role |
18       | teacher1 | C1 | editingteacher |
19       | student1 | C1 | student |
20     And the following "activities" exist:
21       | activity | course | idnumber | name                         | intro | grade |
22       | assign   | C1     | a1       | Test assignment one          | x     | 100   |
23       | assign   | C1     | a2       | Test assignment two          | x     | 50    |
24       | assign   | C1     | a3       | Test assignment three        | x     | 200   |
25       | assign   | C1     | a4       | Test assignment four (extra) | x     | 20    |
26       | assign   | C1     | a5       | Test assignment five (extra) | x     | 10    |
27     And I log in as "teacher1"
28     And I am on "Course 1" course homepage
29     And I navigate to "Setup > Gradebook setup" in the course gradebook
30     And I set the following settings for grade item "Test assignment four (extra)":
31       | Extra credit | 1 |
32     And I set the following settings for grade item "Test assignment five (extra)":
33       | Extra credit | 1 |
35   @javascript
36   Scenario: No weights are overridden and student has all grades present (before the fix 20150619)
37     When I navigate to "View > Grader report" in the course gradebook
38     And I turn editing mode on
39     And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
40     And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
41     And I give the grade "150.00" to the user "Student 1" for the grade item "Test assignment three"
42     And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
43     And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
44     And I press "Save changes"
45     And I navigate to "View > User report" in the course gradebook
46     And I set the field "Select all or one user" to "Student 1"
47     Then the following should exist in the "user-grade" table:
48       | Grade item                   | Calculated weight      | Grade  | Range | Percentage | Contribution to course total |
49       | Test assignment one          | 28.57 %                | 80.00  | 0–100 | 80.00 %    | 22.86 %                      |
50       | Test assignment two          | 14.29 %                | 30.00  | 0–50  | 60.00 %    | 8.57 %                       |
51       | Test assignment three        | 57.14 %                | 150.00 | 0–200 | 75.00 %    | 42.86 %                      |
52       | Test assignment four (extra) | 5.71 %( Extra credit ) | 10.00  | 0–20  | 50.00 %    | 2.86 %                       |
53       | Test assignment five (extra) | 2.86 %( Extra credit ) | 8.00   | 0–10  | 80.00 %    | 2.29 %                       |
54       | Course total                 | -                      | 278.00 | 0–350 | 79.43 %    | -                            |
55     And I log out
57   @javascript
58   Scenario: No weights are overridden, student has some grades present (before the fix 20150619)
59     When I navigate to "View > Grader report" in the course gradebook
60     And I turn editing mode on
61     And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
62     And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
63     And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
64     And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
65     And I press "Save changes"
66     And I navigate to "View > User report" in the course gradebook
67     And I set the field "Select all or one user" to "Student 1"
68     Then the following should exist in the "user-grade" table:
69       | Grade item                   | Calculated weight       | Grade  | Range | Percentage | Contribution to course total |
70       | Test assignment one          | 66.67 %                 | 80.00  | 0–100 | 80.00 %    | 53.33 %                      |
71       | Test assignment two          | 33.33 %                 | 30.00  | 0–50  | 60.00 %    | 20.00 %                      |
72       | Test assignment three        | 0.00 %( Empty )         | -      | 0–200 | -          | 0.00 %                       |
73       | Test assignment four (extra) | 13.33 %( Extra credit ) | 10.00  | 0–20  | 50.00 %    | 6.67 %                       |
74       | Test assignment five (extra) | 6.67 %( Extra credit )  | 8.00   | 0–10  | 80.00 %    | 5.33 %                       |
75       | Course total                 | -                       | 128.00 | 0–150 | 85.33 %    | -                            |
76     And I log out
78   @javascript
79   Scenario: No weights are overridden, student has none grades present except for extra credit (before the fix 20150619)
80     When I navigate to "View > Grader report" in the course gradebook
81     And I turn editing mode on
82     And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
83     And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
84     And I press "Save changes"
85     And I navigate to "View > User report" in the course gradebook
86     And I set the field "Select all or one user" to "Student 1"
87     Then the following should exist in the "user-grade" table:
88       | Grade item                   | Calculated weight      | Grade | Range | Percentage | Contribution to course total |
89       | Test assignment one          | 0.00 %( Empty )        | -     | 0–100 | -          | 0.00 %                       |
90       | Test assignment two          | 0.00 %( Empty )        | -     | 0–50  | -          | 0.00 %                       |
91       | Test assignment three        | 0.00 %( Empty )        | -     | 0–200 | -          | 0.00 %                       |
92       | Test assignment four (extra) | 0.00 %( Extra credit ) | 10.00 | 0–20  | 50.00 %    | 0.00 %                       |
93       | Test assignment five (extra) | 0.00 %( Extra credit ) | 8.00  | 0–10  | 80.00 %    | 0.00 %                       |
94       | Course total                 | -                      | 0.00  | 0–0   |            | -                            |
95     And I log out
97   @javascript
98   Scenario: Make sure there are no errors when all items are marked as extra credit (before the fix 20150619)
99     And I set the following settings for grade item "Test assignment one":
100       | Extra credit | 1 |
101     And I set the following settings for grade item "Test assignment two":
102       | Extra credit | 1 |
103     And I set the following settings for grade item "Test assignment three":
104       | Extra credit | 1 |
105     When I navigate to "View > Grader report" in the course gradebook
106     And I turn editing mode on
107     And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
108     And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
109     And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
110     And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
111     And I press "Save changes"
112     And I navigate to "View > User report" in the course gradebook
113     And I set the field "Select all or one user" to "Student 1"
114     Then the following should exist in the "user-grade" table:
115       | Grade item                   | Calculated weight      | Grade | Range | Percentage | Contribution to course total |
116       | Test assignment one          | 0.00 %( Extra credit ) | 80.00 | 0–100 | 80.00 %    | 0.00 %                       |
117       | Test assignment two          | 0.00 %( Extra credit ) | 30.00 | 0–50  | 60.00 %    | 0.00 %                       |
118       | Test assignment three        | 0.00 %( Empty )        | -     | 0–200 | -          | 0.00 %                       |
119       | Test assignment four (extra) | 0.00 %( Extra credit ) | 10.00 | 0–20  | 50.00 %    | 0.00 %                       |
120       | Test assignment five (extra) | 0.00 %( Extra credit ) | 8.00  | 0–10  | 80.00 %    | 0.00 %                       |
121       | Course total                 | -                      | 0.0   | 0–0   |            | -                            |
122     And I log out
124   @javascript
125   Scenario: Weights are overridden and student has all grades present (before the fix 20150619)
126     When I set the field "Override weight of Test assignment one" to "1"
127     And I set the field "Weight of Test assignment one" to "50"
128     And I press "Save changes"
129     When I navigate to "View > Grader report" in the course gradebook
130     And I turn editing mode on
131     And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
132     And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
133     And I give the grade "150.00" to the user "Student 1" for the grade item "Test assignment three"
134     And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
135     And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
136     And I press "Save changes"
137     And I navigate to "View > User report" in the course gradebook
138     And I set the field "Select all or one user" to "Student 1"
139     Then the following should exist in the "user-grade" table:
140       | Grade item                   | Calculated weight      | Grade  | Range | Percentage | Contribution to course total |
141       | Test assignment one          | 50.00 %                | 80.00  | 0–100 | 80.00 %    | 40.00 %                      |
142       | Test assignment two          | 10.00 %                | 30.00  | 0–50  | 60.00 %    | 6.00 %                       |
143       | Test assignment three        | 40.00 %                | 150.00 | 0–200 | 75.00 %    | 30.00 %                      |
144       | Test assignment four (extra) | 4.00 %( Extra credit ) | 10.00  | 0–20  | 50.00 %    | 2.00 %                       |
145       | Test assignment five (extra) | 2.00 %( Extra credit ) | 8.00   | 0–10  | 80.00 %    | 1.60 %                       |
146       | Course total                 | -                      | 278.60 | 0–350 | 79.60 %    | -                            |
147     # Contributions of extra credit "four" should be 20/350=5.71% and "five" 10/350=2.86% (350 is max grade for the course, 20 and 10 are max grades of "four" and "five")
148     And I log out
150   @javascript
151   Scenario: Weights are overridden and student has some grades present (before the fix 20150619)
152     When I set the field "Override weight of Test assignment one" to "1"
153     And I set the field "Weight of Test assignment one" to "50"
154     And I press "Save changes"
155     When I navigate to "View > Grader report" in the course gradebook
156     And I turn editing mode on
157     And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
158     And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
159     And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
160     And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
161     And I press "Save changes"
162     And I navigate to "View > User report" in the course gradebook
163     And I set the field "Select all or one user" to "Student 1"
164     Then the following should exist in the "user-grade" table:
165       | Grade item                   | Calculated weight       | Grade  | Range | Percentage | Contribution to course total |
166       | Test assignment one          | 83.33 %                 | 80.00  | 0–100 | 80.00 %    | 66.67 %                      |
167       | Test assignment two          | 16.67 %                 | 30.00  | 0–50  | 60.00 %    | 10.00 %                      |
168       | Test assignment three        | 0.00 %( Empty )         | -      | 0–200 | -          | 0.00 %                       |
169       | Test assignment four (extra) | 6.67 %( Extra credit )  | 10.00  | 0–20  | 50.00 %    | 3.33 %                       |
170       | Test assignment five (extra) | 3.33 %( Extra credit )  | 8.00   | 0–10  | 80.00 %    | 2.67 %                       |
171       | Course total                 | -                       | 124.00 | 0–150 | 82.67 %    | -                            |
172     # Contributions of extra credit "four" should be 20/150=13.33% and "five" 10/150=6.67% (150 is max grade for the course, 20 and 10 are max grades of "four" and "five")
173     And I log out
175   @javascript
176   Scenario: Weights are overridden, student has none grades present except for extra credit (before the fix 20150619)
177     When I set the field "Override weight of Test assignment one" to "1"
178     And I set the field "Weight of Test assignment one" to "50"
179     And I press "Save changes"
180     When I navigate to "View > Grader report" in the course gradebook
181     And I turn editing mode on
182     And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
183     And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
184     And I press "Save changes"
185     And I navigate to "View > User report" in the course gradebook
186     And I set the field "Select all or one user" to "Student 1"
187     Then the following should exist in the "user-grade" table:
188       | Grade item                   | Calculated weight      | Grade | Range | Percentage | Contribution to course total |
189       | Test assignment one          | 0.00 %( Empty )        | -     | 0–100 | -          | 0.00 %                       |
190       | Test assignment two          | 0.00 %( Empty )        | -     | 0–50  | -          | 0.00 %                       |
191       | Test assignment three        | 0.00 %( Empty )        | -     | 0–200 | -          | 0.00 %                       |
192       | Test assignment four (extra) | 0.00 %( Extra credit ) | 10.00 | 0–20  | 50.00 %    | 0.00 %                       |
193       | Test assignment five (extra) | 0.00 %( Extra credit ) | 8.00  | 0–10  | 80.00 %    | 0.00 %                       |
194       | Course total                 | -                      | 0.00  | 0–0   |            | -                            |
195     And I log out
197   @javascript
198   Scenario: Weights are overridden, including extra credit, and student has all grades present (before the fix 20150619)
199     When I set the field "Override weight of Test assignment one" to "1"
200     And I set the field "Weight of Test assignment one" to "50"
201     And I set the field "Override weight of Test assignment four (extra)" to "1"
202     And I set the field "Weight of Test assignment four (extra)" to "10"
203     And I press "Save changes"
204     When I navigate to "View > Grader report" in the course gradebook
205     And I turn editing mode on
206     And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
207     And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
208     And I give the grade "150.00" to the user "Student 1" for the grade item "Test assignment three"
209     And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
210     And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
211     And I press "Save changes"
212     And I navigate to "View > User report" in the course gradebook
213     And I set the field "Select all or one user" to "Student 1"
214     Then the following should exist in the "user-grade" table:
215       | Grade item                   | Calculated weight       | Grade  | Range | Percentage | Contribution to course total |
216       | Test assignment one          | 50.00 %                 | 80.00  | 0–100 | 80.00 %    | 40.00 %                      |
217       | Test assignment two          | 8.70 %                  | 30.00  | 0–50  | 60.00 %    | 5.22 %                       |
218       | Test assignment three        | 34.78 %                 | 150.00 | 0–200 | 75.00 %    | 26.09 %                      |
219       | Test assignment four (extra) | 10.00 %( Extra credit ) | 10.00  | 0–20  | 50.00 %    | 5.00 %                       |
220       | Test assignment five (extra) | 1.74 %( Extra credit )  | 8.00   | 0–10  | 80.00 %    | 1.39 %                       |
221       | Course total                 | -                       | 271.93 | 0–350 | 77.70 %    | -                            |
222     # Which is absolutely terrible because weights of normal items do not add up to 100%
223     And I log out
225   @javascript
226   Scenario: Weights are overridden, including extra credit, and student has some grades present (before the fix 20150619)
227     When I set the field "Override weight of Test assignment one" to "1"
228     And I set the field "Weight of Test assignment one" to "50"
229     And I set the field "Override weight of Test assignment four (extra)" to "1"
230     And I set the field "Weight of Test assignment four (extra)" to "10"
231     And I press "Save changes"
232     And I navigate to "View > Grader report" in the course gradebook
233     And I turn editing mode on
234     And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
235     And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
236     And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
237     And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
238     And I press "Save changes"
239     And I navigate to "View > User report" in the course gradebook
240     And I set the field "Select all or one user" to "Student 1"
241     Then the following should exist in the "user-grade" table:
242       | Grade item                   | Calculated weight       | Grade  | Range | Percentage | Contribution to course total |
243       | Test assignment one          | 83.33 %                 | 80.00  | 0–100 | 80.00 %    | 66.67 %                      |
244       | Test assignment two          | 0.00 %                  | 30.00  | 0–50  | 60.00 %    | 0.00 %                       |
245       | Test assignment three        | 0.00 %( Empty )         | -      | 0–200 | -          | 0.00 %                       |
246       | Test assignment four (extra) | 16.67 %( Extra credit ) | 10.00  | 0–20  | 50.00 %    | 8.33 %                       |
247       | Test assignment five (extra) | 0.00 %( Extra credit )  | 8.00   | 0–10  | 80.00 %    | 0.00 %                       |
248       | Course total                 | -                       | 112.50 | 0–150 | 75.00 %    | -                            |
249     # This is just ridiculous, the grades for "two" and "five" are 0 without any reason, and sum weight of normal items is not 100% again.
250     And I log out
252   @javascript
253   Scenario: Weights are overridden, including extra credit, student has none grades present except for extra credit (before the fix 20150619)
254     When I set the field "Override weight of Test assignment one" to "1"
255     And I set the field "Weight of Test assignment one" to "50"
256     And I set the field "Override weight of Test assignment four (extra)" to "1"
257     And I set the field "Weight of Test assignment four (extra)" to "10"
258     And I press "Save changes"
259     When I navigate to "View > Grader report" in the course gradebook
260     And I turn editing mode on
261     And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
262     And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
263     And I press "Save changes"
264     And I navigate to "View > User report" in the course gradebook
265     And I set the field "Select all or one user" to "Student 1"
266     Then the following should exist in the "user-grade" table:
267       | Grade item                   | Calculated weight      | Grade | Range | Percentage | Contribution to course total |
268       | Test assignment one          | 0.00 %( Empty )        | -     | 0–100 | -          | 0.00 %                       |
269       | Test assignment two          | 0.00 %( Empty )        | -     | 0–50  | -          | 0.00 %                       |
270       | Test assignment three        | 0.00 %( Empty )        | -     | 0–200 | -          | 0.00 %                       |
271       | Test assignment four (extra) | 0.00 %( Extra credit ) | 10.00 | 0–20  | 50.00 %    | 0.00 %                       |
272       | Test assignment five (extra) | 0.00 %( Extra credit ) | 8.00  | 0–10  | 80.00 %    | 0.00 %                       |
273       | Course total                 | -                      | 0.00  | 0–0   |            | -                            |
274     And I log out