From 67c67c576618358f54403c10647b41030753b3ae Mon Sep 17 00:00:00 2001 From: Maximilian Haye Date: Wed, 13 Nov 2024 16:04:48 +0100 Subject: [PATCH] wip: write a test for the thing --- tests/question_ui_renderer_test.php | 48 +++++++++++++++++++++++++++ tests/question_uis/input-values.xhtml | 36 ++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 tests/question_uis/input-values.xhtml diff --git a/tests/question_ui_renderer_test.php b/tests/question_ui_renderer_test.php index 77e3cddc..1a6f0d4d 100644 --- a/tests/question_ui_renderer_test.php +++ b/tests/question_ui_renderer_test.php @@ -378,6 +378,54 @@ public function test_should_replace_qpy_urls(): void { // phpcs:enable moodle.Files.LineLength.MaxExceeded } + /** + * Tests the replacement of QPy-URIs. + * + * @return void + * @throws coding_exception + * @covers \qtype_questionpy\question_ui_renderer::replace_qpy_urls + */ + public function test_should_correctly_fill_data(): void { + $input = file_get_contents(__DIR__ . "/question_uis/input-values.xhtml"); + $qa = $this->create_question_attempt_stub("deadbeef"); + $qa->method("get_last_qt_var") + ->willReturnMap([ + ["my_text", "new"], + ["my_checkbox", "value"], + ["my_radio", "value1"], + ["my_select", "value3"], + ["my_hidden", "new"], + ["my_submit", "should be ignored"] + ]); + + $ui = new question_ui_renderer($input, [], new \question_display_options(), $qa); + $result = $ui->render(); + + // phpcs:disable moodle.Files.LineLength.MaxExceeded + $this->assert_html_string_equals_html_string(<< + + + + + + + + + + + + + + + EXPECTED, $result); + // phpcs:enable moodle.Files.LineLength.MaxExceeded + } + /** * Creates a stub question attempt which should fulfill the needs of most tests. * diff --git a/tests/question_uis/input-values.xhtml b/tests/question_uis/input-values.xhtml new file mode 100644 index 00000000..49795e3b --- /dev/null +++ b/tests/question_uis/input-values.xhtml @@ -0,0 +1,36 @@ + + +
+ + + + + + + + + + + + + +