diff --git a/lib/gradelib.php b/lib/gradelib.php index 38280108ecb..8b86b522d52 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -1625,9 +1625,9 @@ function grade_floats_equal($f1, $f2) { * * @param \stdClass $grade * @param \stdClass $user - * @return int + * @return int|null */ -function grade_get_date_for_user_grade(\stdClass $grade, \stdClass $user): int { +function grade_get_date_for_user_grade(\stdClass $grade, \stdClass $user): ?int { // The `datesubmitted` is the time that the grade was created. // The `dategraded` is the time that it was modified or overwritten. // If the grade was last modified by the user themselves use the date graded. diff --git a/lib/tests/gradelib_test.php b/lib/tests/gradelib_test.php index 8401916fd3c..a3e2b3d5667 100644 --- a/lib/tests/gradelib_test.php +++ b/lib/tests/gradelib_test.php @@ -160,7 +160,7 @@ class core_gradelib_testcase extends advanced_testcase { * @param stdClass $user * @param int $expected */ - public function test_grade_get_date_for_user_grade(stdClass $grade, stdClass $user, int $expected): void { + public function test_grade_get_date_for_user_grade(stdClass $grade, stdClass $user, ?int $expected): void { $this->assertEquals($expected, grade_get_date_for_user_grade($grade, $user)); } @@ -191,12 +191,23 @@ class core_gradelib_testcase extends advanced_testcase { 'datesubmitted' => 0, ]; + $g3 = (object) [ + 'usermodified' => $u1->id, + 'dategraded' => null, + 'datesubmitted' => $d2, + ]; + return [ 'If the user is the last person to have modified the grade_item then show the date that it was graded' => [ $g1, $u1, $d1, ], + 'If there is no grade and there is no feedback, then show graded date as null' => [ + $g3, + $u1, + null, + ], 'If the user is not the last person to have modified the grade_item, ' . 'and there is no submission date, then show the date that it was submitted' => [ $g1,