I am probably wrong here, but I cannot for the life of my see anything wrong in the code that is different from the way I think it works - namely, that by default questions are put in the course category, unless you have actually selected the quiz category. The key bits are:
- https://github.com/moodle/moodle/blob/master/lib/questionlib.php#L1013 - note that it prefers course context to quiz context.
- https://github.com/moodle/moodle/blob/master/mod/quiz/edit.php#L57 - confirmation that the quiz uses that standard function, rather than doing anything weird.
Emma, can you give really simple and clear steps to reproduce what you say happens: that the quiz creates questions in the Quiz context. E.g. your instructions could start "Go to https://qa.moodle.net/ then ...". Thanks.