Skip to content

Commit

Permalink
Merge branch 'MDL-71225' of https://github.com/mkassaei/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Apr 19, 2021
2 parents 4478fcf + 42a4c30 commit ee6eccd
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion question/type/ddimageortext/edit_ddimageortext_form.php
Expand Up @@ -117,7 +117,7 @@ protected function definition_draggable_items($mform, $itemrepeatsatstart) {
$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,
Expand Down
5 changes: 5 additions & 0 deletions question/type/ddimageortext/questiontype.php
Expand Up @@ -50,6 +50,11 @@ protected function make_hint($hint) {
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;
Expand Down
8 changes: 8 additions & 0 deletions question/type/ddimageortext/tests/behat/add.feature
Expand Up @@ -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<br/>arc"

Expand Down Expand Up @@ -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 |

3 changes: 2 additions & 1 deletion question/type/ddmarker/edit_ddmarker_form.php
Expand Up @@ -45,6 +45,7 @@ public function qtype() {

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');
Expand All @@ -60,7 +61,7 @@ protected function definition_draggable_items($mform, $itemrepeatsatstart) {
$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,
Expand Down
6 changes: 6 additions & 0 deletions question/type/ddmarker/questiontype.php
Expand Up @@ -82,6 +82,12 @@ public function adjust_display_options(question_display_options $options) {
*/
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;
Expand Down
9 changes: 9 additions & 0 deletions question/type/ddmarker/tests/behat/add.feature
Expand Up @@ -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"
Expand All @@ -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 |
2 changes: 1 addition & 1 deletion question/type/match/edit_match_form.php
Expand Up @@ -60,7 +60,7 @@ protected function definition_inner($mform) {
$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);

Expand Down
5 changes: 5 additions & 0 deletions question/type/match/questiontype.php
Expand Up @@ -47,6 +47,11 @@ public function get_question_options($question) {
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;
Expand Down
8 changes: 8 additions & 0 deletions question/type/match/tests/behat/add.feature
Expand Up @@ -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 |
Expand All @@ -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 |

0 comments on commit ee6eccd

Please sign in to comment.