From ab828079afd356230a7a7dbb59eac4c02253251c Mon Sep 17 00:00:00 2001 From: Philipp Imhof <52650214+PhilippImhof@users.noreply.github.com> Date: Fri, 3 Jul 2026 14:59:09 +0200 Subject: [PATCH] fix missing feedback after manual regrade --- renderer.php | 9 ++++++++- tests/renderer_test.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/renderer.php b/renderer.php index 4f952d82..ee6a6f1b 100644 --- a/renderer.php +++ b/renderer.php @@ -867,13 +867,20 @@ public function part_correct_response($part) { /** * Check whether the last response of a question attempt is the same as the last submitted response, i. e. it * was either submitted (e. g. using the "Check" button) or it was saved during page navigation in a quiz but - * still contains the same answers as the ones from the last regular submission. + * still contains the same answers as the ones from the last regular submission. This is used to decide whether + * the feedback should be shown or not. * * @param question_attempt $qa * @param formulas_part|null $part * @return bool */ protected function response_is_same_as_submitted(question_attempt $qa, formulas_part|null $part = null): bool { + // If the question is marked as finished, we will return true here to make sure the feedback + // will be shown, because students will not be able to interact with the question anymore. + if ($qa->get_state()->is_finished()) { + return true; + } + // If the last step contains the behaviour var 'submit', it was itself a submitted response. // For the deferredfeedback behaviour, the step will contain 'finish' instead of 'submit'. $laststep = $qa->get_last_step(); diff --git a/tests/renderer_test.php b/tests/renderer_test.php index 5434e0bb..63ed7c16 100644 --- a/tests/renderer_test.php +++ b/tests/renderer_test.php @@ -121,6 +121,36 @@ public function test_show_response_with_backslash(): void { $this->check_output_contains_text_input('0_0', '\1', false); } + public function test_feedback_remains_visible_after_manual_regrading(): void { + $q = $this->get_test_formulas_question('testthreeparts'); + $this->start_attempt_at_question($q, 'deferredfeedback', 3); + + // Submit wrong answer. + $this->process_submission(['0_0' => '1', '1_0' => '6', '2_0' => '7']); + $this->finish(); + $this->render(); + $this->check_current_state(question_state::$gradedpartial); + $this->check_output_contains_lang_string('correctansweris', 'qtype_formulas', '5'); + $this->check_output_contains_lang_string('correctansweris', 'qtype_formulas', '6'); + $this->check_output_contains_lang_string('correctansweris', 'qtype_formulas', '7'); + $this->check_current_output( + $this->get_contains_num_parts_correct(2), + ); + + // Manually regrade the question and add a comment. + $this->quba->manual_grade(1, 'giving some bonus', 2.5, FORMAT_HTML); + + $this->render(); + $this->check_current_state(question_state::$mangrpartial); + $this->check_output_contains_lang_string('correctansweris', 'qtype_formulas', '5'); + $this->check_output_contains_lang_string('correctansweris', 'qtype_formulas', '6'); + $this->check_output_contains_lang_string('correctansweris', 'qtype_formulas', '7'); + $this->check_output_contains('giving some bonus'); + $this->check_current_output( + $this->get_contains_num_parts_correct(2), + ); + } + public function test_adaptive_grading_details_are_shown(): void { // Create a simple test question with no feedback strings at all. $q = $this->get_test_formulas_question('testsinglenum');