Skip to content

Commit 308b813

Browse files
committed
more updates for unit tests
1 parent d333806 commit 308b813

File tree

3 files changed

+95
-69
lines changed

3 files changed

+95
-69
lines changed

mod/assign/classes/external/revoke_attempt.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
class revoke_attempt extends external_api {
3232

3333
/**
34-
* Describes the parameters for submission_start.
34+
* Describes the parameters for revoke_attempt.
3535
*
3636
* @return external_function_parameters
37-
* @since Moodle 4.0
37+
* @since Moodle 4.5
3838
*/
3939
public static function execute_parameters(): external_function_parameters {
4040
return new external_function_parameters ([
@@ -45,11 +45,11 @@ public static function execute_parameters(): external_function_parameters {
4545
}
4646

4747
/**
48-
* Call to start an assignment submission.
48+
* Call to revoke an assignment attempt.
4949
*
5050
* @param int $assignid Assignment ID.
5151
* @return array
52-
* @since Moodle 4.0
52+
* @since Moodle 4.5
5353
*/
5454
public static function execute(int $assignid, int $userid): array {
5555
global $DB, $USER;
@@ -73,14 +73,14 @@ public static function execute(int $assignid, int $userid): array {
7373
}
7474

7575
/**
76-
* Describes the submission_start return value.
76+
* Describes the revoke attempt return value.
7777
*
7878
* @return external_single_structure
79-
* @since Moodle 4.0
79+
* @since Moodle 4.5
8080
*/
8181
public static function execute_returns(): external_single_structure {
8282
return new external_single_structure([
83-
'submissionid' => new external_value(PARAM_INT, 'New submission ID.'),
83+
'submissionid' => new external_value(PARAM_INT, 'Current submission ID.'),
8484
'warnings' => new external_warnings(),
8585
]);
8686
}

mod/assign/locallib.php

+1
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ public function view($action='', $args = array()) {
544544
$action = 'redirect';
545545
$nextpageparams['action'] = 'grading';
546546
} else if ($action == 'revokeattempt') {
547+
require_sesskey();
547548
$this->revoke_attempt(required_param('userid', PARAM_INT));
548549
$action = 'redirect';
549550
$nextpageparams['action'] = 'grading';

mod/assign/tests/revokeattempt_test.php

+87-62
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
global $CFG;
2424
require_once(__DIR__ . '/../locallib.php');
2525
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;
2631

2732
/**
2833
* Unit tests for revoking attempts in mod/assign/locallib.php.
@@ -37,75 +42,82 @@ class revokeattempt_test extends \advanced_testcase {
3742

3843
protected function revoke_attempt_dataprovider() {
3944
return [
40-
// Attempt single submission no additional grading, no feedback.
45+
// Attempt single submission no additional grading.
4146
'Single attempt' => [
4247
'type' => 'single',
43-
'grade' => false,
44-
'feedback' => false,
45-
'activitycompletion' => 'none'
48+
'firstgrade' => 45.0,
49+
'grade' => 0,
50+
'activitycompletion' => [],
51+
'result' => []
4652
],
47-
// Attempt single submission, additional grade, no feedback.
53+
// Attempt single submission, additional grade.
4854
'Single attempt with grade' => [
4955
'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' => []
6060
],
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.
6262
'Single attempt with past completed activity' => [
6363
'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']
6771
],
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.
6973
'Single attempt with future completed activity' => [
7074
'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']
7482
],
75-
// Group attempt, no additional grading, no feedback.
83+
// Activity completion requires submission, requires grade, requires passing grade.
84+
// Group attempt, no additional grading.
7685
'Group attempt' => [
7786
'type' => 'group',
78-
'grade' => false,
79-
'feedback' => false,
80-
'activitycompletion' => 'none'
87+
'firstgrade' => 45.0,
88+
'grade' => 0,
89+
'activitycompletion' => [],
90+
'result' => []
8191
],
82-
// Group attempt, additional grade, no feedback.
92+
// Group attempt, additional grade.
8393
'Group attempt with grade' => [
8494
'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' => []
9599
],
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.
97101
'Group attempt with past completed activity' => [
98102
'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']
102110
],
103-
// Group attempt, additional grade, no feedback, activity was not complete, now is.
111+
// Group attempt, additional grade, activity was not complete, now is.
104112
'Group attempt with future completed activity' => [
105113
'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']
109121
],
110122
];
111123
}
@@ -115,11 +127,11 @@ protected function revoke_attempt_dataprovider() {
115127
*
116128
* @dataProvider revoke_attempt_dataprovider
117129
*/
118-
public function test_revoke_attempt($type, $grade, $feedback, $activitycompletion) {
130+
public function test_revoke_attempt($type, $initialgrade, $grade, $activitycompletion, $result) {
119131
$this->resetAfterTest();
120132

121133
$generator = $this->getDataGenerator();
122-
$course = $generator->create_course();
134+
$course = $generator->create_course(['enablecompletion' => 1]);
123135
// user creation to be moved.
124136
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
125137
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
@@ -136,33 +148,46 @@ public function test_revoke_attempt($type, $grade, $feedback, $activitycompletio
136148
$data = [
137149
'assignfeedbackcomments_editor' => ['text' => $initialfeedback, 'format' => 1]
138150
];
139-
$this->mark_submission($teacher, $assign, $student, 45.0, $data);
151+
$this->mark_submission($teacher, $assign, $student, $initialgrade, $data);
140152

141153
$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);
153162
$gradeinfo = $assign->get_user_grade($student->id, true);
154-
$this->assertEquals(51.0, $gradeinfo->grade);
163+
$this->assertEquals($grade, $gradeinfo->grade);
155164
}
156165

157166
$assign->revoke_attempt($student->id);
167+
// submission
168+
$submission = $assign->get_user_submission($student->id, false);
169+
// print_object($submission->status);
158170
$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));
160179
}
161180

162181
protected function create_assignment($generator, $type, $course) {
163182
$data = [
183+
'maxattempts' => -1,
184+
'attemptreopenmethod' => 'manual',
164185
'assignsubmission_onlinetext_enabled' => 1,
165186
'assignfeedback_comments_enabled' => 1,
187+
'completion' => COMPLETION_TRACKING_AUTOMATIC,
188+
'completionsubmit' => COMPLETION_ENABLED,
189+
'completionpassgrade' => 1,
190+
'gradepass' => 50.0
166191
];
167192

168193
$assign = $this->create_instance($course, $data);

0 commit comments

Comments
 (0)