From 0320040469161449c8e1b63953fcf5abafa62ced Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 22 Oct 2019 09:38:05 +0800 Subject: [PATCH] MDL-66971 core: Update the convenience date grade getter to allow nulls --- lib/gradelib.php | 4 ++-- lib/tests/gradelib_test.php | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) 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,