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 53f86eb commit 915530a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
6 changes: 6 additions & 0 deletions Modules/Test/classes/Setup/class.ilTest9DBUpdateSteps.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,10 @@ public function step_20(): void
{
$this->db->modifyTableColumn('ass_log', 'logtext', ['type' => \ilDBConstants::T_CLOB]);
}

public function step_21(): 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');
}
}
17 changes: 11 additions & 6 deletions Modules/Test/classes/class.ilObjTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8109,6 +8109,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 @@ -8205,7 +8209,8 @@ public function updateTestPassResults(

$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 @@ -8225,7 +8230,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 @@ -8251,10 +8256,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

0 comments on commit 915530a

Please sign in to comment.