diff --git a/question/type/calculatedsimple/edit_calculatedsimple_form.php b/question/type/calculatedsimple/edit_calculatedsimple_form.php index 499f3de20f1..f1149298478 100644 --- a/question/type/calculatedsimple/edit_calculatedsimple_form.php +++ b/question/type/calculatedsimple/edit_calculatedsimple_form.php @@ -496,6 +496,11 @@ class qtype_calculatedsimple_edit_form extends qtype_calculated_edit_form { if ($k > 0 || $this->outsidelimit || !empty($this->numbererrors)) { $mform->addElement('float', "number[{$j}]", get_string( 'wildcard', 'qtype_calculatedsimple', $datasetdef->name)); + + // Forcing new generated sets of wildcard values into the question edit form, + // so they can be saved. + $mform->setConstant("number[{$j}]", $datasetdef->items[$i]->value); + $mform->setAdvanced("number[{$j}]", true); if (!empty($this->numbererrors['number['.$j.']'])) { $mform->addElement('static', "numbercomment[{$j}]", '', diff --git a/question/type/calculatedsimple/tests/behat/generate_wildcards.feature b/question/type/calculatedsimple/tests/behat/generate_wildcards.feature new file mode 100644 index 00000000000..0ef9791ebed --- /dev/null +++ b/question/type/calculatedsimple/tests/behat/generate_wildcards.feature @@ -0,0 +1,52 @@ +@qtype @qtype_calculatedsimple +Feature: Test creating sets of wildcard values + As a teacher + In order to be able to update my calculated simple questions + I need to be able to create and re-create sets of wildcard values + + Background: + Given the following "users" exist: + | username | + | teacher | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher | C1 | editingteacher | + And the following "question categories" exist: + | contextlevel | reference | name | + | Course | C1 | Test questions | + And the following "user preferences" exist: + | user | preference | value | + | teacher | htmleditor | textarea | + + Scenario: Add a calculated simple question and re-generate different wild card values + When I am on the "Course 1" "core_question > course question bank" page logged in as teacher + And I add a "Calculated simple" question filling the form with: + | Question name | calculatedsimple-001 | + | Question text | {x1} + {x2} | + | Answer 1 formula = | {x1} + {x2} | + | Grade | 100% | + And I should see "There must be at least one wild card" + And I press "id_analyzequestion" + And I should see "You must add at least one set of wild card(s) values before you can save this question." + # Creating one set of wild card values by default. + And I press "id_addbutton" + And I should see "Wild card(s) values" + # As the wild card values are random edit them to some known values. + And I set the following fields to these values: + | number[2] | 3.5 | + | number[1] | 5.3 | + And I press "id_updatedatasets" + # Save changes and continue editing. + And I press "id_updatebutton" + Then I should see "3.5 + 5.3 = 8.80" + And I should see "Correct answer : 8.80 inside limits of true value" + # Now generate a new set of wild card values. + And I press "id_addbutton" + # Save changes and continue editing. + And I press "id_updatebutton" + # Make sure the old values are no longer stored. + Then I should not see "3.5 + 5.3 = 8.80" + And I should not see "Correct answer : 8.80 inside limits of true value"