From 7499e96a33a67d855138b8b48b7b5097320cca05 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Wed, 31 May 2023 09:39:06 +0200 Subject: [PATCH] MDL-78378 survey: Display default introduction when description is empty This is a regression when the activity pages were redessigned in Moodle 4.0. The default introduction should be displayed when the activity description is empty. --- .../tests/behat/survey_description.feature | 30 +++++++++++++++++++ mod/survey/view.php | 12 ++++---- 2 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 mod/survey/tests/behat/survey_description.feature diff --git a/mod/survey/tests/behat/survey_description.feature b/mod/survey/tests/behat/survey_description.feature new file mode 100644 index 00000000000..1d2ad8daaad --- /dev/null +++ b/mod/survey/tests/behat/survey_description.feature @@ -0,0 +1,30 @@ +@mod @mod_survey +Feature: The default introduction is displayed when the activity description is empty + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | format | + | Course 1 | C1 | topics | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + And the following "activities" exist: + | activity | name | course | idnumber | template | + | survey | Test survey name | C1 | survey1 | 1 | + + Scenario: Display the default survey introduction when activity description is empty + Given I am on the "Test survey name" "survey activity" page logged in as "teacher1" + And I should see "Test survey 1" + When I am on the "Test survey name" "survey activity editing" page + And I set the following fields to these values: + | Description | | + And I press "Save and display" + Then I should see "The purpose of this survey is to help us understand" + And I am on the "Test survey name" "survey activity editing" page + And I set the following fields to these values: + | Survey type | ATTLS (20 item version) | + And I press "Save and display" + And I should see "The purpose of this questionnaire is to help us evaluate" diff --git a/mod/survey/view.php b/mod/survey/view.php index bb16507ac42..078530887b8 100644 --- a/mod/survey/view.php +++ b/mod/survey/view.php @@ -46,11 +46,6 @@ require_capability('mod/survey:participate', $context); if (! $survey = $DB->get_record("survey", array("id" => $cm->instance))) { throw new \moodle_exception('invalidsurveyid', 'survey'); } -$trimmedintro = trim($survey->intro); -if (empty($trimmedintro)) { - $tempo = $DB->get_field("survey", "intro", array("id" => $survey->template)); - $survey->intro = get_string($tempo, "survey"); -} if (! $template = $DB->get_record("survey", array("id" => $survey->template))) { throw new \moodle_exception('invalidtmptid', 'survey'); @@ -73,6 +68,13 @@ $PAGE->set_heading($course->fullname); // No need to show the description if the survey is done and a graph page is to be shown. if ($surveyalreadydone && $showscales) { $PAGE->activityheader->set_description(''); +} else { + // If the survey has empty description, display the default one. + $trimmedintro = trim($survey->intro); + if (empty($trimmedintro)) { + $tempo = $DB->get_field("survey", "intro", array("id" => $survey->template)); + $PAGE->activityheader->set_description(get_string($tempo, "survey")); + } } $PAGE->add_body_class('limitedwidth');