From c90c9b04f6623b035e726a37e9b778d86d3f8097 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 7 Mar 2023 15:56:26 +0100 Subject: [PATCH] MDL-77550 lesson: Format decimals in feedback page --- mod/lesson/pagetypes/numerical.php | 15 +++++++++++++++ .../lesson_numerical_question_with_locale.feature | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/mod/lesson/pagetypes/numerical.php b/mod/lesson/pagetypes/numerical.php index 9a6f20f7017..a697cc5a9c5 100644 --- a/mod/lesson/pagetypes/numerical.php +++ b/mod/lesson/pagetypes/numerical.php @@ -347,6 +347,21 @@ class lesson_page_type_numerical extends lesson_page { return $data; } + + /** + * Custom formats the answer to display + * + * @param string $answer + * @param context $context + * @param int $answerformat + * @param array $options Optional param for additional options. + * @return string Returns formatted string + */ + public function format_answer($answer, $context, $answerformat, $options = []) { + $answer = helper::lesson_format_numeric_value($answer); + + return parent::format_answer($answer, $context, $answerformat, $options); + } } class lesson_add_page_form_numerical extends lesson_add_page_form_base { diff --git a/mod/lesson/tests/behat/lesson_numerical_question_with_locale.feature b/mod/lesson/tests/behat/lesson_numerical_question_with_locale.feature index aa18fc5b38f..1be05ec5fab 100644 --- a/mod/lesson/tests/behat/lesson_numerical_question_with_locale.feature +++ b/mod/lesson/tests/behat/lesson_numerical_question_with_locale.feature @@ -57,6 +57,7 @@ Feature: In a lesson activity, I need to edit pages in the lesson taking into ac | Your answer | 2#87 | And I press "Submit" Then I should see "Correct answer" + And I should see "2#87" And I should not see "Incorrect answer" And I press "Continue" And I should see "Congratulations - end of lesson reached" @@ -69,6 +70,7 @@ Feature: In a lesson activity, I need to edit pages in the lesson taking into ac | Your answer | 2#7 | And I press "Submit" Then I should not see "Correct answer" + And I should see "2#7" And I should see "Incorrect answer" And I press "Continue" And I should see "Congratulations - end of lesson reached" @@ -81,6 +83,7 @@ Feature: In a lesson activity, I need to edit pages in the lesson taking into ac | Your answer | 2#87 | And I press "Submit" Then I should see "Correct answer" + And I should see "2#87" And I should not see "Incorrect answer" And I press "Continue" And I should see "Congratulations - end of lesson reached" @@ -106,6 +109,7 @@ Feature: In a lesson activity, I need to edit pages in the lesson taking into ac | Your answer | 2,7 | And I press "Submit" And I should see "Incorrect answer" + And I should see "2,7" And I should not see "Correct answer" And I press "Continue" And I should see "Congratulations - end of lesson reached"