Merge branch 'MDL-73874-311' of https://github.com/BruceGoodGuy/moodle into MOODLE_311_STABLE
This commit is contained in:
@@ -53,4 +53,17 @@ class qtype_ddwtos_edit_form extends qtype_gapselect_edit_form_base {
|
||||
array('size' => 1, 'class' => 'tweakcss'));
|
||||
return $grouparray;
|
||||
}
|
||||
|
||||
protected function extra_slot_validation(array $slots, array $choices): ?string {
|
||||
foreach ($slots as $slot) {
|
||||
if (count(array_keys($slots, $slot)) > 1) {
|
||||
$choice = $choices[$slot - 1];
|
||||
if (!isset($choice['infinite']) || $choice['infinite'] != 1) {
|
||||
return get_string('errorlimitedchoice', 'qtype_ddwtos',
|
||||
html_writer::tag('b', $slot));
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ $string['addmorechoiceblanks'] = 'Blanks for {no} more choices';
|
||||
$string['answer'] = 'Answer';
|
||||
$string['blank'] = 'blank';
|
||||
$string['correctansweris'] = 'The correct answer is: {$a}';
|
||||
$string['errorlimitedchoice'] = 'Choice [[{$a}]] has been used more than once without being set to "Unlimited". Please recheck this question.';
|
||||
$string['infinite'] = 'Unlimited';
|
||||
$string['pleaseputananswerineachbox'] = 'Please put an answer in each box.';
|
||||
$string['pluginname'] = 'Drag and drop into text';
|
||||
|
||||
@@ -39,3 +39,20 @@ Feature: Test creating a drag and drop into text question
|
||||
And the following fields match these values:
|
||||
| id_shuffleanswers | 1 |
|
||||
| Penalty for each incorrect try | 20% |
|
||||
|
||||
Scenario: Cannot create a drag and drop into text question when making the unsolvable questions
|
||||
When I am on the "Course 1" "core_question > course question bank" page logged in as teacher
|
||||
And I add a "Drag and drop into text" question filling the form with:
|
||||
| Question name | Drag and drop into text 001 |
|
||||
| Question text | The [[1]] [[2]] on the [[1]]. |
|
||||
| General feedback | The cat sat on the cat. |
|
||||
| id_shuffleanswers | 1 |
|
||||
| id_choices_0_answer | cat |
|
||||
| id_choices_1_answer | goes through |
|
||||
| id_choices_2_answer | mat |
|
||||
| id_choices_3_answer | dog |
|
||||
| id_choices_4_answer | table |
|
||||
| Penalty for each incorrect try | 20% |
|
||||
| Hint 1 | First hint |
|
||||
| Hint 2 | Second hint |
|
||||
Then I should see "Choice [[1]] has been used more than once without being set to \"Unlimited\". Please recheck this question."
|
||||
|
||||
@@ -31,3 +31,14 @@ Feature: Test editing a drag and drop into text questions
|
||||
| Question name | Edited question name |
|
||||
And I press "id_submitbutton"
|
||||
Then I should see "Edited question name"
|
||||
|
||||
Scenario: Cannot update a drag and drop into text question to the unsolvable questions
|
||||
When I am on the "Drag to text" "core_question > edit" page logged in as teacher
|
||||
And I should see "Choice [[1]]"
|
||||
And I should see "Choice [[2]]"
|
||||
And I should see "Choice [[3]]"
|
||||
And I set the following fields to these values:
|
||||
| Question name | Edited question name |
|
||||
| Question text | Choice [[1]] Choice [[2]] Choice [[1]] |
|
||||
And I press "id_submitbutton"
|
||||
Then I should see "Choice [[1]] has been used more than once without being set to \"Unlimited\". Please recheck this question."
|
||||
|
||||
@@ -281,7 +281,6 @@ class qtype_gapselect_edit_form_base extends question_edit_form {
|
||||
}
|
||||
$slots = $cleanedslots;
|
||||
|
||||
$found = false;
|
||||
foreach ($slots as $slot) {
|
||||
$found = false;
|
||||
foreach ($choices as $key => $choice) {
|
||||
@@ -299,10 +298,21 @@ class qtype_gapselect_edit_form_base extends question_edit_form {
|
||||
html_writer::tag('b', $slot));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return $this->extra_slot_validation($slots, $choices) ?? false;
|
||||
}
|
||||
|
||||
public function qtype() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds more errors in question slots.
|
||||
*
|
||||
* @param array $slots The question text
|
||||
* @param array $choices Question choices
|
||||
* @return string|null Error message or false if no errors
|
||||
*/
|
||||
protected function extra_slot_validation(array $slots, array $choices): ?string {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user