From 35e69b6ae85e095bec0757e29620fb9e7022cd08 Mon Sep 17 00:00:00 2001
From: Jun Pataleta <jun@moodle.com>
Date: Mon, 24 Apr 2023 20:07:57 +0800
Subject: [PATCH] MDL-77766 qtype_truefalse: Respect showstandardinstruction

* When showstandardinstruction is set to no, replace the standard
instruction with the generic "Answer" text for the answer options
fieldset's legend.
---
 question/type/truefalse/renderer.php               | 6 ++++--
 question/type/truefalse/tests/walkthrough_test.php | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/question/type/truefalse/renderer.php b/question/type/truefalse/renderer.php
index 201e606e0a0..3e8c42723f4 100644
--- a/question/type/truefalse/renderer.php
+++ b/question/type/truefalse/renderer.php
@@ -100,11 +100,13 @@ class qtype_truefalse_renderer extends qtype_renderer {
                 array('class' => 'qtext'));
 
         $result .= html_writer::start_tag('fieldset', array('class' => 'ablock'));
-        $legendclass = 'sr-only';
         if (!empty($question->showstandardinstruction)) {
             $legendclass = '';
+            $questionnumber = $options->add_question_identifier_to_label(get_string('selectone', 'qtype_truefalse'), true, true);
+        } else {
+            $legendclass = 'sr-only';
+            $questionnumber = $options->add_question_identifier_to_label(get_string('answer'), true, true);
         }
-        $questionnumber = $options->add_question_identifier_to_label(get_string('selectone', 'qtype_truefalse'), true, true);
         $result .= html_writer::tag('legend', $questionnumber,
             array('class' => 'prompt h6 font-weight-normal ' . $legendclass));
 
diff --git a/question/type/truefalse/tests/walkthrough_test.php b/question/type/truefalse/tests/walkthrough_test.php
index 07721a69fe0..94bb1166ccb 100644
--- a/question/type/truefalse/tests/walkthrough_test.php
+++ b/question/type/truefalse/tests/walkthrough_test.php
@@ -155,7 +155,7 @@ class walkthrough_test extends \qbehaviour_walkthrough_test_base {
         $this->render();
 
         // Check for 'Show standard instruction'.
-        $standardinstruction = \html_writer::tag('legend', get_string('selectone', 'qtype_truefalse'), [
+        $standardinstruction = \html_writer::tag('legend', get_string('answer'), [
             'class' => 'prompt h6 font-weight-normal sr-only'
         ]);
         $this->assertStringContainsString($standardinstruction, $this->currentoutput);