Skip to content

Commit

Permalink
Test: Ensure Results Don't Contain Negative Values
Browse files Browse the repository at this point in the history
  • Loading branch information
kergomard committed Dec 16, 2024
1 parent ff532d3 commit 68dcac9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
17 changes: 11 additions & 6 deletions components/ILIAS/Test/classes/class.ilObjTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7362,6 +7362,10 @@ public function updateTestResultCache(int $active_id, ilAssQuestionProcessLocker
[$active_id]
);

if ($reached < 0.0) {
$reached = 0.0;
}

$mark_short_name = $mark->getShortName();
if ($mark_short_name === '') {
$mark_short_name = ' ';
Expand Down Expand Up @@ -7425,7 +7429,8 @@ public function updateTestPassResults(
if ($result->numRows() > 0) {
$row = $this->db->fetchAssoc($result);

if ($row['reachedpoints'] === null) {
if ($row['reachedpoints'] === null
|| $row['reachedpoints'] < 0.0) {
$row['reachedpoints'] = 0.0;
}
if ($row['hint_count'] === null) {
Expand All @@ -7445,7 +7450,7 @@ public function updateTestPassResults(
'pass' => ['integer', $pass]
],
[
'points' => ['float', $row['reachedpoints'] ?: 0],
'points' => ['float', $row['reachedpoints']],
'maxpoints' => ['float', $data['points']],
'questioncount' => ['integer', $data['count']],
'answeredquestions' => ['integer', $row['answeredquestions']],
Expand All @@ -7470,10 +7475,10 @@ public function updateTestPassResults(
return [
'active_fi' => $active_id,
'pass' => $pass,
'points' => $row["reachedpoints"] ?? 0.0,
'maxpoints' => $data["points"],
'questioncount' => $data["count"],
'answeredquestions' => $row["answeredquestions"],
'points' => $row['reachedpoints'],
'maxpoints' => $data['points'],
'questioncount' => $data['count'],
'answeredquestions' => $row['answeredquestions'],
'workingtime' => $time,
'tstamp' => time(),
'hint_count' => $row['hint_count'],
Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/Test/src/Results/Data/AttemptOverview.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function getAsDescriptiveListing(
?->setTimezone($environment['timezone'])
->format($environment['datetimeformat']) ?? '',
$lng->txt('tst_nr_of_passes') => (string) $this->nr_of_attempts,
$lng->txt('scored_pass') => (string) $this->scored_attempt,
$lng->txt('scored_pass') => (string) ($this->scored_attempt + 1),
$lng->txt('tst_stat_result_rank_participant') => (string) $this->rank
]
);
Expand Down
5 changes: 5 additions & 0 deletions components/ILIAS/Test/src/Setup/Test9DBUpdateSteps.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,9 @@ public function step_19(): void
}
}

public function step_20(): void
{
$this->db->manipulate('UPDATE tst_pass_result SET points = 0 WHERE points < 0');
$this->db->manipulate('UPDATE tst_result_cache SET reached_points = 0 WHERE reached_points < 0');
}
}

0 comments on commit 68dcac9

Please sign in to comment.