From aee466c0fcda56a78bffff004323d3fff05067c8 Mon Sep 17 00:00:00 2001 From: hieuvu Date: Thu, 15 Sep 2022 10:56:55 +0700 Subject: [PATCH] MDL-75744 gapselect: remove empty choices option. --- question/type/gapselect/edit_form_base.php | 14 ++------ .../type/gapselect/tests/behat/add.feature | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/question/type/gapselect/edit_form_base.php b/question/type/gapselect/edit_form_base.php index a539866a3e4..31f29ae7a42 100644 --- a/question/type/gapselect/edit_form_base.php +++ b/question/type/gapselect/edit_form_base.php @@ -142,18 +142,10 @@ class qtype_gapselect_edit_form_base extends question_edit_form { $textboxgroup[] = $mform->createElement('group', 'choices', get_string('choicex', 'qtype_gapselect'), $this->choice_group($mform)); - if (isset($this->question->options)) { - $countanswers = count($this->question->options->answers); + if (!empty($this->question->options->answers)) { + $repeatsatstart = count($this->question->options->answers); } else { - $countanswers = 0; - } - - if ($this->question->formoptions->repeatelements) { - $defaultstartnumbers = QUESTION_NUMANS_START * 2; - $repeatsatstart = max($defaultstartnumbers, QUESTION_NUMANS_START, - $countanswers + QUESTION_NUMANS_ADD); - } else { - $repeatsatstart = $countanswers; + $repeatsatstart = QUESTION_NUMANS_ADD * 2; } $repeatedoptions = $this->repeated_options(); diff --git a/question/type/gapselect/tests/behat/add.feature b/question/type/gapselect/tests/behat/add.feature index 95fa34ac554..94f8c374470 100644 --- a/question/type/gapselect/tests/behat/add.feature +++ b/question/type/gapselect/tests/behat/add.feature @@ -37,3 +37,35 @@ Feature: Test creating a Select missing words question And I click on "Add" "button" in the "Choose a question type to add" "dialogue" And the following fields match these values: | id_shuffleanswers | 1 | + + @javascript + Scenario: Edit a Select missing words question with 2 choice and should not have empty choice. + Given I am on the "Course 1" "core_question > course question bank" page logged in as teacher + And I add a "Select missing words" question filling the form with: + | Question name | Select missing words 002 | + | Question text | The [[1]] [[2]] on the mat. | + | General feedback | The cat sat on the mat. | + | id_shuffleanswers | 1 | + | id_choices_0_answer | cat | + | id_choices_1_answer | sat | + | id_choices_2_answer | dog | + | id_choices_2_choicegroup | 2 | + | id_choices_3_answer | stand | + | id_choices_3_choicegroup | 2 | + | Hint 1 | First hint | + | Hint 2 | Second hint | + When I choose "Edit question" action for "Select missing words 002" in the question bank + And the following fields match these values: + | Question name | Select missing words 002 | + | Question text | The [[1]] [[2]] on the mat. | + | General feedback | The cat sat on the mat. | + | id_shuffleanswers | 1 | + | id_choices_0_answer | cat | + | id_choices_1_answer | sat | + | id_choices_2_answer | dog | + | id_choices_2_choicegroup | 2 | + | id_choices_3_answer | stand | + | id_choices_3_choicegroup | 2 | + | Hint 1 | First hint | + | Hint 2 | Second hint | + Then I should not see "Choice [[5]]"