Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 32... Línea 32...
32
 * @package    mod_quiz
32
 * @package    mod_quiz
33
 * @category   test
33
 * @category   test
34
 * @copyright  2021 Catalyst IT Australia Pty Ltd
34
 * @copyright  2021 Catalyst IT Australia Pty Ltd
35
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
35
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
36
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 * @coversDefaultClass \mod_quiz\question\bank\qbank_helper
-
 
38
 * @coversDefaultClass \backup_quiz_activity_structure_step
-
 
39
 * @coversDefaultClass \restore_quiz_activity_structure_step
-
 
40
 */
37
 */
41
class quiz_question_restore_test extends \advanced_testcase {
38
class quiz_question_restore_test extends \advanced_testcase {
42
    use \quiz_question_helper_test_trait;
39
    use \quiz_question_helper_test_trait;
Línea 43... Línea 40...
43
 
40
 
Línea 59... Línea 56...
59
    }
56
    }
Línea 60... Línea 57...
60
 
57
 
61
    /**
58
    /**
62
     * Test a quiz backup and restore in a different course without attempts for course question bank.
59
     * Test a quiz backup and restore in a different course without attempts for course question bank.
63
     *
60
     *
64
     * @covers ::get_question_structure
61
     * @covers \mod_quiz\question\bank\qbank_helper::get_question_structure
65
     */
62
     */
66
    public function test_quiz_restore_in_a_different_course_using_course_question_bank() {
63
    public function test_quiz_restore_in_a_different_course_using_course_question_bank(): void {
Línea 67... Línea 64...
67
        $this->resetAfterTest();
64
        $this->resetAfterTest();
68
 
65
 
69
        // Create the test quiz.
66
        // Create the test quiz.
Línea 98... Línea 95...
98
    }
95
    }
Línea 99... Línea 96...
99
 
96
 
100
    /**
97
    /**
101
     * Test a quiz backup and restore in a different course without attempts for quiz question bank.
98
     * Test a quiz backup and restore in a different course without attempts for quiz question bank.
102
     *
99
     *
103
     * @covers ::get_question_structure
100
     * @covers \mod_quiz\question\bank\qbank_helper::get_question_structure
104
     */
101
     */
105
    public function test_quiz_restore_in_a_different_course_using_quiz_question_bank() {
102
    public function test_quiz_restore_in_a_different_course_using_quiz_question_bank(): void {
Línea 106... Línea 103...
106
        $this->resetAfterTest();
103
        $this->resetAfterTest();
107
 
104
 
108
        // Create the test quiz.
105
        // Create the test quiz.
Línea 156... Línea 153...
156
    /**
153
    /**
157
     * Test if a duplicate does not duplicate questions in course question bank.
154
     * Test if a duplicate does not duplicate questions in course question bank.
158
     *
155
     *
159
     * @covers ::duplicate_module
156
     * @covers ::duplicate_module
160
     */
157
     */
161
    public function test_quiz_duplicate_does_not_duplicate_course_question_bank_questions() {
158
    public function test_quiz_duplicate_does_not_duplicate_course_question_bank_questions(): void {
162
        $this->resetAfterTest();
159
        $this->resetAfterTest();
163
        $quiz = $this->create_test_quiz($this->course);
160
        $quiz = $this->create_test_quiz($this->course);
164
        // Test for questions from a different context.
161
        // Test for questions from a different context.
165
        $context = \context_course::instance($this->course->id);
162
        $context = \context_course::instance($this->course->id);
166
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
163
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
Línea 178... Línea 175...
178
    /**
175
    /**
179
     * Test quiz duplicate for quiz question bank.
176
     * Test quiz duplicate for quiz question bank.
180
     *
177
     *
181
     * @covers ::duplicate_module
178
     * @covers ::duplicate_module
182
     */
179
     */
183
    public function test_quiz_duplicate_for_quiz_question_bank_questions() {
180
    public function test_quiz_duplicate_for_quiz_question_bank_questions(): void {
184
        $this->resetAfterTest();
181
        $this->resetAfterTest();
185
        $quiz = $this->create_test_quiz($this->course);
182
        $quiz = $this->create_test_quiz($this->course);
186
        // Test for questions from a different context.
183
        // Test for questions from a different context.
187
        $context = \context_module::instance($quiz->cmid);
184
        $context = \context_module::instance($quiz->cmid);
188
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
185
        $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
Línea 198... Línea 195...
198
    }
195
    }
Línea 199... Línea 196...
199
 
196
 
200
    /**
197
    /**
201
     * Test quiz restore with attempts.
198
     * Test quiz restore with attempts.
202
     *
199
     *
203
     * @covers ::get_question_structure
200
     * @covers \mod_quiz\question\bank\qbank_helper::get_question_structure
204
     */
201
     */
205
    public function test_quiz_restore_with_attempts() {
202
    public function test_quiz_restore_with_attempts(): void {
Línea 206... Línea 203...
206
        $this->resetAfterTest();
203
        $this->resetAfterTest();
207
 
204
 
208
        // Create a quiz.
205
        // Create a quiz.
Línea 239... Línea 236...
239
    /**
236
    /**
240
     * Test pre 4.0 quiz restore for regular questions.
237
     * Test pre 4.0 quiz restore for regular questions.
241
     *
238
     *
242
     * Also, for efficiency, tests restore of the review options.
239
     * Also, for efficiency, tests restore of the review options.
243
     *
240
     *
244
     * @covers ::process_quiz_question_legacy_instance
241
     * @covers \restore_quiz_activity_structure_step::process_quiz_question_legacy_instance
245
     */
242
     */
246
    public function test_pre_4_quiz_restore_for_regular_questions() {
243
    public function test_pre_4_quiz_restore_for_regular_questions(): void {
247
        global $USER, $DB;
244
        global $USER, $DB;
248
        $this->resetAfterTest();
245
        $this->resetAfterTest();
249
        $backupid = 'abc';
246
        $backupid = 'abc';
250
        $backuppath = make_backup_temp_directory($backupid);
247
        $backuppath = make_backup_temp_directory($backupid);
251
        get_file_packer('application/vnd.moodle.backup')->extract_to_pathname(
248
        get_file_packer('application/vnd.moodle.backup')->extract_to_pathname(
Línea 287... Línea 284...
287
    }
284
    }
Línea 288... Línea 285...
288
 
285
 
289
    /**
286
    /**
290
     * Test pre 4.0 quiz restore for random questions.
287
     * Test pre 4.0 quiz restore for random questions.
291
     *
288
     *
292
     * @covers ::process_quiz_question_legacy_instance
289
     * @covers \restore_quiz_activity_structure_step::process_quiz_question_legacy_instance
293
     */
290
     */
294
    public function test_pre_4_quiz_restore_for_random_questions() {
291
    public function test_pre_4_quiz_restore_for_random_questions(): void {
295
        global $USER, $DB;
292
        global $USER, $DB;
Línea 296... Línea 293...
296
        $this->resetAfterTest();
293
        $this->resetAfterTest();
297
 
294
 
Línea 335... Línea 332...
335
    }
332
    }
Línea 336... Línea 333...
336
 
333
 
337
    /**
334
    /**
338
     * Test pre 4.0 quiz restore for random question tags.
335
     * Test pre 4.0 quiz restore for random question tags.
339
     *
336
     *
340
     * @covers ::process_quiz_question_legacy_instance
337
     * @covers \restore_quiz_activity_structure_step::process_quiz_question_legacy_instance
341
     */
338
     */
342
    public function test_pre_4_quiz_restore_for_random_question_tags() {
339
    public function test_pre_4_quiz_restore_for_random_question_tags(): void {
343
        global $USER, $DB;
340
        global $USER, $DB;
344
        $this->resetAfterTest();
341
        $this->resetAfterTest();
345
        $randomtags = [
342
        $randomtags = [
346
            '1' => ['first question', 'one', 'number one'],
343
            '1' => ['first question', 'one', 'number one'],
Línea 392... Línea 389...
392
    }
389
    }
Línea 393... Línea 390...
393
 
390
 
394
    /**
391
    /**
395
     * Test pre 4.0 quiz restore for random question used on multiple quizzes.
392
     * Test pre 4.0 quiz restore for random question used on multiple quizzes.
396
     *
393
     *
397
     * @covers ::process_quiz_question_legacy_instance
394
     * @covers \restore_quiz_activity_structure_step::process_quiz_question_legacy_instance
398
     */
395
     */
399
    public function test_pre_4_quiz_restore_shared_random_question() {
396
    public function test_pre_4_quiz_restore_shared_random_question(): void {
400
        global $USER, $DB;
397
        global $USER, $DB;
Línea 401... Línea 398...
401
        $this->resetAfterTest();
398
        $this->resetAfterTest();
402
 
399
 
Línea 523... Línea 520...
523
    /**
520
    /**
524
     * Test pre 4.3 quiz restore for random question filter conditions.
521
     * Test pre 4.3 quiz restore for random question filter conditions.
525
     *
522
     *
526
     * @covers \restore_question_set_reference_data_trait::process_question_set_reference
523
     * @covers \restore_question_set_reference_data_trait::process_question_set_reference
527
     */
524
     */
528
    public function test_pre_43_quiz_restore_for_random_question_filtercondition() {
525
    public function test_pre_43_quiz_restore_for_random_question_filtercondition(): void {
529
        global $USER, $DB;
526
        global $USER, $DB;
530
        $this->resetAfterTest();
527
        $this->resetAfterTest();
531
        $backupid = 'abc';
528
        $backupid = 'abc';
532
        $backuppath = make_backup_temp_directory($backupid);
529
        $backuppath = make_backup_temp_directory($backupid);
533
        get_file_packer('application/vnd.moodle.backup')->extract_to_pathname(
530
        get_file_packer('application/vnd.moodle.backup')->extract_to_pathname(