Skip to content

Commit 7ad0204

Browse files
committed
Fix bug with castext within dropdown input, and add testcase for previous commit.
1 parent f294e8f commit 7ad0204

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

stack/input/dropdown/dropdown.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ public function adapt_to_model_answer($teacheranswer) {
256256
}
257257
if ($ddlvalues[$key]['correct']) {
258258
if (substr($display, 0, 9) === '["%root",') {
259-
$tmp = castext2_parser_utils::unpack_maxima_strings($display);
259+
$tmp = castext2_parser_utils::string_to_list($display, true);
260+
$tmp = castext2_parser_utils::unpack_maxima_strings($tmp);
260261
$holder = new castext2_placeholder_holder();
261262
$correctanswerdisplay[] = castext2_parser_utils::postprocess_parsed($tmp, null, $holder);
262263
} else {

tests/input_dropdown_test.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,4 +395,21 @@ public function test_decimals() {
395395
$expected = 'A correct answer is: <code>3,1415</code>';
396396
$this->assertEquals($expected, $el->get_teacher_answer_display(false, false));
397397
}
398+
399+
public function test_validate_student_response_castext() {
400+
$options = new stack_options();
401+
$ta = '[[1+x^2,false],[1-x^2,false],' .
402+
'["1+x^3",true,["%root","Hello world ",["smlt","\\({x^3}\\)"]]]]';
403+
$el = stack_input_factory::make('dropdown', 'ans1', $ta, $options, ['options' => '']);
404+
$el->adapt_to_model_answer($ta);
405+
$state = $el->validate_student_response(['ans1' => '2'], $options, '2', new stack_cas_security());
406+
$this->assertEquals(stack_input::SCORE, $state->status);
407+
408+
$ta = '[[1+x^2,true],[1-x^2,false],' .
409+
'["1+x^3",false,["%root","Hello world ",["smlt","\\({x^3}\\)"]]]]';
410+
$el = stack_input_factory::make('dropdown', 'ans1', $ta, $options, ['options' => '']);
411+
$el->adapt_to_model_answer($ta);
412+
$state = $el->validate_student_response(['ans1' => '2'], $options, '2', new stack_cas_security());
413+
$this->assertEquals(stack_input::SCORE, $state->status);
414+
}
398415
}

0 commit comments

Comments
 (0)