MDL-85556 questions: Fix repeated_restore unit test
This unit test is meant to test restoring duplicated questions that exist in a shared question bank. However, due to improvements in the restore process from the introduction of mod_qbank, having the questions in a bank that is not in the restored course means the questions don't get restored at all, and we can't test that the process is working. This changes the test to use a bank in the target course instead.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
issueNumber: MDL-85556
|
||||
notes:
|
||||
core_question:
|
||||
- message: >
|
||||
The unit test repeated\_restore\_test::test\_restore\_course\_with\_same\_stamp\_questions was passing incorrectly on 5.x for question types that use answers.
|
||||
|
||||
Maintainers of third-party question types may want to re-run the test with the fix in place, or if they have copied parts of this test as the basis of a test in their own plugin, review the changes and see if they should be reflected in their own test.
|
||||
type: fixed
|
||||
@@ -516,16 +516,14 @@ final class repeated_restore_test extends advanced_testcase {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create three courses and a user with editing teacher capabilities.
|
||||
// Create two courses and a user with editing teacher capabilities.
|
||||
$generator = $this->getDataGenerator();
|
||||
$course1 = $generator->create_course();
|
||||
$course2 = $generator->create_course();
|
||||
$course3 = $generator->create_course();
|
||||
$qbank = $generator->get_plugin_generator('mod_qbank')->create_instance(['course' => $course3->id]);
|
||||
$qbank = $generator->get_plugin_generator('mod_qbank')->create_instance(['course' => $course2->id]);
|
||||
$teacher = $USER;
|
||||
$generator->enrol_user($teacher->id, $course1->id, 'editingteacher');
|
||||
$generator->enrol_user($teacher->id, $course2->id, 'editingteacher');
|
||||
$generator->enrol_user($teacher->id, $course3->id, 'editingteacher');
|
||||
|
||||
$context = \context_module::instance($qbank->cmid);
|
||||
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
||||
@@ -557,6 +555,13 @@ final class repeated_restore_test extends advanced_testcase {
|
||||
$DB->update_record('question_answers', $answer);
|
||||
}
|
||||
|
||||
$course1q1structure = \mod_quiz\question\bank\qbank_helper::get_question_structure(
|
||||
$quiz1->id, \context_module::instance($quiz1->cmid));
|
||||
$this->assertEquals($question1->id, $course1q1structure[1]->questionid);
|
||||
$course1q2structure = \mod_quiz\question\bank\qbank_helper::get_question_structure(
|
||||
$quiz2->id, \context_module::instance($quiz2->cmid));
|
||||
$this->assertEquals($question2->id, $course1q2structure[1]->questionid);
|
||||
|
||||
// Backup course1.
|
||||
$bc = new backup_controller(backup::TYPE_1COURSE, $course1->id, backup::FORMAT_MOODLE,
|
||||
backup::INTERACTIVE_NO, backup::MODE_IMPORT, $teacher->id);
|
||||
@@ -573,19 +578,21 @@ final class repeated_restore_test extends advanced_testcase {
|
||||
|
||||
// Verify that the newly-restored course's quizzes use the same questions as their counterparts of course1.
|
||||
$modules = get_fast_modinfo($course2->id)->get_instances_of('quiz');
|
||||
$course1structure = \mod_quiz\question\bank\qbank_helper::get_question_structure(
|
||||
$course1q1structure = \mod_quiz\question\bank\qbank_helper::get_question_structure(
|
||||
$quiz1->id, \context_module::instance($quiz1->cmid));
|
||||
$course2quiz1 = array_shift($modules);
|
||||
$course2structure = \mod_quiz\question\bank\qbank_helper::get_question_structure(
|
||||
$course2q1structure = \mod_quiz\question\bank\qbank_helper::get_question_structure(
|
||||
$course2quiz1->instance, $course2quiz1->context);
|
||||
$this->assertEquals($course1structure[1]->questionid, $course2structure[1]->questionid);
|
||||
$this->assertEquals($question1->id, $course1q1structure[1]->questionid);
|
||||
$this->assertEquals($question1->id, $course2q1structure[1]->questionid);
|
||||
|
||||
$course1structure = \mod_quiz\question\bank\qbank_helper::get_question_structure(
|
||||
$course1q2structure = \mod_quiz\question\bank\qbank_helper::get_question_structure(
|
||||
$quiz2->id, \context_module::instance($quiz2->cmid));
|
||||
$course2quiz2 = array_shift($modules);
|
||||
$course2structure = \mod_quiz\question\bank\qbank_helper::get_question_structure(
|
||||
$course2q2structure = \mod_quiz\question\bank\qbank_helper::get_question_structure(
|
||||
$course2quiz2->instance, $course2quiz2->context);
|
||||
$this->assertEquals($course1structure[1]->questionid, $course2structure[1]->questionid);
|
||||
$this->assertEquals($question2->id, $course1q2structure[1]->questionid);
|
||||
$this->assertEquals($question2->id, $course2q2structure[1]->questionid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user