Show
This patch is fully covered by unit and behat tests including bad data scenario.
However, please feel free to do the following testing that covers bad pre-existing data case.
Manual testing in Moodle 4.0 and master (optional)
Create a course.
Create a quiz.
From the quiz page access question bank page.
Switch to Categories view.
For Default for Quiz parent category add two new categories: Category 1 and Category 2 .
Select from the database and note down category ids:
moodle=# SELECT id, name, parent FROM mdl_question_categories;
id | name | parent
----+------------------------+--------
1 | top | 0
2 | Default for Quiz 1 | 1
3 | top | 0
4 | Default for Course 1 | 3
5 | top | 0
6 | Default for Category 1 | 5
7 | top | 0
8 | Default for System | 7
9 | Category 1 | 2
10 | Category 2 | 2
( 10 rows)
On the question bank page switch to Import view.
Select Moodle XML format file format.
Choose Category 1 in the Import category field.
Upload kvaujjIouOFTOnnOVKMOgbHj.xml file.
Click Import and then Continue .
Run the following SQL and confirm , that all 3 questions are linked to Category 1 :
moodle=# SELECT q.id, q.parent, q.name, q.qtype, qbe.questioncategoryid, qc.name
FROM mdl_question q
JOIN mdl_question_versions qv ON qv.questionid = q.id
JOIN mdl_question_bank_entries qbe ON qbe.id = qv.questionbankentryid
LEFT JOIN mdl_question_categories qc ON qc.id = qbe.questioncategoryid;
id | parent | name | qtype | questioncategoryid | name
----+--------+-------------------------+-------------+--------------------+------------
1 | 0 | Embedded answer (Cloze) | multianswer | 9 | Category 1
2 | 1 | Embedded answer (Cloze) | multichoice | 9 | Category 1
3 | 1 | Embedded answer (Cloze) | multichoice | 9 | Category 1
( 3 rows)
Manually update child questions to belong to not existing category:
UPDATE mdl_question_bank_entries SET questioncategoryid = 123456789 WHERE id IN ( 2 , 3 );
Confirm , that child-questions belong to the category that doesn't exist anymore:
moodle=# SELECT q.id, q.parent, q.name, q.qtype, qbe.questioncategoryid, qc.name
FROM mdl_question q
JOIN mdl_question_versions qv ON qv.questionid = q.id
JOIN mdl_question_bank_entries qbe ON qbe.id = qv.questionbankentryid
LEFT JOIN mdl_question_categories qc ON qc.id = qbe.questioncategoryid;
id | parent | name | qtype | questioncategoryid | name
----+--------+-------------------------+-------------+--------------------+------------
1 | 0 | Embedded answer (Cloze) | multianswer | 9 | Category 1
2 | 1 | Embedded answer (Cloze) | multichoice | 123456789 |
3 | 1 | Embedded answer (Cloze) | multichoice | 123456789 |
( 3 rows)
On the question bank page switch to Categories view.
Click on the delete Category 1 category link.
Confirm , that The category 'Category 1' contains 1 questions message is displayed.
Choose Category 2 in the category dropdown menu and click Save in category .
Confirm , that no error is displayed.
Re-run the query and confirm , that parent question is now linked to Category 2 , while child questions are still linked to the category that doesn't exist anymore:
moodle=# SELECT q.id, q.parent, q.name, q.qtype, qbe.questioncategoryid, qc.name
FROM mdl_question q
JOIN mdl_question_versions qv ON qv.questionid = q.id
JOIN mdl_question_bank_entries qbe ON qbe.id = qv.questionbankentryid
LEFT JOIN mdl_question_categories qc ON qc.id = qbe.questioncategoryid;
id | parent | name | qtype | questioncategoryid | name
----+--------+-------------------------+-------------+--------------------+------------
1 | 0 | Embedded answer (Cloze) | multianswer | 10 | Category 2
2 | 1 | Embedded answer (Cloze) | multichoice | 123456789 |
3 | 1 | Embedded answer (Cloze) | multichoice | 123456789 |
( 3 rows)
Edit the quiz and add the question from question bank (from Category 2).
Enrol a student.
Log in as student and attempt the quiz.
Confirm , that there is no error during the quiz attempt and the question works as expected.