Skip to content

Commit

Permalink
Test: Fix Variable Substitution In Formulas
Browse files Browse the repository at this point in the history
  • Loading branch information
kergomard committed Dec 13, 2023
1 parent 1b0c0f6 commit e764621
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public function substituteVariables(array $userdata, bool $graphicalOutput = fal
return false;
}

$text = $this->getQuestionForHTMLOutput();
$text = $this->getQuestion();

foreach ($this->fetchAllVariables($this->getQuestion()) as $varObj) {
if (isset($userdata[$varObj->getVariable()]) && strlen($userdata[$varObj->getVariable()])) {
Expand All @@ -277,6 +277,8 @@ public function substituteVariables(array $userdata, bool $graphicalOutput = fal
$text = preg_replace("/\\$" . substr($varObj->getVariable(), 1) . "(?![0-9]+)/", $val . " " . $unit . "\\1", $text);
}

$text = $this->purifyAndPrepareTextAreaOutput($text);

if (preg_match_all("/(\\\$r\\d+)/ims", $this->getQuestion(), $rmatches)) {
foreach ($rmatches[1] as $result) {
$resObj = $this->getResult($result);
Expand Down
11 changes: 8 additions & 3 deletions Modules/TestQuestionPool/classes/class.assQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -2966,13 +2966,18 @@ public function getQuestion(): string

public function getQuestionForHTMLOutput(): string
{
$question_text = $this->getHtmlQuestionContentPurifier()->purify($this->question);
return $this->purifyAndPrepareTextAreaOutput($this->question);
}

protected function purifyAndPrepareTextAreaOutput(string $content) : string
{
$purified_content = $this->getHtmlQuestionContentPurifier()->purify($content);
if ($this->isAdditionalContentEditingModePageObject()
|| !(new ilSetting('advanced_editing'))->get('advanced_editing_javascript_editor') === 'tinymce') {
$question_text = nl2br($question_text);
$purified_content = nl2br($purified_content);
}
return $this->prepareTextareaOutput(
$question_text,
$purified_content,
true,
true
);
Expand Down

0 comments on commit e764621

Please sign in to comment.