Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 14... Línea 14...
14
// You should have received a copy of the GNU General Public License
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea -... Línea 17...
-
 
17
namespace mod_quiz;
-
 
18
 
17
namespace mod_quiz;
19
use core\exception\coding_exception;
18
 
20
use core_question\local\bank\random_question_loader;
Línea 19... Línea 21...
19
use core_question\question_reference_manager;
21
use core_question\question_reference_manager;
Línea 32... Línea 34...
32
 * @package    mod_quiz
34
 * @package    mod_quiz
33
 * @category   test
35
 * @category   test
34
 * @copyright  2021 Catalyst IT Australia Pty Ltd
36
 * @copyright  2021 Catalyst IT Australia Pty Ltd
35
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
37
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
36
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
39
 * @covers \mod_quiz\question\bank\qbank_helper
-
 
40
 * @covers \restore_quiz_activity_structure_step
-
 
41
 * @covers \restore_question_set_reference_data_trait
37
 */
42
 */
38
class quiz_question_restore_test extends \advanced_testcase {
43
final class quiz_question_restore_test extends \advanced_testcase {
39
    use \quiz_question_helper_test_trait;
44
    use \quiz_question_helper_test_trait;
Línea 40... Línea 45...
40
 
45
 
41
    /**
46
    /**
42
     * @var \stdClass test student user.
47
     * @var \stdClass test student user.
Línea 54... Línea 59...
54
        $this->student = $this->getDataGenerator()->create_user();
59
        $this->student = $this->getDataGenerator()->create_user();
55
        $this->user = $USER;
60
        $this->user = $USER;
56
    }
61
    }
Línea 57... Línea 62...
57
 
62
 
58
    /**
63
    /**
59
     * Test a quiz backup and restore in a different course without attempts for course question bank.
64
     * Create a quiz with 2 questions and 1 random question, using question categories in the provided context.
60
     *
65
     *
-
 
66
     * @param int $questioncontextid Context to create question categories in.
61
     * @covers \mod_quiz\question\bank\qbank_helper::get_question_structure
67
     * @return array The quiz, slots, random questions in each slot that has them, and the quiz context.
62
     */
68
     */
63
    public function test_quiz_restore_in_a_different_course_using_course_question_bank(): void {
-
 
64
        $this->resetAfterTest();
-
 
65
 
-
 
66
        // Create the test quiz.
69
    public function create_quiz_with_questions(int $questioncontextid): array {
67
        $quiz = $this->create_test_quiz($this->course);
70
        $quiz = $this->create_test_quiz($this->course);
-
 
71
        $quizcontext = \context_module::instance($quiz->cmid);
68
        $oldquizcontext = \context_module::instance($quiz->cmid);
72
 
69
        // Test for questions from a different context.
-
 
70
        $coursecontext = \context_course::instance($this->course->id);
73
        // Test for questions from a different context.
71
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
74
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
72
        $this->add_two_regular_questions($questiongenerator, $quiz, ['contextid' => $coursecontext->id]);
75
        $this->add_two_regular_questions($questiongenerator, $quiz, ['contextid' => $questioncontextid]);
-
 
76
        $this->add_one_random_question($questiongenerator, $quiz, ['contextid' => $questioncontextid]);
-
 
77
        $slots = \mod_quiz\question\bank\qbank_helper::get_question_structure(
-
 
78
            $quiz->id, $quizcontext);
-
 
79
        $randomquestions = [];
-
 
80
        $loader = new random_question_loader(new \qubaid_list([]));
-
 
81
        foreach ($slots as $number => $slot) {
-
 
82
            if (!empty($slot->filtercondition)) {
-
 
83
                $randomquestions[$number] = $loader->get_filtered_questions($slot->filtercondition['filter']);
-
 
84
            }
-
 
85
        }
-
 
86
        return [
-
 
87
            $quiz,
-
 
88
            $slots,
-
 
89
            $randomquestions,
-
 
90
            $quizcontext,
-
 
91
        ];
-
 
92
    }
-
 
93
 
-
 
94
    /**
-
 
95
     * Verify the layout of the quiz on the provided course matches (or doesn't match) the expected layout.
-
 
96
     *
-
 
97
     * For $expectedslots, the value should be provided as an array keyed by slot number. Each slot can be provided as a single
-
 
98
     * number, which will considered a question ID, or an array with 'filter' and 'randomquestionids' which will be considered
-
 
99
     * a random question.
-
 
100
     *
-
 
101
     * For example,
-
 
102
     * [
-
 
103
     *  [1] => 123,
-
 
104
     *  [2] => [
-
 
105
     *           'filter' => ['name' => 'category', 'values' => ['345']],
-
 
106
     *           'randomquestionids' => ['101', '102'],
-
 
107
     *         ],
-
 
108
     *  [3] => 124,
-
 
109
     * ]
-
 
110
     * Will assert that the quiz contains (or doesn't contain if $expectequal is false):
-
 
111
     * - A question in slot 1 with ID 123,
-
 
112
     * - A random question in slot 2 with a filter for category ID 345, which matches questions with IDs 101 and 102,
-
 
113
     * - A question in slot 3 with ID 124.
-
 
114
     *
-
 
115
     * @param int $courseid The ID of the course to pick the quiz from.
-
 
116
     * @param array $expectedslots The layout of slots to compare to, see above for details of the structure.
-
 
117
     * @param bool $expectequal If true, assert that each slot is equal to the expected value. Otherwise assert it's not equal.
-
 
118
     */
-
 
119
    public function verify_restored_quiz_layout(
-
 
120
        int $courseid,
-
 
121
        array $expectedslots,
-
 
122
        bool $expectequal
-
 
123
    ): void {
-
 
124
        $loader = new random_question_loader(new \qubaid_list([]));
-
 
125
        $modules = get_fast_modinfo($courseid)->get_instances_of('quiz');
-
 
126
        $module = reset($modules);
-
 
127
        $newslots = \mod_quiz\question\bank\qbank_helper::get_question_structure(
-
 
128
            $module->instance, $module->context);
-
 
129
        $this->assertCount(count($expectedslots), $newslots);
-
 
130
        foreach ($newslots as $number => $slot) {
-
 
131
            $randomquestionids = null;
-
 
132
            if (is_array($expectedslots[$number])) {
-
 
133
                // A random question, compare filters and filtered question ids.
-
 
134
                $actualcontents = $slot->filtercondition['filter'];
-
 
135
                $expectedcontents = $expectedslots[$number]['filter'];
-
 
136
                $randomquestions = $loader->get_filtered_questions($slot->filtercondition['filter']);
-
 
137
                $randomquestionids = array_keys($randomquestions);
-
 
138
                sort($randomquestionids);
-
 
139
                sort($expectedslots[$number]['randomquestionids']);
-
 
140
            } else if (is_numeric($expectedslots[$number])) {
-
 
141
                // A normal question, compare IDs.
-
 
142
                $actualcontents = $slot->questionid;
-
 
143
                $expectedcontents = $expectedslots[$number];
-
 
144
            } else {
-
 
145
                throw new coding_exception('Slots must either be a number or an array.');
-
 
146
            }
-
 
147
            if ($expectequal) {
-
 
148
                $this->assertEquals($expectedcontents, $actualcontents);
-
 
149
                if (!is_null($randomquestionids)) {
-
 
150
                    $this->assertEquals($expectedslots[$number]['randomquestionids'], $randomquestionids);
-
 
151
                }
-
 
152
            } else {
-
 
153
                $this->assertNotEquals($expectedcontents, $actualcontents);
-
 
154
                if (!is_null($randomquestionids)) {
-
 
155
                    $this->assertNotEquals($expectedslots[$number]['randomquestionids'], $randomquestionids);
-
 
156
                }
-
 
157
            }
-
 
158
        }
-
 
159
    }
-
 
160
 
-
 
161
    /**
-
 
162
     * Restore a quiz that used questions from a shared question bank on the same course, after the course is deleted.
-
 
163
     *
-
 
164
     * The restored quiz should use new copies of the questions.
-
 
165
     */
-
 
166
    public function test_quiz_restore_in_a_different_course_using_question_bank(): void {
-
 
167
        $this->resetAfterTest();
-
 
168
 
-
 
169
        // Create the test quiz.
-
 
170
        $qbank = self::getDataGenerator()->create_module('qbank', ['course' => $this->course]);
-
 
171
        $qbankcontext = \context_module::instance($qbank->cmid);
Línea 73... Línea 172...
73
        $this->add_one_random_question($questiongenerator, $quiz, ['contextid' => $coursecontext->id]);
172
        [$quiz, $originalslots, $randomquestions, $quizcontext] = $this->create_quiz_with_questions($qbankcontext->id);
74
 
173
 
Línea 75... Línea 174...
75
        // Make the backup.
174
        // Make the backup.
76
        $backupid = $this->backup_quiz($quiz, $this->user);
175
        $backupid = $this->backup_quiz($quiz, $this->user);
Línea 77... Línea 176...
77
 
176
 
78
        // Delete the current course to make sure there is no data.
177
        // Delete the current course to make sure there is no data.
-
 
178
        delete_course($this->course, false);
-
 
179
 
-
 
180
        // Check if the questions and associated data are deleted properly.
-
 
181
        $this->assertEquals(0, count(\mod_quiz\question\bank\qbank_helper::get_question_structure($quiz->id, $quizcontext)));
-
 
182
 
-
 
183
        // Restore the course.
-
 
184
        $newcourse = $this->getDataGenerator()->create_course();
-
 
185
        $this->restore_quiz($backupid, $newcourse, $this->user);
-
 
186
 
79
        delete_course($this->course, false);
187
        $this->verify_restored_quiz_layout(
-
 
188
            courseid: $newcourse->id,
-
 
189
            expectedslots: [
-
 
190
                1 => $originalslots[1]->questionid,
-
 
191
                2 => $originalslots[2]->questionid,
-
 
192
                3 => [
-
 
193
                    'filter' => $originalslots[3]->filtercondition['filter'],
-
 
194
                    'randomquestionids' => array_keys($randomquestions[3]),
-
 
195
                ],
-
 
196
            ],
-
 
197
            expectequal: false,
-
 
198
        );
-
 
199
    }
-
 
200
 
-
 
201
    /**
-
 
202
     * Restore a quiz that used questions from a shared question bank on the same course.
-
 
203
     *
-
 
204
     * The restored quiz should reference the questions in the original question bank.
-
 
205
     */
-
 
206
    public function test_quiz_restore_in_a_different_course_reference_original_question_bank(): void {
-
 
207
        $this->resetAfterTest();
-
 
208
 
-
 
209
        // Create the test quiz.
-
 
210
        $qbank = self::getDataGenerator()->create_module('qbank', ['course' => $this->course]);
-
 
211
        $qbankcontext = \context_module::instance($qbank->cmid);
Línea 80... Línea 212...
80
 
212
        [$quiz, $originalslots, $randomquestions] = $this->create_quiz_with_questions($qbankcontext->id);
81
        // Check if the questions and associated data are deleted properly.
213
 
82
        $this->assertEquals(0, count(\mod_quiz\question\bank\qbank_helper::get_question_structure(
214
        // Make the backup.
Línea -... Línea 215...
-
 
215
        $backupid = $this->backup_quiz($quiz, $this->user);
-
 
216
 
-
 
217
        // Restore the course.
-
 
218
        $newcourse = $this->getDataGenerator()->create_course();
-
 
219
        $this->restore_quiz($backupid, $newcourse, $this->user);
-
 
220
 
-
 
221
        $this->verify_restored_quiz_layout(
-
 
222
            courseid: $newcourse->id,
-
 
223
            expectedslots: [
-
 
224
                1 => $originalslots[1]->questionid,
-
 
225
                2 => $originalslots[2]->questionid,
-
 
226
                3 => [
-
 
227
                    'filter' => $originalslots[3]->filtercondition['filter'],
-
 
228
                    'randomquestionids' => array_keys($randomquestions[3]),
-
 
229
                ],
-
 
230
            ],
-
 
231
            expectequal: true,
-
 
232
        );
-
 
233
    }
-
 
234
 
-
 
235
    /**
-
 
236
     * Restore a quiz that used questions from a shared question bank on the same course, as a user who cannot access the course.
-
 
237
     *
-
 
238
     * The restored quiz should use new copies of the questions.
-
 
239
     */
-
 
240
    public function test_quiz_restore_in_a_different_course_cant_use_original_question_bank(): void {
-
 
241
        $this->resetAfterTest();
-
 
242
 
-
 
243
        // Create the test quiz.
-
 
244
        $qbank = self::getDataGenerator()->create_module('qbank', ['course' => $this->course]);
-
 
245
        $qbankcontext = \context_module::instance($qbank->cmid);
-
 
246
        [$quiz, $originalslots, $randomquestions] = $this->create_quiz_with_questions($qbankcontext->id);
-
 
247
 
-
 
248
        // Make the backup.
-
 
249
        $backupid = $this->backup_quiz($quiz, $this->user);
-
 
250
 
-
 
251
        // Restore the course as a new user without access to the original course.
-
 
252
        $newcourse = $this->getDataGenerator()->create_course();
-
 
253
        $newuser = self::getDataGenerator()->create_user();
-
 
254
        self::getDataGenerator()->enrol_user($newuser->id, $newcourse->id, 'manager');
-
 
255
        $this->setUser($newuser);
-
 
256
        $this->restore_quiz($backupid, $newcourse, $newuser);
-
 
257
 
-
 
258
        $this->verify_restored_quiz_layout(
-
 
259
            courseid: $newcourse->id,
-
 
260
            expectedslots: [
-
 
261
                1 => $originalslots[1]->questionid,
-
 
262
                2 => $originalslots[2]->questionid,
-
 
263
                3 => [
-
 
264
                    'filter' => $originalslots[3]->filtercondition['filter'],
-
 
265
                    'randomquestionids' => array_keys($randomquestions[3]),
-
 
266
                ],
-
 
267
            ],
-
 
268
            expectequal: false,
-
 
269
        );
-
 
270
    }
-
 
271
 
-
 
272
    /**
-
 
273
     * Restore a quiz that used questions from a shared question bank on another course, after that other course is deleted.
-
 
274
     *
-
 
275
     * The restored quiz should use new copies of the questions.
-
 
276
     */
-
 
277
    public function test_quiz_restore_in_a_different_course_question_course_has_been_deleted(): void {
-
 
278
        $this->resetAfterTest();
-
 
279
 
-
 
280
        // Create the test quiz.
-
 
281
        $qbankcourse = self::getDataGenerator()->create_course();
-
 
282
        $qbank = self::getDataGenerator()->create_module('qbank', ['course' => $qbankcourse]);
-
 
283
        $qbankcontext = \context_module::instance($qbank->cmid);
-
 
284
        [$quiz, $originalslots, $randomquestions] = $this->create_quiz_with_questions($qbankcontext->id);
-
 
285
 
-
 
286
        // Make the backup.
-
 
287
        $backupid = $this->backup_quiz($quiz, $this->user);
-
 
288
 
-
 
289
        // Delete the qbank course.
83
                $quiz->id, $oldquizcontext)));
290
        delete_course($qbankcourse, false);
-
 
291
 
84
 
292
        // Restore the course as a new copy.
85
        // Restore the course.
293
        $newcourse = $this->getDataGenerator()->create_course();
86
        $newcourse = $this->getDataGenerator()->create_course();
294
        $this->restore_quiz($backupid, $newcourse, $this->user);
87
        $this->restore_quiz($backupid, $newcourse, $this->user);
295
 
-
 
296
        // Verify.
-
 
297
        $this->verify_restored_quiz_layout(
-
 
298
            courseid: $newcourse->id,
-
 
299
            expectedslots: [
-
 
300
                1 => $originalslots[1]->questionid,
88
 
301
                2 => $originalslots[2]->questionid,
-
 
302
                3 => [
89
        // Verify.
303
                    'filter' => $originalslots[3]->filtercondition['filter'],
Línea 90... Línea 304...
90
        $modules = get_fast_modinfo($newcourse->id)->get_instances_of('quiz');
304
                    'randomquestionids' => array_keys($randomquestions[3]),
91
        $module = reset($modules);
305
                ],
92
        $questions = \mod_quiz\question\bank\qbank_helper::get_question_structure(
306
            ],
Línea 149... Línea 363...
149
              WHERE qc.contextid = ?
363
              WHERE qc.contextid = ?
150
              $extracondition", [$contextid]);
364
              $extracondition", [$contextid]);
151
    }
365
    }
Línea 152... Línea 366...
152
 
366
 
153
    /**
367
    /**
154
     * Test if a duplicate does not duplicate questions in course question bank.
368
     * Duplicate a quiz that uses questions from a shared bank on the same course.
155
     *
369
     *
156
     * @covers ::duplicate_module
370
     * The new quiz should reference the same questions.
157
     */
371
     */
158
    public function test_quiz_duplicate_does_not_duplicate_course_question_bank_questions(): void {
372
    public function test_quiz_duplicate_does_not_duplicate_questions_from_shared_banks(): void {
159
        $this->resetAfterTest();
-
 
160
        $quiz = $this->create_test_quiz($this->course);
373
        $this->resetAfterTest();
161
        // Test for questions from a different context.
374
        // Test for questions from a qbank context.
162
        $context = \context_course::instance($this->course->id);
375
        $qbankcourse = self::getDataGenerator()->create_course();
163
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
376
        $qbank = self::getDataGenerator()->create_module('qbank', ['course' => $qbankcourse]);
164
        $this->add_two_regular_questions($questiongenerator, $quiz, ['contextid' => $context->id]);
377
        $context = \context_module::instance($qbank->cmid);
165
        $this->add_one_random_question($questiongenerator, $quiz, ['contextid' => $context->id]);
378
        [$quiz, $originalslots, $randomquestions] = $this->create_quiz_with_questions($context->id);
166
        // Count the questions in course context.
379
        // Count the questions in qbank context.
-
 
380
        $this->assertEquals(7, $this->question_count($context->id));
167
        $this->assertEquals(7, $this->question_count($context->id));
381
        $this->assertCount(3, $originalslots);
168
        $newquiz = $this->duplicate_quiz($this->course, $quiz);
382
        $newquiz = $this->duplicate_quiz($this->course, $quiz);
169
        $this->assertEquals(7, $this->question_count($context->id));
383
        $this->assertEquals(7, $this->question_count($context->id));
170
        $context = \context_module::instance($newquiz->id);
384
        $newquizcontext = \context_module::instance($newquiz->id);
171
        // Count the questions in the quiz context.
385
        // Count the questions in the quiz context.
-
 
386
        $this->assertEquals(0, $this->question_count($newquizcontext->id));
-
 
387
 
-
 
388
        $this->verify_restored_quiz_layout(
-
 
389
            courseid: $this->course->id,
-
 
390
            expectedslots: [
-
 
391
                1 => $originalslots[1]->questionid,
-
 
392
                2 => $originalslots[2]->questionid,
-
 
393
                3 => [
-
 
394
                    'filter' => $originalslots[3]->filtercondition['filter'],
-
 
395
                    'randomquestionids' => array_keys($randomquestions[3]),
-
 
396
                ],
-
 
397
            ],
-
 
398
            expectequal: true,
172
        $this->assertEquals(0, $this->question_count($context->id));
399
        );
Línea 173... Línea 400...
173
    }
400
    }
174
 
401
 
175
    /**
402
    /**
Línea 301... Línea 528...
301
        $categoryid = $DB->get_field_sql("SELECT MIN(id) FROM {course_categories}");
528
        $categoryid = $DB->get_field_sql("SELECT MIN(id) FROM {course_categories}");
302
        $newcourseid = \restore_dbops::create_new_course('Test fullname', 'Test shortname', $categoryid);
529
        $newcourseid = \restore_dbops::create_new_course('Test fullname', 'Test shortname', $categoryid);
303
        $rc = new \restore_controller($backupid, $newcourseid, \backup::INTERACTIVE_NO, \backup::MODE_GENERAL, $USER->id,
530
        $rc = new \restore_controller($backupid, $newcourseid, \backup::INTERACTIVE_NO, \backup::MODE_GENERAL, $USER->id,
304
            \backup::TARGET_NEW_COURSE);
531
            \backup::TARGET_NEW_COURSE);
Línea 305... Línea 532...
305
 
532
 
-
 
533
        $rc->execute_precheck();
-
 
534
        $results = $rc->get_precheck_results();
-
 
535
        // Backup contains categories attached to deprecated contexts so the results should only contain warnings for these.
-
 
536
        $this->assertCount(2, $results['warnings']);
-
 
537
        foreach ($results['warnings'] as $warning) {
-
 
538
            $this->assertStringContainsString('will be created at a question bank module context by restore', $warning);
-
 
539
        }
-
 
540
        $this->assertArrayNotHasKey('errors', $results);
306
        $this->assertTrue($rc->execute_precheck());
541
 
307
        $rc->execute_plan();
542
        $rc->execute_plan();
Línea 308... Línea 543...
308
        $rc->destroy();
543
        $rc->destroy();
309
 
544
 
-
 
545
        // Get the information about the resulting course and check that it is set up correctly.
-
 
546
        $modinfo = get_fast_modinfo($newcourseid);
-
 
547
        $qbanks = $modinfo->get_instances_of('qbank');
-
 
548
        $this->assertCount(1, $qbanks);
310
        // Get the information about the resulting course and check that it is set up correctly.
549
        $qbank = reset($qbanks);
311
        $modinfo = get_fast_modinfo($newcourseid);
550
        $this->assertEquals(get_string('systembank', 'question'), $qbank->name);
312
        $quiz = array_values($modinfo->get_instances_of('quiz'))[0];
551
        $quiz = array_values($modinfo->get_instances_of('quiz'))[0];
Línea 313... Línea 552...
313
        $quizobj = \mod_quiz\quiz_settings::create($quiz->instance);
552
        $quizobj = \mod_quiz\quiz_settings::create($quiz->instance);
Línea 320... Línea 559...
320
        $quizobj->preload_questions();
559
        $quizobj->preload_questions();
321
        $quizobj->load_questions();
560
        $quizobj->load_questions();
322
        $questions = $quizobj->get_questions();
561
        $questions = $quizobj->get_questions();
323
        $this->assertCount(1, $questions);
562
        $this->assertCount(1, $questions);
Línea 324... Línea 563...
324
 
563
 
325
        // Count the questions for course question bank.
564
        // Count the questions for new course mod_qbank question bank.
326
        $this->assertEquals(6, $this->question_count(\context_course::instance($newcourseid)->id));
565
        $this->assertEquals(6, $this->question_count(\context_module::instance($qbank->id)->id));
327
        $this->assertEquals(6, $this->question_count(\context_course::instance($newcourseid)->id,
-
 
Línea 328... Línea 566...
328
            "AND q.qtype <> 'random'"));
566
        $this->assertEquals(6, $this->question_count(\context_module::instance($qbank->id)->id, "AND q.qtype <> 'random'"));
329
 
567
 
330
        // Count the questions in quiz qbank.
568
        // Count the questions in quiz qbank.
Línea 406... Línea 644...
406
        $categoryid = $DB->get_field_sql("SELECT MIN(id) FROM {course_categories}");
644
        $categoryid = $DB->get_field_sql("SELECT MIN(id) FROM {course_categories}");
407
        $newcourseid = \restore_dbops::create_new_course('Test fullname', 'Test shortname', $categoryid);
645
        $newcourseid = \restore_dbops::create_new_course('Test fullname', 'Test shortname', $categoryid);
408
        $rc = new \restore_controller($backupid, $newcourseid, \backup::INTERACTIVE_NO, \backup::MODE_GENERAL, $USER->id,
646
        $rc = new \restore_controller($backupid, $newcourseid, \backup::INTERACTIVE_NO, \backup::MODE_GENERAL, $USER->id,
409
                \backup::TARGET_NEW_COURSE);
647
                \backup::TARGET_NEW_COURSE);
Línea 410... Línea 648...
410
 
648
 
-
 
649
        $rc->execute_precheck();
-
 
650
        $results = $rc->get_precheck_results();
-
 
651
        // Backup contains categories attached to deprecated contexts, so we should only have warnings for those.
-
 
652
        $this->assertCount(1, $results['warnings']);
-
 
653
        $this->assertStringContainsString('will be created at a question bank module context by restore', $results['warnings'][0]);
-
 
654
        $this->assertArrayNotHasKey('errors', $results);
411
        $this->assertTrue($rc->execute_precheck());
655
 
412
        $rc->execute_plan();
656
        $rc->execute_plan();
Línea 413... Línea 657...
413
        $rc->destroy();
657
        $rc->destroy();
414
 
658
 
415
        // Get the information about the resulting course and check that it is set up correctly.
659
        // Get the information about the resulting course and check that it is set up correctly.
-
 
660
        // Each quiz should contain an instance of the random question.
416
        // Each quiz should contain an instance of the random question.
661
        $modinfo = get_fast_modinfo($newcourseid);
417
        $modinfo = get_fast_modinfo($newcourseid);
662
        $qbank = array_values($modinfo->get_instances_of('qbank'))[0];
418
        $quizzes = $modinfo->get_instances_of('quiz');
663
        $quizzes = $modinfo->get_instances_of('quiz');
419
        $this->assertCount(2, $quizzes);
664
        $this->assertCount(2, $quizzes);
420
        foreach ($quizzes as $quiz) {
665
        foreach ($quizzes as $quiz) {
Línea 429... Línea 674...
429
            $quizobj->load_questions();
674
            $quizobj->load_questions();
430
            $questions = $quizobj->get_questions();
675
            $questions = $quizobj->get_questions();
431
            $this->assertCount(1, $questions);
676
            $this->assertCount(1, $questions);
432
        }
677
        }
Línea 433... Línea 678...
433
 
678
 
434
        // Count the questions for course question bank.
679
        // Count the questions for new course mod_qbank question bank.
435
        // We should have a single question, the random question should have been deleted after the restore.
680
        // We should have a single question, the random question should have been deleted after the restore.
436
        $this->assertEquals(1, $this->question_count(\context_course::instance($newcourseid)->id));
681
        $this->assertEquals(1, $this->question_count(\context_module::instance($qbank->id)->id));
437
        $this->assertEquals(1, $this->question_count(\context_course::instance($newcourseid)->id,
682
        $this->assertEquals(1, $this->question_count(\context_module::instance($qbank->id)->id,
Línea 438... Línea 683...
438
                "AND q.qtype <> 'random'"));
683
                "AND q.qtype <> 'random'"));
439
 
684
 
440
        // Count the questions in quiz qbank.
685
        // Count the questions in quiz qbank.