From a003b3b8828793313f307321e0fd521b2948e0ec Mon Sep 17 00:00:00 2001 From: Juan Segarra Montesinos Date: Tue, 7 Mar 2023 15:44:00 +0100 Subject: [PATCH] MDL-76257 core: Activity intro should honor user preference on creation --- course/modlib.php | 2 +- course/tests/behat/add_activities.feature | 40 +++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/course/modlib.php b/course/modlib.php index ee5490cba97..18370d2b78e 100644 --- a/course/modlib.php +++ b/course/modlib.php @@ -866,7 +866,7 @@ function prepare_new_moduleinfo_data($course, $modulename, $section) { if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) { $draftid_editor = file_get_submitted_draft_itemid('introeditor'); file_prepare_draft_area($draftid_editor, null, null, null, null, array('subdirs'=>true)); - $data->introeditor = array('text'=>'', 'format'=>FORMAT_HTML, 'itemid'=>$draftid_editor); // TODO: add better default + $data->introeditor = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftid_editor); } if (plugin_supports('mod', $data->modulename, FEATURE_ADVANCED_GRADING, false) diff --git a/course/tests/behat/add_activities.feature b/course/tests/behat/add_activities.feature index e979323a973..f2e726a3543 100644 --- a/course/tests/behat/add_activities.feature +++ b/course/tests/behat/add_activities.feature @@ -47,3 +47,43 @@ Feature: Add activities to courses And I add a "Database" to section "3" and I fill the form with: | Name | Test name | Then I should see "Required" + + @javascript + Scenario: The activity description should use the user's preferred editor on creation + Given the following "user preferences" exist: + | user | preference | value | + | admin | htmleditor | textarea | + And I am logged in as admin + And I am on "Course 1" course homepage with editing mode on + When I add a "Database" to section "3" + Then I should see "Moodle auto-format" in the "#menuintroeditorformat > option[selected]" "css_element" + + @javascript + Scenario: The activity description should preserve the format used once edited (markdown version) + Given the following "activities" exist: + | activity | name | intro | introformat | course | + | assign | A4 | Desc 4 | 4 | Course 1 | + And the following "user preferences" exist: + | user | preference | value | + | admin | htmleditor | textarea | + And I am logged in as admin + And I am on "Course 1" course homepage with editing mode on + And I open "A4" actions menu + When I click on "Edit settings" "link" in the "A4" activity + Then I should see "Markdown format" in the "#menuintroeditorformat > option[selected]" "css_element" + And I should not see "Plain text format" in the "#menuintroeditorformat > option[selected]" "css_element" + + @javascript + Scenario: The activity description should preserve the format used once edited (plain text version) + Given the following "activities" exist: + | activity | name | intro | introformat | course | + | assign | A2 | Desc 2 | 2 | Course 1 | + And the following "user preferences" exist: + | user | preference | value | + | admin | htmleditor | textarea | + And I am logged in as admin + And I am on "Course 1" course homepage with editing mode on + And I open "A2" actions menu + When I click on "Edit settings" "link" in the "A2" activity + Then I should see "Plain text format" in the "#menuintroeditorformat > option[selected]" "css_element" + And I should not see "Markdown format" in the "#menuintroeditorformat > option[selected]" "css_element"