diff --git a/question/type/ddimageortext/edit_ddimageortext_form.php b/question/type/ddimageortext/edit_ddimageortext_form.php index 7d499e7f5b9..1c364f2305f 100644 --- a/question/type/ddimageortext/edit_ddimageortext_form.php +++ b/question/type/ddimageortext/edit_ddimageortext_form.php @@ -117,7 +117,7 @@ class qtype_ddimageortext_edit_form extends qtype_ddtoimage_edit_form_base { $mform->addElement('header', 'draggableitemheader', get_string('draggableitems', 'qtype_ddimageortext')); $mform->addElement('advcheckbox', 'shuffleanswers', get_string('shuffleimages', 'qtype_'.$this->qtype())); - $mform->setDefault('shuffleanswers', 0); + $mform->setDefault('shuffleanswers', $this->get_default_value('shuffleanswers', 0)); $this->repeat_elements($this->draggable_item($mform), $itemrepeatsatstart, $this->draggable_items_repeated_options(), 'noitems', 'additems', self::ADD_NUM_ITEMS, diff --git a/question/type/ddimageortext/questiontype.php b/question/type/ddimageortext/questiontype.php index 7be493fcf27..fa5e42c66ca 100644 --- a/question/type/ddimageortext/questiontype.php +++ b/question/type/ddimageortext/questiontype.php @@ -50,6 +50,11 @@ class qtype_ddimageortext extends qtype_ddtoimage_base { return question_hint_with_parts::load_from_record($hint); } + public function save_defaults_for_new_questions(stdClass $fromform): void { + parent::save_defaults_for_new_questions($fromform); + $this->set_default_value('shuffleanswers', $fromform->shuffleanswers); + } + public function save_question_options($formdata) { global $DB, $USER; $context = $formdata->context; diff --git a/question/type/ddimageortext/tests/behat/add.feature b/question/type/ddimageortext/tests/behat/add.feature index 46b95589735..423bc071e19 100644 --- a/question/type/ddimageortext/tests/behat/add.feature +++ b/question/type/ddimageortext/tests/behat/add.feature @@ -32,6 +32,7 @@ Feature: Test creating a drag and drop onto image question And I follow "Draggable items" And I press "Blanks for 3 more draggable items" + And I set the field "id_shuffleanswers" to "1" And I set the field "id_drags_0_dragitemtype" to "Draggable text" And I set the field "id_draglabel_0" to "island
arc" @@ -94,3 +95,10 @@ Feature: Test creating a drag and drop onto image question And I press "id_submitbutton" Then I should see "Drag and drop onto image 001" + # Checking that the next new question form displays user preferences settings. + When I press "Create a new question ..." + And I set the field "item_qtype_ddimageortext" to "1" + And I click on "Add" "button" in the "Choose a question type to add" "dialogue" + Then the following fields match these values: + | id_shuffleanswers | 1 | + diff --git a/question/type/ddmarker/edit_ddmarker_form.php b/question/type/ddmarker/edit_ddmarker_form.php index 15ff5864e7c..a30c81d87ef 100644 --- a/question/type/ddmarker/edit_ddmarker_form.php +++ b/question/type/ddmarker/edit_ddmarker_form.php @@ -45,6 +45,7 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base { protected function definition_inner($mform) { $mform->addElement('advcheckbox', 'showmisplaced', get_string('showmisplaced', 'qtype_ddmarker')); + $mform->setDefault('showmisplaced', $this->get_default_value('showmisplaced', 0)); parent::definition_inner($mform); $mform->addHelpButton('drops[0]', 'dropzones', 'qtype_ddmarker'); @@ -60,7 +61,7 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base { $mform->addElement('header', 'draggableitemheader', get_string('markers', 'qtype_ddmarker')); $mform->addElement('advcheckbox', 'shuffleanswers', get_string('shuffleimages', 'qtype_'.$this->qtype())); - $mform->setDefault('shuffleanswers', 0); + $mform->setDefault('shuffleanswers', $this->get_default_value('shuffleanswers', 0)); $this->repeat_elements($this->draggable_item($mform), $itemrepeatsatstart, $this->draggable_items_repeated_options(), 'noitems', 'additems', self::ADD_NUM_ITEMS, diff --git a/question/type/ddmarker/questiontype.php b/question/type/ddmarker/questiontype.php index e08bc588ea3..0cc8ff83dad 100644 --- a/question/type/ddmarker/questiontype.php +++ b/question/type/ddmarker/questiontype.php @@ -82,6 +82,12 @@ class question_hint_ddmarker extends question_hint_with_parts { */ class qtype_ddmarker extends qtype_ddtoimage_base { + public function save_defaults_for_new_questions(stdClass $fromform): void { + parent::save_defaults_for_new_questions($fromform); + $this->set_default_value('showmisplaced', $fromform->showmisplaced); + $this->set_default_value('shuffleanswers', $fromform->shuffleanswers); + } + public function save_question_options($formdata) { global $DB, $USER; $context = $formdata->context; diff --git a/question/type/ddmarker/tests/behat/add.feature b/question/type/ddmarker/tests/behat/add.feature index ec506c2d85b..6f86eeb9444 100644 --- a/question/type/ddmarker/tests/behat/add.feature +++ b/question/type/ddmarker/tests/behat/add.feature @@ -26,10 +26,12 @@ Feature: Test creating a drag and drop markers question And I set the field "Question name" to "Drag and drop markers" And I set the field "Question text" to "Please place the markers on the map of Milton Keynes and be aware that there is more than one railway station." And I set the field "General feedback" to "The Open University is at the junction of Brickhill Street and Groveway. There are three railway stations, Wolverton, Milton Keynes Central and Bletchley." + And I set the field "id_showmisplaced" to "1" And I upload "question/type/ddmarker/tests/fixtures/mkmap.png" file to "Background image" filemanager And I expand all fieldsets # Markers. + And I set the field "id_shuffleanswers" to "1" And I set the field "id_drags_0_label" to "OU" And I set the field "id_drags_0_noofdrags" to "1" And I set the field "id_drags_1_label" to "Railway station" @@ -56,3 +58,10 @@ Feature: Test creating a drag and drop markers question And I set the field "id_drops_3_choice" to "2" And I press "id_submitbutton" And I should see "Drag and drop markers" + # Checking that the next new question form displays user preferences settings. + When I press "Create a new question ..." + And I set the field "item_qtype_ddmarker" to "1" + And I click on "Add" "button" in the "Choose a question type to add" "dialogue" + Then the following fields match these values: + | id_showmisplaced | 1 | + | id_shuffleanswers | 1 | diff --git a/question/type/match/edit_match_form.php b/question/type/match/edit_match_form.php index 5ee734a8804..0618771e78f 100644 --- a/question/type/match/edit_match_form.php +++ b/question/type/match/edit_match_form.php @@ -60,7 +60,7 @@ class qtype_match_edit_form extends question_edit_form { $mform->addElement('advcheckbox', 'shuffleanswers', get_string('shuffle', 'qtype_match'), null, null, array(0, 1)); $mform->addHelpButton('shuffleanswers', 'shuffle', 'qtype_match'); - $mform->setDefault('shuffleanswers', 1); + $mform->setDefault('shuffleanswers', $this->get_default_value('shuffleanswers', 1)); $this->add_per_answer_fields($mform, get_string('questionno', 'question', '{no}'), 0); diff --git a/question/type/match/questiontype.php b/question/type/match/questiontype.php index 7e35d45ed92..3da218d170f 100644 --- a/question/type/match/questiontype.php +++ b/question/type/match/questiontype.php @@ -47,6 +47,11 @@ class qtype_match extends question_type { return true; } + public function save_defaults_for_new_questions(stdClass $fromform): void { + parent::save_defaults_for_new_questions($fromform); + $this->set_default_value('shuffleanswers', $fromform->shuffleanswers); + } + public function save_question_options($question) { global $DB; $context = $question->context; diff --git a/question/type/match/tests/behat/add.feature b/question/type/match/tests/behat/add.feature index 9e7a9f690d8..adb847a1598 100644 --- a/question/type/match/tests/behat/add.feature +++ b/question/type/match/tests/behat/add.feature @@ -18,11 +18,13 @@ Feature: Test creating a Matching question And I am on "Course 1" course homepage And I navigate to "Question bank" in current page administration + @javascript Scenario: Create a Matching question with 3 subquestions When I add a "Matching" question filling the form with: | Question name | match-001 | | Question text | Match the country with the capital city. | | General feedback | England=London, France=Paris and Spain=Madrid. | + | id_shuffleanswers | 0 | | id_subquestions_0 | England | | id_subanswers_0 | London | | id_subquestions_1 | France | @@ -35,3 +37,9 @@ Feature: Test creating a Matching question | Hint 1 | This is your first hint | | Hint 2 | This is your second hint | Then I should see "match-001" + # Checking that the next new question form displays user preferences settings. + When I press "Create a new question ..." + And I set the field "item_qtype_match" to "1" + And I click on "Add" "button" in the "Choose a question type to add" "dialogue" + Then the following fields match these values: + | id_shuffleanswers | 0 |