Skip to content

Commit 55d8cea

Browse files
committed
CTP-3560 coursework tests review
1 parent 842cf5c commit 55d8cea

File tree

78 files changed

+593
-374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+593
-374
lines changed

classes/allocation/table/builder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* Represents the table that will show all students and all markers so that they can be matched up with one another for grading.
3939
* Various automatic strategies will be available for this, but the manual override happens here.
4040
*/
41+
#[\AllowDynamicProperties]
4142
class builder {
4243

4344
/**

classes/controllers/feedback_controller.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,19 @@ protected function show_feedback() {
7474

7575
$teacherfeedback = new feedback($this->params['feedbackid']);
7676

77-
$ability = new ability(user::find($USER), $this->coursework);
78-
$ability->require_can('show', $teacherfeedback);
77+
$user = user::find($USER);
78+
if ($user) {
79+
$ability = new ability($user, $this->coursework);
80+
$ability->require_can('show', $teacherfeedback);
7981

80-
$renderer = $this->get_page_renderer();
81-
$html = $renderer->show_feedback_page($teacherfeedback, $ajax);
82+
$renderer = $this->get_page_renderer();
83+
$html = $renderer->show_feedback_page($teacherfeedback, (bool)$ajax);
8284

83-
if (empty($ajax)) {
84-
echo $html;
85-
} else {
86-
echo json_encode(['success' => true, 'formhtml' => $html]);
85+
if (empty($ajax)) {
86+
echo $html;
87+
} else {
88+
echo json_encode(['success' => true, 'formhtml' => $html]);
89+
}
8790
}
8891
}
8992

classes/export/csv/cells/feedbackcomments_cell.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ class feedbackcomments_cell extends cell_base {
4040
*/
4141
public function get_cell($submission, $student, $stage_identifier) {
4242

43-
$stage_identifier = ($this->coursework->get_max_markers() == 1) ? "assessor_1" : $this->get_stage_identifier_for_assessor($submission, $student);
43+
$stage_identifier = ($this->coursework->get_max_markers() == 1)
44+
? "assessor_1" : $this->get_stage_identifier_for_assessor($submission, $student);
4445
$grade = $submission->get_assessor_feedback_by_stage($stage_identifier);
45-
return (!$grade) ? '' : strip_tags($grade->feedbackcomment);
46+
return (!$grade || !isset($grade->feedbackcomment)) ? '' : strip_tags($grade->feedbackcomment);
4647
}
4748

4849
/**

classes/framework/table_base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2121
*/
2222

23-
namespace mod_coursework\framework;;
23+
namespace mod_coursework\framework;
2424

2525
use moodle_database;
2626
use stdClass;

classes/grade_judge.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,14 @@ public function get_grade_capped_by_submission_time($submission) {
6565
}
6666

6767
/**
68-
* @param $grade
68+
* @param int|float $grade
6969
* @return float
7070
*/
7171
private function round_grade_decimals($grade) {
72+
if ($grade === '' || $grade === null) {
73+
// Avoid PHPUnit exception passing null or empty string to round().
74+
return null;
75+
}
7276
return round($grade, 2);
7377
}
7478

@@ -145,10 +149,10 @@ public function has_feedback_that_is_promoted_to_gradebook($submission) {
145149

146150
/**
147151
* @param submission $submission
148-
* @return int
152+
* @return int|null
149153
*/
150154
public function get_time_graded($submission) {
151-
return $this->get_feedback_that_is_promoted_to_gradebook($submission)->timemodified;
155+
return $this->get_feedback_that_is_promoted_to_gradebook($submission)->timemodified ?? null;
152156
}
153157

154158
/**

classes/models/allocation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* @property mixed allocatableid
3636
* @property mixed allocatabletype
3737
*/
38+
#[\AllowDynamicProperties]
3839
class allocation extends table_base {
3940

4041
/**

classes/models/assessment_set_membership.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* @package mod_coursework\models
3939
*
4040
*/
41+
#[\AllowDynamicProperties]
4142
class assessment_set_membership extends table_base implements moderatable {
4243

4344
/**

classes/models/coursework.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
* @property mixed startdate
8585
* @author administrator
8686
*/
87+
#[\AllowDynamicProperties]
8788
class coursework extends table_base {
8889

8990
/**
@@ -882,13 +883,10 @@ public function early_finalisation_allowed() {
882883
* @return void
883884
*/
884885
public function publish_grades() {
885-
886-
$submisisons = $this->get_submissions_to_publish();
887-
888-
foreach ($submisisons as $submisison) {
889-
$submisison->publish();
886+
$submissions = $this->get_submissions_to_publish();
887+
foreach ($submissions as $submission) {
888+
$submission->publish();
890889
}
891-
892890
}
893891

894892
/**

classes/models/deadline_extension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* @property mixed allocatableid
3737
* @package mod_coursework\models
3838
*/
39+
#[\AllowDynamicProperties]
3940
class deadline_extension extends table_base {
4041

4142
/**

classes/models/feedback.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* @property mixed stage_identifier
3939
* @property int feedback_manager
4040
*/
41+
#[\AllowDynamicProperties]
4142
class feedback extends table_base {
4243

4344
/**
@@ -475,7 +476,8 @@ public function get_submission() {
475476

476477
if (!isset($this->submission) && !empty($this->submissionid)) {
477478
global $DB;
478-
$coursework_id = $this->courseworkid ?? $DB->get_field(submission::$table_name, 'courseworkid', ['id' => $this->submissionid], MUST_EXIST);
479+
$coursework_id = $this->courseworkid
480+
?? $DB->get_field(submission::$table_name, 'courseworkid', ['id' => $this->submissionid], MUST_EXIST);
479481
if (!isset(submission::$pool[$coursework_id])) {
480482
submission::fill_pool_coursework($coursework_id);
481483
}
@@ -591,7 +593,7 @@ public static function fill_pool_coursework($coursework_id) {
591593
if (isset(self::$pool[$coursework_id])) {
592594
return;
593595
}
594-
if (submission::$pool[$coursework_id]) {
596+
if (submission::$pool[$coursework_id] ?? null) {
595597
$submission_ids = submission::$pool[$coursework_id]['id'];
596598
} else {
597599
$submission_ids = $DB->get_records(submission::$table_name, ['courseworkid' => $coursework_id], '', 'id');
@@ -650,7 +652,7 @@ public static function fill_pool_submissions($coursework_id, $submission_ids) {
650652
* @param $coursework_id
651653
* @param $key
652654
* @param $params
653-
* @return bool
655+
* @return self|bool
654656
*/
655657
public static function get_object($coursework_id, $key, $params) {
656658
if (!isset(self::$pool[$coursework_id])) {

0 commit comments

Comments
 (0)