23
23
global $ CFG ;
24
24
require_once (__DIR__ . '/../locallib.php ' );
25
25
require_once ($ CFG ->dirroot . '/mod/assign/tests/generator.php ' );
26
+ require_once ($ CFG ->libdir .'/completionlib.php ' );
27
+
28
+ use cm_info ;
29
+ use completion_info ;
30
+ use stdClass ;
26
31
27
32
/**
28
33
* Unit tests for revoking attempts in mod/assign/locallib.php.
@@ -37,75 +42,82 @@ class revokeattempt_test extends \advanced_testcase {
37
42
38
43
protected function revoke_attempt_dataprovider () {
39
44
return [
40
- // Attempt single submission no additional grading, no feedback .
45
+ // Attempt single submission no additional grading.
41
46
'Single attempt ' => [
42
47
'type ' => 'single ' ,
43
- 'grade ' => false ,
44
- 'feedback ' => false ,
45
- 'activitycompletion ' => 'none '
48
+ 'firstgrade ' => 45.0 ,
49
+ 'grade ' => 0 ,
50
+ 'activitycompletion ' => [],
51
+ 'result ' => []
46
52
],
47
- // Attempt single submission, additional grade, no feedback .
53
+ // Attempt single submission, additional grade.
48
54
'Single attempt with grade ' => [
49
55
'type ' => 'single ' ,
50
- 'grade ' => true ,
51
- 'feedback ' => false ,
52
- 'activitycompletion ' => 'none '
53
- ],
54
- // Attempt single submission, additional grade, feedback.
55
- 'Single attempt with grade and feedback ' => [
56
- 'type ' => 'single ' ,
57
- 'grade ' => true ,
58
- 'feedback ' => true ,
59
- 'activitycompletion ' => 'none '
56
+ 'firstgrade ' => 45.0 ,
57
+ 'grade ' => 51.0 ,
58
+ 'activitycompletion ' => [],
59
+ 'result ' => []
60
60
],
61
- // Attempt single submission no additional grading, no feedback, activity was complete, now is not.
61
+ // Attempt single submission no additional grading, activity was complete, now is not.
62
62
'Single attempt with past completed activity ' => [
63
63
'type ' => 'single ' ,
64
- 'grade ' => false ,
65
- 'feedback ' => false ,
66
- 'activitycompletion ' => 'past '
64
+ 'firstgrade ' => 54.0 ,
65
+ 'grade ' => 0 ,
66
+ 'activitycompletion ' => [
67
+ 'type ' => 'past ' ,
68
+ 'thing ' => ['requires_submission ' ]
69
+ ],
70
+ 'result ' => ['completion ' => 'incomplete ' ]
67
71
],
68
- // Attempt single submission, additional grade, no feedback, activity was not complete, now is.
72
+ // Attempt single submission, additional grade, activity was not complete, now is.
69
73
'Single attempt with future completed activity ' => [
70
74
'type ' => 'single ' ,
71
- 'grade ' => true ,
72
- 'feedback ' => false ,
73
- 'activitycompletion ' => 'future '
75
+ 'firstgrade ' => 45.0 ,
76
+ 'grade ' => 51.0 ,
77
+ 'activitycompletion ' => [
78
+ 'type ' => 'future ' ,
79
+ 'thing ' => ['requires_submission ' ]
80
+ ],
81
+ 'result ' => ['completion ' => 'complete ' ]
74
82
],
75
- // Group attempt, no additional grading, no feedback.
83
+ // Activity completion requires submission, requires grade, requires passing grade.
84
+ // Group attempt, no additional grading.
76
85
'Group attempt ' => [
77
86
'type ' => 'group ' ,
78
- 'grade ' => false ,
79
- 'feedback ' => false ,
80
- 'activitycompletion ' => 'none '
87
+ 'firstgrade ' => 45.0 ,
88
+ 'grade ' => 0 ,
89
+ 'activitycompletion ' => [],
90
+ 'result ' => []
81
91
],
82
- // Group attempt, additional grade, no feedback .
92
+ // Group attempt, additional grade.
83
93
'Group attempt with grade ' => [
84
94
'type ' => 'group ' ,
85
- 'grade ' => true ,
86
- 'feedback ' => false ,
87
- 'activitycompletion ' => 'none '
88
- ],
89
- // Group attempt, additional grade, feedback.
90
- 'Group attempt with grade and feedback ' => [
91
- 'type ' => 'group ' ,
92
- 'grade ' => true ,
93
- 'feedback ' => true ,
94
- 'activitycompletion ' => 'none '
95
+ 'firstgrade ' => 45.0 ,
96
+ 'grade ' => 51.0 ,
97
+ 'activitycompletion ' => [],
98
+ 'result ' => []
95
99
],
96
- // Group attempt, no additional grading, no feedback, activity was complete, now is not.
100
+ // Group attempt, no additional grading, activity was complete, now is not.
97
101
'Group attempt with past completed activity ' => [
98
102
'type ' => 'group ' ,
99
- 'grade ' => false ,
100
- 'feedback ' => false ,
101
- 'activitycompletion ' => 'past '
103
+ 'firstgrade ' => 54.0 ,
104
+ 'grade ' => 0 ,
105
+ 'activitycompletion ' => [
106
+ 'type ' => 'past ' ,
107
+ 'thing ' => ['requires_submission ' ]
108
+ ],
109
+ 'result ' => ['completion ' => 'incomplete ' ]
102
110
],
103
- // Group attempt, additional grade, no feedback, activity was not complete, now is.
111
+ // Group attempt, additional grade, activity was not complete, now is.
104
112
'Group attempt with future completed activity ' => [
105
113
'type ' => 'group ' ,
106
- 'grade ' => true ,
107
- 'feedback ' => false ,
108
- 'activitycompletion ' => 'future '
114
+ 'firstgrade ' => 45.0 ,
115
+ 'grade ' => 51.0 ,
116
+ 'activitycompletion ' => [
117
+ 'type ' => 'future ' ,
118
+ 'thing ' => ['requires_submission ' ]
119
+ ],
120
+ 'result ' => ['completion ' => 'complete ' ]
109
121
],
110
122
];
111
123
}
@@ -115,11 +127,11 @@ protected function revoke_attempt_dataprovider() {
115
127
*
116
128
* @dataProvider revoke_attempt_dataprovider
117
129
*/
118
- public function test_revoke_attempt ($ type , $ grade , $ feedback , $ activitycompletion ) {
130
+ public function test_revoke_attempt ($ type , $ initialgrade , $ grade , $ activitycompletion, $ result ) {
119
131
$ this ->resetAfterTest ();
120
132
121
133
$ generator = $ this ->getDataGenerator ();
122
- $ course = $ generator ->create_course ();
134
+ $ course = $ generator ->create_course ([ ' enablecompletion ' => 1 ] );
123
135
// user creation to be moved.
124
136
$ teacher = $ this ->getDataGenerator ()->create_and_enrol ($ course , 'teacher ' );
125
137
$ student = $ this ->getDataGenerator ()->create_and_enrol ($ course , 'student ' );
@@ -136,33 +148,46 @@ public function test_revoke_attempt($type, $grade, $feedback, $activitycompletio
136
148
$ data = [
137
149
'assignfeedbackcomments_editor ' => ['text ' => $ initialfeedback , 'format ' => 1 ]
138
150
];
139
- $ this ->mark_submission ($ teacher , $ assign , $ student , 45.0 , $ data );
151
+ $ this ->mark_submission ($ teacher , $ assign , $ student , $ initialgrade , $ data );
140
152
141
153
$ assign ->testable_process_add_attempt ($ student ->id );
142
- if ($ grade ) {
143
- if ($ feedback ) {
144
- $ data = [
145
- 'assignfeedbackcomments_editor ' => ['text ' => 'Feedback! ' , 'format ' => 1 ]
146
- ];
147
- } else {
148
- $ data = [
149
- 'assignfeedbackcomments_editor ' => ['text ' => '' , 'format ' => 1 ]
150
- ];
151
- }
152
- $ this ->mark_submission ($ teacher , $ assign , $ student , 51.0 , $ data , 1 );
154
+ $ submission = $ assign ->get_user_submission ($ student ->id , false );
155
+ $ this ->assertEquals (ASSIGN_SUBMISSION_STATUS_REOPENED , $ submission ->status );
156
+
157
+ if ($ grade != 0 ) {
158
+ $ data = [
159
+ 'assignfeedbackcomments_editor ' => ['text ' => 'Feedback! ' , 'format ' => 1 ]
160
+ ];
161
+ $ this ->mark_submission ($ teacher , $ assign , $ student , $ grade , $ data , 1 );
153
162
$ gradeinfo = $ assign ->get_user_grade ($ student ->id , true );
154
- $ this ->assertEquals (51.0 , $ gradeinfo ->grade );
163
+ $ this ->assertEquals ($ grade , $ gradeinfo ->grade );
155
164
}
156
165
157
166
$ assign ->revoke_attempt ($ student ->id );
167
+ // submission
168
+ $ submission = $ assign ->get_user_submission ($ student ->id , false );
169
+ // print_object($submission->status);
158
170
$ gradeinfo = $ assign ->get_user_grade ($ student ->id , true );
159
- $ this ->assertEquals (45.0 , $ gradeinfo ->grade );
171
+ $ this ->assertEquals ($ initialgrade , $ gradeinfo ->grade );
172
+
173
+ $ cm = cm_info::create ($ assign ->get_course_module ());
174
+ $ completioninfo = new completion_info ($ course );
175
+ // $customcompletion = new custom_completion($cm, (int)$student->id);
176
+ $ current = new stdClass ();
177
+ // Try internal_get_grade_state instead.
178
+ print_object ($ completioninfo ->get_grade_completion ($ cm , $ student ->id ));
160
179
}
161
180
162
181
protected function create_assignment ($ generator , $ type , $ course ) {
163
182
$ data = [
183
+ 'maxattempts ' => -1 ,
184
+ 'attemptreopenmethod ' => 'manual ' ,
164
185
'assignsubmission_onlinetext_enabled ' => 1 ,
165
186
'assignfeedback_comments_enabled ' => 1 ,
187
+ 'completion ' => COMPLETION_TRACKING_AUTOMATIC ,
188
+ 'completionsubmit ' => COMPLETION_ENABLED ,
189
+ 'completionpassgrade ' => 1 ,
190
+ 'gradepass ' => 50.0
166
191
];
167
192
168
193
$ assign = $ this ->create_instance ($ course , $ data );
0 commit comments