diff --git a/public/question/type/questionbase.php b/public/question/type/questionbase.php old mode 100644 new mode 100755 index 75c24e762c9..e255ea2e843 --- a/public/question/type/questionbase.php +++ b/public/question/type/questionbase.php @@ -459,14 +459,30 @@ abstract class question_definition { /** @return the result of applying {@link format_text()} to the question text. */ public function format_questiontext($qa) { - return html_writer::tag('div', $this->format_text($this->questiontext, $this->questiontextformat, - $qa, 'question', 'questiontext', $this->id), ['class' => 'clearfix']); + $formattext = $this->format_text( + $this->questiontext, + $this->questiontextformat, + $qa, + 'question', + 'questiontext', + $this->id + ); + + return html_writer::nonempty_tag('div', $formattext, ['class' => 'clearfix']); } /** @return the result of applying {@link format_text()} to the general feedback. */ public function format_generalfeedback($qa) { - return html_writer::tag('div', $this->format_text($this->generalfeedback, $this->generalfeedbackformat, - $qa, 'question', 'generalfeedback', $this->id), ['class' => 'clearfix']); + $formattext = $this->format_text( + $this->generalfeedback, + $this->generalfeedbackformat, + $qa, + 'question', + 'generalfeedback', + $this->id + ); + + return html_writer::nonempty_tag('div', $formattext, ['class' => 'clearfix']); } /** diff --git a/public/question/type/truefalse/tests/walkthrough_test.php b/public/question/type/truefalse/tests/walkthrough_test.php old mode 100644 new mode 100755 index 341fff1ef26..22a7e6ff586 --- a/public/question/type/truefalse/tests/walkthrough_test.php +++ b/public/question/type/truefalse/tests/walkthrough_test.php @@ -17,6 +17,7 @@ namespace qtype_truefalse; use question_state; +use question_display_options; defined('MOODLE_INTERNAL') || die(); @@ -160,4 +161,28 @@ final class walkthrough_test extends \qbehaviour_walkthrough_test_base { ]); $this->assertStringContainsString($standardinstruction, $this->currentoutput); } + + /** + * Tests that the general feedback box is not displayed when it is empty for a false answer. + * + * @covers ::format_generalfeedback + */ + public function test_false_right_does_not_show_empty_general_feedback_when_answer(): void { + $tf = \test_question_maker::make_question('truefalse', 'false'); + $this->start_attempt_at_question($tf, 'deferredfeedback', 1); + $this->process_submission(data: ['answer' => 0]); + $this->quba->finish_all_questions(); + $displayoptions = new question_display_options(); + $html = $this->quba->render_question(1, $displayoptions); + $pattern = "/
\s*
\s*{$tf->generalfeedback}\s*<\/div>\s*<\/div>/"; + $this->assertMatchesRegularExpression($pattern, $html); + + $tf->generalfeedback = ""; + $this->start_attempt_at_question($tf, 'deferredfeedback', 1); + $this->process_submission(data: ['answer' => 0]); + $this->quba->finish_all_questions(); + $html = $this->quba->render_question(1, $displayoptions); + $pattern = "/
\s*
<\/div>\s*<\/div>/"; + $this->assertDoesNotMatchRegularExpression($pattern, $html); + } } diff --git a/public/theme/boost/scss/moodle/question.scss b/public/theme/boost/scss/moodle/question.scss old mode 100644 new mode 100755 index efe70079ef4..b9582fd546f --- a/public/theme/boost/scss/moodle/question.scss +++ b/public/theme/boost/scss/moodle/question.scss @@ -259,20 +259,28 @@ body.path-question-type { } .que { - clear: left; text-align: left; margin: 0 auto 1.8em auto; + display: flex; + align-items: start; + gap: 1rem; + @include media-breakpoint-down(md) { + flex-direction: column; + } } .que .info { - float: left; + flex-shrink: 0; width: 7em; padding: 0.5em; - margin-bottom: 1.8em; background-color: $gray-100; border: 1px solid darken($gray-300, 7%); @include border-radius(2px); + + @include media-breakpoint-down(md) { + width: 100%; + } } .que h3.no { @@ -303,7 +311,11 @@ body.path-question-type { } .que .content { - margin: 0 0 0 8.5em; + flex-grow: 1; + + @include media-breakpoint-down(md) { + width: 100%; + } } .que .formulation, @@ -673,16 +685,6 @@ body.path-question-type .mform fieldset.hidden { position: relative; } -@include media-breakpoint-down(md) { - .que .info { - float: none; - width: auto; - } - .que .content { - margin: 0; - } -} - .qbank_managecategories-item.qbank_managecategories-droptarget-before, .qbank_managecategories-item .qbank_managecategories-item.qbank_managecategories-droptarget-before, .qbank_managecategories-categorylist.qbank_managecategories-droptarget-before > .qbank_managecategories-item:first-child { diff --git a/public/theme/boost/style/moodle.css b/public/theme/boost/style/moodle.css index d8617fc74c8..21c39a768ea 100644 --- a/public/theme/boost/style/moodle.css +++ b/public/theme/boost/style/moodle.css @@ -34029,20 +34029,31 @@ body.path-question-type .fitem .col-form-label.visually-hidden:not(legend):not([ } .que { - clear: left; text-align: left; margin: 0 auto 1.8em auto; + display: flex; + align-items: start; + gap: 1rem; +} +@media (max-width: 767.98px) { + .que { + flex-direction: column; + } } .que .info { - float: left; + flex-shrink: 0; width: 7em; padding: 0.5em; - margin-bottom: 1.8em; background-color: #f8f9fa; border: 1px solid #cad0d7; border-radius: 2px; } +@media (max-width: 767.98px) { + .que .info { + width: 100%; + } +} .que h3.no, .que .no.h3 { margin: 0; @@ -34072,7 +34083,12 @@ body.path-question-type .fitem .col-form-label.visually-hidden:not(legend):not([ } .que .content { - margin: 0 0 0 8.5em; + flex-grow: 1; +} +@media (max-width: 767.98px) { + .que .content { + width: 100%; + } } .que .formulation, @@ -34420,15 +34436,6 @@ body.path-question-type .mform fieldset.hidden { position: relative; } -@media (max-width: 767.98px) { - .que .info { - float: none; - width: auto; - } - .que .content { - margin: 0; - } -} .qbank_managecategories-item.qbank_managecategories-droptarget-before, .qbank_managecategories-item .qbank_managecategories-item.qbank_managecategories-droptarget-before, .qbank_managecategories-categorylist.qbank_managecategories-droptarget-before > .qbank_managecategories-item:first-child { diff --git a/public/theme/classic/style/moodle.css b/public/theme/classic/style/moodle.css index e3043205b03..40ea688d152 100644 --- a/public/theme/classic/style/moodle.css +++ b/public/theme/classic/style/moodle.css @@ -34029,20 +34029,31 @@ body.path-question-type .fitem .col-form-label.visually-hidden:not(legend):not([ } .que { - clear: left; text-align: left; margin: 0 auto 1.8em auto; + display: flex; + align-items: start; + gap: 1rem; +} +@media (max-width: 767.98px) { + .que { + flex-direction: column; + } } .que .info { - float: left; + flex-shrink: 0; width: 7em; padding: 0.5em; - margin-bottom: 1.8em; background-color: #f8f9fa; border: 1px solid #cad0d7; border-radius: 2px; } +@media (max-width: 767.98px) { + .que .info { + width: 100%; + } +} .que h3.no, .que .no.h3 { margin: 0; @@ -34072,7 +34083,12 @@ body.path-question-type .fitem .col-form-label.visually-hidden:not(legend):not([ } .que .content { - margin: 0 0 0 8.5em; + flex-grow: 1; +} +@media (max-width: 767.98px) { + .que .content { + width: 100%; + } } .que .formulation, @@ -34420,15 +34436,6 @@ body.path-question-type .mform fieldset.hidden { position: relative; } -@media (max-width: 767.98px) { - .que .info { - float: none; - width: auto; - } - .que .content { - margin: 0; - } -} .qbank_managecategories-item.qbank_managecategories-droptarget-before, .qbank_managecategories-item .qbank_managecategories-item.qbank_managecategories-droptarget-before, .qbank_managecategories-categorylist.qbank_managecategories-droptarget-before > .qbank_managecategories-item:first-child {