MDL-75874 aiken_html: correctly display HTML chars for Aiken questions

Updates the Aiken Format class to process answers correctly, enabling
support for special HTML characteres such as <, >, and &.

Co-authored-by: Leticia Luz <leticia.adrielli.luz@gmail.com>
This commit is contained in:
Matheus Rodrigues 2022-11-10 09:56:28 -03:00
parent 35f39c45b7
commit caf6b655e6
3 changed files with 18 additions and 5 deletions

View File

@ -86,8 +86,7 @@ class qformat_aiken extends qformat_default {
}
// A choice. Trim off the label and space, then save.
$question->answer[] = $this->text_field(
htmlspecialchars(trim(substr($nowline, 2)), ENT_NOQUOTES));
$question->answer[] = $this->text_field(substr($nowline, 2));
$question->fraction[] = 0;
$question->feedback[] = $this->text_field('');
} else if (preg_match('/^ANSWER:/', $nowline)) {

View File

@ -59,16 +59,19 @@ class aikenformat_test extends question_testcase {
$this->assertStringContainsString('Error importing question A question started but not finished', $output);
$this->assertStringContainsString('Question not completed before next question start on line 18', $output);
// There are two expected questions.
$this->assertCount(2, $questions);
// There are three expected questions.
$this->assertCount(3, $questions);
$q1 = null;
$q2 = null;
$q3 = null;
foreach ($questions as $question) {
if ($question->name === 'A good question') {
$q1 = $question;
} else if ($question->name === 'A second good question') {
$q2 = $question;
} else if ($question->name === 'A third good question with HTML chars such as > < &') {
$q3 = $question;
}
}
@ -83,5 +86,11 @@ class aikenformat_test extends question_testcase {
$this->assertEquals(1, $q2->fraction[1]);
$this->assertEquals('Incorrect (No space)', $q2->answer[0]['text']);
$this->assertEquals('Correct (No space)', $q2->answer[1]['text']);
// Check the third good question that has anwsers with special HTML chars such as <, >, and &.
$this->assertCount(2, $q3->answer);
$this->assertEquals(1, $q3->fraction[0]);
$this->assertEquals('Correct (&lt; &gt; &amp;)', $q3->answer[0]['text']);
$this->assertEquals('Incorrect (&lt; &gt; &amp;)', $q3->answer[1]['text']);
}
}

View File

@ -18,4 +18,9 @@ B) Incorrect-ish
A second good question
A)Incorrect (No space)
B)Correct (No space)
ANSWER: B
ANSWER: B
A third good question with HTML chars such as > < &
A) Correct (< > &)
B) Incorrect (< > &)
ANSWER: A