Skip to content

Commit ae4709b

Browse files
committed
broken-save - Behat tests
1 parent 13d4138 commit ae4709b

5 files changed

Lines changed: 87 additions & 2 deletions

File tree

edit_stack_form.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,8 @@ public function validation($fromform, $files) {
974974
return $allerrors;
975975
} else {
976976
if (array_search(stack_string('youmustconfirm'), $allerrors)) {
977-
$allerrors['versioninfo'] = stack_string('notsaved') . $allerrors['versioninfo'];
977+
$allerrors['versioninfo'] = isset($allerrors['versioninfo']) ?
978+
stack_string('notsaved') . ' ' . $allerrors['versioninfo'] : stack_string('notsaved');
978979
return $allerrors;
979980
} else {
980981
return $errors;

questiontype.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,7 @@ protected function validate_cas_string($errors, $value, $fieldname, $savesession
19571957
* @return array updated $errors array.
19581958
*/
19591959
protected function validate_cas_text($errors, $value, $fieldname, $fixingdollars, $session = null) {
1960-
if (!$fixingdollars && strpos($value, '$$') !== false) {
1960+
if (!$fixingdollars && $value && strpos($value, '$$') !== false) {
19611961
$errors[$fieldname][] = stack_string('forbiddendoubledollars');
19621962
}
19631963

stack/mathsoutput/fact_sheets.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public static function get_unrecognised_tags($text) {
6262
* @return array tags, if there are any. Empty array if none.
6363
*/
6464
protected static function get_fact_sheet_tags($text) {
65+
if (!$text) {
66+
return [];
67+
}
6568
if (preg_match_all('|\[\[facts:(\w*)\]\]|U', $text, $matches)) {
6669
return $matches[1];
6770
}

stack/utils.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,9 @@ public static function list_to_array($string, $rec = true) {
617617
* @return array of placeholdernames.
618618
*/
619619
public static function extract_placeholders($text, $type) {
620+
if (!$text) {
621+
return [];
622+
}
620623
preg_match_all('~\[\[' . $type . ':(' . self::VALID_NAME_REGEX . ')\]\]~',
621624
$text, $matches);
622625
return $matches[1];

tests/behat/create_preview_edit.feature

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,81 @@ Feature: Create, preview, test, tidy and edit STACK questions
348348
And I should see "Number of new variants successfully created, tested and deployed: 1."
349349
And I should see "Too many repeated existing question notes were generated."
350350
And I should see "A variant matching this Question note is already deployed."
351+
352+
@javascript
353+
Scenario: Saving broken questions
354+
When I am on the "Course 1" "core_question > course question bank" page logged in as "teacher"
355+
# Create a new question.
356+
And I add a "STACK" question filling the form with:
357+
| Question name | Test STACK question |
358+
| Question variables | p : (x-1)^3; |
359+
| Question text | Differentiate {@p@} with respect to \(x\). [[input:ans1]] [[validation:ans1]] |
360+
| Question description | This is a very simple test question. |
361+
| Model answer | diff(p,x) |
362+
| SAns | ans1 |
363+
| TAns | diff(p,x) |
364+
Then I should see "Test STACK question"
365+
366+
# Save a broken question.
367+
When I am on the "Test STACK question" "core_question > edit" page
368+
And I set the following fields to these values:
369+
| Question name | Broken question |
370+
| Model answer | |
371+
And I press "id_submitbutton"
372+
Then I should not see "Broken question"
373+
And I set the following fields to these values:
374+
| Save as broken | 1 |
375+
And I press "id_submitbutton"
376+
Then I should see "Broken question"
377+
378+
# Update a broken question
379+
When I am on the "Broken question" "core_question > edit" page
380+
And I set the following fields to these values:
381+
| Question name | Broken question updated |
382+
| Question text | [[input:ans1]] [[validation:ans1]] [[input:ans2]] [[validation:ans2]] |
383+
| Specific feedback | [[feedback:prt1]] [[feedback:prt2]] |
384+
And I press "id_submitbutton"
385+
Then I should see "Broken question updated"
386+
387+
# Remove an input from a broken question
388+
When I am on the "Broken question updated" "core_question > edit" page
389+
Then I should see "Potential response tree: prt2"
390+
And I should see "Input: ans2"
391+
And I set the following fields to these values:
392+
| Question name | Broken question update2 |
393+
| Question text | [[input:ans1]] [[validation:ans1]] |
394+
| Specific feedback | [[feedback:prt1]] [[feedback:prt2]] |
395+
And I press "id_submitbutton"
396+
Then I should see "QUESTION WAS NOT SAVED"
397+
And I click on "[id='id_ans2deleteconfirm']" "css_element"
398+
And I press "id_submitbutton"
399+
Then I should see "Broken question update2"
400+
401+
# Remove a PRT from a broken question
402+
When I am on the "Broken question update2" "core_question > edit" page
403+
Then I should see "Potential response tree: prt1"
404+
And I should see "Potential response tree: prt2"
405+
And I should see "Input: ans1"
406+
And I should not see "Input: ans2"
407+
And I set the following fields to these values:
408+
| Question name | Broken question update3 |
409+
| Question text | [[input:ans1]] [[validation:ans1]] |
410+
| Specific feedback | [[feedback:prt1]] |
411+
And I press "id_submitbutton"
412+
Then I should see "QUESTION WAS NOT SAVED"
413+
And I click on "[id='id_prt2prtdeleteconfirm']" "css_element"
414+
And I press "id_submitbutton"
415+
Then I should see "Broken question update3"
416+
417+
# Fix the question, then save normally
418+
When I am on the "Broken question update3" "core_question > edit" page
419+
Then I should see "Potential response tree: prt1"
420+
And I should not see "Potential response tree: prt2"
421+
And I should see "Input: ans1"
422+
And I should not see "Input: ans2"
423+
And I set the following fields to these values:
424+
| Question name | Fixed question |
425+
| Model answer | diff(p,x) |
426+
| Save as broken | 0 |
427+
And I press "id_submitbutton"
428+
Then I should see "Fixed question"

0 commit comments

Comments
 (0)