MDL-66971 core: Update the convenience date grade getter to allow nulls

This commit is contained in:
Peter 2019-10-22 09:38:05 +08:00
parent aaff6692a1
commit 0320040469
2 changed files with 14 additions and 3 deletions

View File

@ -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.

View File

@ -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,