Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 115... Línea 115...
115
    protected function assert_category_contains_questions(int $categoryid, int $numberofquestions): void {
115
    protected function assert_category_contains_questions(int $categoryid, int $numberofquestions): void {
116
        $questionsid = question_bank::get_finder()->get_questions_from_categories([$categoryid], null);
116
        $questionsid = question_bank::get_finder()->get_questions_from_categories([$categoryid], null);
117
        $this->assertEquals($numberofquestions, count($questionsid));
117
        $this->assertEquals($numberofquestions, count($questionsid));
118
    }
118
    }
Línea 119... Línea 119...
119
 
119
 
120
    public function test_question_reorder_qtypes() {
120
    public function test_question_reorder_qtypes(): void {
121
        $this->assertEquals(
121
        $this->assertEquals(
122
            array(0 => 't2', 1 => 't1', 2 => 't3'),
122
            array(0 => 't2', 1 => 't1', 2 => 't3'),
123
            question_reorder_qtypes(array('t1' => '', 't2' => '', 't3' => ''), 't1', +1));
123
            question_reorder_qtypes(array('t1' => '', 't2' => '', 't3' => ''), 't1', +1));
124
        $this->assertEquals(
124
        $this->assertEquals(
Línea 133... Línea 133...
133
        $this->assertEquals(
133
        $this->assertEquals(
134
            array(0 => 't1', 1 => 't2', 2 => 't3'),
134
            array(0 => 't1', 1 => 't2', 2 => 't3'),
135
            question_reorder_qtypes(array('t1' => '', 't2' => '', 't3' => ''), 'missing', +1));
135
            question_reorder_qtypes(array('t1' => '', 't2' => '', 't3' => ''), 'missing', +1));
136
    }
136
    }
Línea 137... Línea 137...
137
 
137
 
138
    public function test_match_grade_options() {
138
    public function test_match_grade_options(): void {
Línea 139... Línea 139...
139
        $gradeoptions = question_bank::fraction_options_full();
139
        $gradeoptions = question_bank::fraction_options_full();
140
 
140
 
141
        $this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.3333333, 'error'));
141
        $this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.3333333, 'error'));
Línea 153... Línea 153...
153
 
153
 
154
    /**
154
    /**
155
     * This function tests that the functions responsible for moving questions to
155
     * This function tests that the functions responsible for moving questions to
156
     * different contexts also updates the tag instances associated with the questions.
156
     * different contexts also updates the tag instances associated with the questions.
157
     */
157
     */
158
    public function test_altering_tag_instance_context() {
158
    public function test_altering_tag_instance_context(): void {
Línea 159... Línea 159...
159
        global $CFG, $DB;
159
        global $CFG, $DB;
160
 
160
 
Línea 276... Línea 276...
276
    }
276
    }
Línea 277... Línea 277...
277
 
277
 
278
    /**
278
    /**
279
     * Test that deleting a question from the question bank works in the normal case.
279
     * Test that deleting a question from the question bank works in the normal case.
280
     */
280
     */
281
    public function test_question_delete_question() {
281
    public function test_question_delete_question(): void {
Línea 282... Línea 282...
282
        global $DB;
282
        global $DB;
283
 
283
 
284
        // Setup.
284
        // Setup.
Línea 299... Línea 299...
299
    }
299
    }
Línea 300... Línea 300...
300
 
300
 
301
    /**
301
    /**
302
     * Test that deleting a broken question from the question bank does not cause fatal errors.
302
     * Test that deleting a broken question from the question bank does not cause fatal errors.
303
     */
303
     */
304
    public function test_question_delete_question_broken_data() {
304
    public function test_question_delete_question_broken_data(): void {
Línea 305... Línea 305...
305
        global $DB;
305
        global $DB;
306
 
306
 
307
        // Setup.
307
        // Setup.
Línea 327... Línea 327...
327
    }
327
    }
Línea 328... Línea 328...
328
 
328
 
329
    /**
329
    /**
330
     * Test deleting a broken question whose category refers to a missing context
330
     * Test deleting a broken question whose category refers to a missing context
331
     */
331
     */
332
    public function test_question_delete_question_missing_context() {
332
    public function test_question_delete_question_missing_context(): void {
Línea 333... Línea 333...
333
        global $DB;
333
        global $DB;
334
 
334
 
Línea 354... Línea 354...
354
    }
354
    }
Línea 355... Línea 355...
355
 
355
 
356
    /**
356
    /**
357
     * This function tests the question_category_delete_safe function.
357
     * This function tests the question_category_delete_safe function.
358
     */
358
     */
359
    public function test_question_category_delete_safe() {
359
    public function test_question_category_delete_safe(): void {
360
        global $DB;
360
        global $DB;
361
        $this->resetAfterTest(true);
361
        $this->resetAfterTest(true);
Línea 362... Línea 362...
362
        $this->setAdminUser();
362
        $this->setAdminUser();
Línea 378... Línea 378...
378
    }
378
    }
Línea 379... Línea 379...
379
 
379
 
380
    /**
380
    /**
381
     * This function tests the question_delete_activity function.
381
     * This function tests the question_delete_activity function.
382
     */
382
     */
383
    public function test_question_delete_activity() {
383
    public function test_question_delete_activity(): void {
384
        global $DB;
384
        global $DB;
385
        $this->resetAfterTest(true);
385
        $this->resetAfterTest(true);
Línea 386... Línea 386...
386
        $this->setAdminUser();
386
        $this->setAdminUser();
Línea 401... Línea 401...
401
    }
401
    }
Línea 402... Línea 402...
402
 
402
 
403
    /**
403
    /**
404
     * This function tests the question_delete_context function.
404
     * This function tests the question_delete_context function.
405
     */
405
     */
406
    public function test_question_delete_context() {
406
    public function test_question_delete_context(): void {
407
        global $DB;
407
        global $DB;
408
        $this->resetAfterTest(true);
408
        $this->resetAfterTest(true);
Línea 409... Línea 409...
409
        $this->setAdminUser();
409
        $this->setAdminUser();
Línea 422... Línea 422...
422
    }
422
    }
Línea 423... Línea 423...
423
 
423
 
424
    /**
424
    /**
425
     * This function tests the question_delete_course function.
425
     * This function tests the question_delete_course function.
426
     */
426
     */
427
    public function test_question_delete_course() {
427
    public function test_question_delete_course(): void {
428
        global $DB;
428
        global $DB;
429
        $this->resetAfterTest(true);
429
        $this->resetAfterTest(true);
Línea 430... Línea 430...
430
        $this->setAdminUser();
430
        $this->setAdminUser();
Línea 443... Línea 443...
443
    }
443
    }
Línea 444... Línea 444...
444
 
444
 
445
    /**
445
    /**
446
     * This function tests the question_delete_course_category function.
446
     * This function tests the question_delete_course_category function.
447
     */
447
     */
448
    public function test_question_delete_course_category() {
448
    public function test_question_delete_course_category(): void {
449
        global $DB;
449
        global $DB;
450
        $this->resetAfterTest(true);
450
        $this->resetAfterTest(true);
Línea 451... Línea 451...
451
        $this->setAdminUser();
451
        $this->setAdminUser();
Línea 464... Línea 464...
464
    }
464
    }
Línea 465... Línea 465...
465
 
465
 
466
    /**
466
    /**
467
     * This function tests the question_delete_course_category function when it is supposed to move question categories.
467
     * This function tests the question_delete_course_category function when it is supposed to move question categories.
468
     */
468
     */
469
    public function test_question_delete_course_category_move_qcats() {
469
    public function test_question_delete_course_category_move_qcats(): void {
470
        global $DB;
470
        global $DB;
471
        $this->resetAfterTest(true);
471
        $this->resetAfterTest(true);
Línea 472... Línea 472...
472
        $this->setAdminUser();
472
        $this->setAdminUser();
Línea 505... Línea 505...
505
 
505
 
506
    /**
506
    /**
507
     * This function tests the question_save_from_deletion function when it is supposed to make a new category and
507
     * This function tests the question_save_from_deletion function when it is supposed to make a new category and
508
     * move question categories to that new category.
508
     * move question categories to that new category.
509
     */
509
     */
510
    public function test_question_save_from_deletion() {
510
    public function test_question_save_from_deletion(): void {
511
        global $DB;
511
        global $DB;
512
        $this->resetAfterTest(true);
512
        $this->resetAfterTest(true);
Línea 513... Línea 513...
513
        $this->setAdminUser();
513
        $this->setAdminUser();
Línea 528... Línea 528...
528
 
528
 
529
    /**
529
    /**
530
     * This function tests the question_save_from_deletion function when it is supposed to make a new category and
530
     * This function tests the question_save_from_deletion function when it is supposed to make a new category and
531
     * move question categories to that new category when quiz name is very long but less than 256 characters.
531
     * move question categories to that new category when quiz name is very long but less than 256 characters.
532
     */
532
     */
533
    public function test_question_save_from_deletion_quiz_with_long_name() {
533
    public function test_question_save_from_deletion_quiz_with_long_name(): void {
534
        global $DB;
534
        global $DB;
535
        $this->resetAfterTest(true);
535
        $this->resetAfterTest(true);
Línea 536... Línea 536...
536
        $this->setAdminUser();
536
        $this->setAdminUser();
Línea 558... Línea 558...
558
    }
558
    }
Línea 559... Línea 559...
559
 
559
 
560
    /**
560
    /**
561
     * get_question_options should add the category object to the given question.
561
     * get_question_options should add the category object to the given question.
562
     */
562
     */
563
    public function test_get_question_options_includes_category_object_single_question() {
563
    public function test_get_question_options_includes_category_object_single_question(): void {
564
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
564
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
Línea 565... Línea 565...
565
        $question = array_shift($questions);
565
        $question = array_shift($questions);
Línea 571... Línea 571...
571
 
571
 
572
    /**
572
    /**
573
     * get_question_options should add the category object to all of the questions in
573
     * get_question_options should add the category object to all of the questions in
574
     * the given list.
574
     * the given list.
575
     */
575
     */
576
    public function test_get_question_options_includes_category_object_multiple_questions() {
576
    public function test_get_question_options_includes_category_object_multiple_questions(): void {
Línea 577... Línea 577...
577
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
577
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
Línea 578... Línea 578...
578
 
578
 
Línea 584... Línea 584...
584
    }
584
    }
Línea 585... Línea 585...
585
 
585
 
586
    /**
586
    /**
587
     * get_question_options includes the tags for all questions in the list.
587
     * get_question_options includes the tags for all questions in the list.
588
     */
588
     */
589
    public function test_get_question_options_includes_question_tags() {
589
    public function test_get_question_options_includes_question_tags(): void {
590
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
590
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
591
        $question1 = $questions[0];
591
        $question1 = $questions[0];
592
        $question2 = $questions[1];
592
        $question2 = $questions[1];
Línea 621... Línea 621...
621
    }
621
    }
Línea 622... Línea 622...
622
 
622
 
623
    /**
623
    /**
624
     * get_question_options includes the course tags for all questions in the list.
624
     * get_question_options includes the course tags for all questions in the list.
625
     */
625
     */
626
    public function test_get_question_options_includes_course_tags() {
626
    public function test_get_question_options_includes_course_tags(): void {
627
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
627
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
628
        $question1 = $questions[0];
628
        $question1 = $questions[0];
629
        $question2 = $questions[1];
629
        $question2 = $questions[1];
Línea 660... Línea 660...
660
 
660
 
661
    /**
661
    /**
662
     * get_question_options only categorises a tag as a course tag if it is in a
662
     * get_question_options only categorises a tag as a course tag if it is in a
663
     * course context that is different from the question context.
663
     * course context that is different from the question context.
664
     */
664
     */
665
    public function test_get_question_options_course_tags_in_course_question_context() {
665
    public function test_get_question_options_course_tags_in_course_question_context(): void {
666
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('course');
666
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('course');
667
        $question1 = $questions[0];
667
        $question1 = $questions[0];
668
        $question2 = $questions[1];
668
        $question2 = $questions[1];
Línea 693... Línea 693...
693
 
693
 
694
    /**
694
    /**
695
     * get_question_options includes the tags and course tags for all questions in the list
695
     * get_question_options includes the tags and course tags for all questions in the list
696
     * if each question has course and question level tags.
696
     * if each question has course and question level tags.
697
     */
697
     */
698
    public function test_get_question_options_includes_question_and_course_tags() {
698
    public function test_get_question_options_includes_question_and_course_tags(): void {
699
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
699
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
700
        $question1 = $questions[0];
700
        $question1 = $questions[0];
701
        $question2 = $questions[1];
701
        $question2 = $questions[1];
702
        $qcontext = \context::instance_by_id($qcat->contextid);
702
        $qcontext = \context::instance_by_id($qcat->contextid);
Línea 745... Línea 745...
745
    /**
745
    /**
746
     * get_question_options should update the context id to the question category
746
     * get_question_options should update the context id to the question category
747
     * context id for any non-course context tag that isn't in the question category
747
     * context id for any non-course context tag that isn't in the question category
748
     * context.
748
     * context.
749
     */
749
     */
750
    public function test_get_question_options_normalises_question_tags() {
750
    public function test_get_question_options_normalises_question_tags(): void {
751
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
751
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
752
        $question1 = $questions[0];
752
        $question1 = $questions[0];
753
        $question2 = $questions[1];
753
        $question2 = $questions[1];
754
        $qcontext = \context::instance_by_id($qcat->contextid);
754
        $qcontext = \context::instance_by_id($qcat->contextid);
755
        $systemcontext = \context_system::instance();
755
        $systemcontext = \context_system::instance();
Línea 787... Línea 787...
787
 
787
 
788
    /**
788
    /**
789
     * get_question_options if the question is a course level question then tags
789
     * get_question_options if the question is a course level question then tags
790
     * in that context should not be consdered course tags, they are question tags.
790
     * in that context should not be consdered course tags, they are question tags.
791
     */
791
     */
792
    public function test_get_question_options_includes_course_context_question_tags() {
792
    public function test_get_question_options_includes_course_context_question_tags(): void {
793
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('course');
793
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('course');
794
        $question1 = $questions[0];
794
        $question1 = $questions[0];
795
        $question2 = $questions[1];
795
        $question2 = $questions[1];
Línea 816... Línea 816...
816
    }
816
    }
Línea 817... Línea 817...
817
 
817
 
818
    /**
818
    /**
819
     * get_question_options should return tags from all course contexts by default.
819
     * get_question_options should return tags from all course contexts by default.
820
     */
820
     */
821
    public function test_get_question_options_includes_multiple_courses_tags() {
821
    public function test_get_question_options_includes_multiple_courses_tags(): void {
822
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
822
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
823
        $question1 = $questions[0];
823
        $question1 = $questions[0];
824
        $question2 = $questions[1];
824
        $question2 = $questions[1];
825
        $coursecontext = \context_course::instance($course->id);
825
        $coursecontext = \context_course::instance($course->id);
Línea 849... Línea 849...
849
    }
849
    }
Línea 850... Línea 850...
850
 
850
 
851
    /**
851
    /**
852
     * get_question_options should filter the course tags by the given list of courses.
852
     * get_question_options should filter the course tags by the given list of courses.
853
     */
853
     */
854
    public function test_get_question_options_includes_filter_course_tags() {
854
    public function test_get_question_options_includes_filter_course_tags(): void {
855
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
855
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
856
        $question1 = $questions[0];
856
        $question1 = $questions[0];
857
        $question2 = $questions[1];
857
        $question2 = $questions[1];
858
        $coursecontext = \context_course::instance($course->id);
858
        $coursecontext = \context_course::instance($course->id);
Línea 882... Línea 882...
882
    /**
882
    /**
883
     * question_move_question_tags_to_new_context should update all of the
883
     * question_move_question_tags_to_new_context should update all of the
884
     * question tags contexts when they are moving down (from system to course
884
     * question tags contexts when they are moving down (from system to course
885
     * category context).
885
     * category context).
886
     */
886
     */
887
    public function test_question_move_question_tags_to_new_context_system_to_course_cat_qtags() {
887
    public function test_question_move_question_tags_to_new_context_system_to_course_cat_qtags(): void {
888
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('system');
888
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('system');
889
        $question1 = $questions[0];
889
        $question1 = $questions[0];
890
        $question2 = $questions[1];
890
        $question2 = $questions[1];
891
        $qcontext = \context::instance_by_id($qcat->contextid);
891
        $qcontext = \context::instance_by_id($qcat->contextid);
892
        $newcontext = \context_coursecat::instance($category->id);
892
        $newcontext = \context_coursecat::instance($category->id);
Línea 914... Línea 914...
914
    /**
914
    /**
915
     * question_move_question_tags_to_new_context should update all of the question tags
915
     * question_move_question_tags_to_new_context should update all of the question tags
916
     * contexts when they are moving down (from system to course category context)
916
     * contexts when they are moving down (from system to course category context)
917
     * but leave any tags in the course context where they are.
917
     * but leave any tags in the course context where they are.
918
     */
918
     */
919
    public function test_question_move_question_tags_to_new_context_system_to_course_cat_qtags_and_course_tags() {
919
    public function test_question_move_question_tags_to_new_context_system_to_course_cat_qtags_and_course_tags(): void {
920
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('system');
920
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('system');
921
        $question1 = $questions[0];
921
        $question1 = $questions[0];
922
        $question2 = $questions[1];
922
        $question2 = $questions[1];
923
        $qcontext = \context::instance_by_id($qcat->contextid);
923
        $qcontext = \context::instance_by_id($qcat->contextid);
924
        $coursecontext = \context_course::instance($course->id);
924
        $coursecontext = \context_course::instance($course->id);
Línea 954... Línea 954...
954
 
954
 
955
    /**
955
    /**
956
     * question_move_question_tags_to_new_context should update all of the question
956
     * question_move_question_tags_to_new_context should update all of the question
957
     * contexts tags when they are moving up (from course category to system context).
957
     * contexts tags when they are moving up (from course category to system context).
958
     */
958
     */
959
    public function test_question_move_question_tags_to_new_context_course_cat_to_system_qtags() {
959
    public function test_question_move_question_tags_to_new_context_course_cat_to_system_qtags(): void {
960
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
960
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
961
        $question1 = $questions[0];
961
        $question1 = $questions[0];
962
        $question2 = $questions[1];
962
        $question2 = $questions[1];
963
        $qcontext = \context::instance_by_id($qcat->contextid);
963
        $qcontext = \context::instance_by_id($qcat->contextid);
Línea 986... Línea 986...
986
    /**
986
    /**
987
     * question_move_question_tags_to_new_context should update all of the question
987
     * question_move_question_tags_to_new_context should update all of the question
988
     * tags contexts when they are moving up (from course category context to system
988
     * tags contexts when they are moving up (from course category context to system
989
     * context) but leave any tags in the course context where they are.
989
     * context) but leave any tags in the course context where they are.
990
     */
990
     */
991
    public function test_question_move_question_tags_to_new_context_course_cat_to_system_qtags_and_course_tags() {
991
    public function test_question_move_question_tags_to_new_context_course_cat_to_system_qtags_and_course_tags(): void {
992
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
992
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
993
        $question1 = $questions[0];
993
        $question1 = $questions[0];
994
        $question2 = $questions[1];
994
        $question2 = $questions[1];
995
        $qcontext = \context::instance_by_id($qcat->contextid);
995
        $qcontext = \context::instance_by_id($qcat->contextid);
996
        $coursecontext = \context_course::instance($course->id);
996
        $coursecontext = \context_course::instance($course->id);
Línea 1026... Línea 1026...
1026
 
1026
 
1027
    /**
1027
    /**
1028
     * question_move_question_tags_to_new_context should merge all tags into the course
1028
     * question_move_question_tags_to_new_context should merge all tags into the course
1029
     * context when moving down from course category context into course context.
1029
     * context when moving down from course category context into course context.
1030
     */
1030
     */
1031
    public function test_question_move_question_tags_to_new_context_course_cat_to_coures_qtags_and_course_tags() {
1031
    public function test_question_move_question_tags_to_new_context_course_cat_to_coures_qtags_and_course_tags(): void {
1032
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
1032
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
1033
        $question1 = $questions[0];
1033
        $question1 = $questions[0];
1034
        $question2 = $questions[1];
1034
        $question2 = $questions[1];
1035
        $qcontext = \context::instance_by_id($qcat->contextid);
1035
        $qcontext = \context::instance_by_id($qcat->contextid);
Línea 1065... Línea 1065...
1065
     * question_move_question_tags_to_new_context should delete all of the tag
1065
     * question_move_question_tags_to_new_context should delete all of the tag
1066
     * instances from sibling courses when moving the context of a question down
1066
     * instances from sibling courses when moving the context of a question down
1067
     * from a course category into a course context because the other courses will
1067
     * from a course category into a course context because the other courses will
1068
     * no longer have access to the question.
1068
     * no longer have access to the question.
1069
     */
1069
     */
1070
    public function test_question_move_question_tags_to_new_context_remove_other_course_tags() {
1070
    public function test_question_move_question_tags_to_new_context_remove_other_course_tags(): void {
1071
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
1071
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
1072
        // Create a sibling course.
1072
        // Create a sibling course.
1073
        $siblingcourse = $this->getDataGenerator()->create_course(['category' => $course->category]);
1073
        $siblingcourse = $this->getDataGenerator()->create_course(['category' => $course->category]);
1074
        $question1 = $questions[0];
1074
        $question1 = $questions[0];
1075
        $question2 = $questions[1];
1075
        $question2 = $questions[1];
Línea 1114... Línea 1114...
1114
    /**
1114
    /**
1115
     * question_move_question_tags_to_new_context should update all of the question
1115
     * question_move_question_tags_to_new_context should update all of the question
1116
     * tags to be the course category context when moving the tags from a course
1116
     * tags to be the course category context when moving the tags from a course
1117
     * context to a course category context.
1117
     * context to a course category context.
1118
     */
1118
     */
1119
    public function test_question_move_question_tags_to_new_context_course_to_course_cat() {
1119
    public function test_question_move_question_tags_to_new_context_course_to_course_cat(): void {
1120
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('course');
1120
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('course');
1121
        $question1 = $questions[0];
1121
        $question1 = $questions[0];
1122
        $question2 = $questions[1];
1122
        $question2 = $questions[1];
1123
        $qcontext = \context::instance_by_id($qcat->contextid);
1123
        $qcontext = \context::instance_by_id($qcat->contextid);
1124
        // Moving up into the course category context.
1124
        // Moving up into the course category context.
Línea 1147... Línea 1147...
1147
    /**
1147
    /**
1148
     * question_move_question_tags_to_new_context should update all of the
1148
     * question_move_question_tags_to_new_context should update all of the
1149
     * question tags contexts when they are moving down (from system to course
1149
     * question tags contexts when they are moving down (from system to course
1150
     * category context).
1150
     * category context).
1151
     */
1151
     */
1152
    public function test_question_move_question_tags_to_new_context_orphaned_tag_contexts() {
1152
    public function test_question_move_question_tags_to_new_context_orphaned_tag_contexts(): void {
1153
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('system');
1153
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('system');
1154
        $question1 = $questions[0];
1154
        $question1 = $questions[0];
1155
        $question2 = $questions[1];
1155
        $question2 = $questions[1];
1156
        $othercategory = $this->getDataGenerator()->create_category();
1156
        $othercategory = $this->getDataGenerator()->create_category();
1157
        $qcontext = \context::instance_by_id($qcat->contextid);
1157
        $qcontext = \context::instance_by_id($qcat->contextid);
Línea 1189... Línea 1189...
1189
    /**
1189
    /**
1190
     * When moving from a course category context down into an activity context
1190
     * When moving from a course category context down into an activity context
1191
     * all question context tags and course tags (where the course is a parent of
1191
     * all question context tags and course tags (where the course is a parent of
1192
     * the activity) should move into the new context.
1192
     * the activity) should move into the new context.
1193
     */
1193
     */
1194
    public function test_question_move_question_tags_to_new_context_course_cat_to_activity_qtags_and_course_tags() {
1194
    public function test_question_move_question_tags_to_new_context_course_cat_to_activity_qtags_and_course_tags(): void {
1195
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
1195
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
1196
        $question1 = $questions[0];
1196
        $question1 = $questions[0];
1197
        $question2 = $questions[1];
1197
        $question2 = $questions[1];
1198
        $qcontext = \context::instance_by_id($qcat->contextid);
1198
        $qcontext = \context::instance_by_id($qcat->contextid);
1199
        $coursecontext = \context_course::instance($course->id);
1199
        $coursecontext = \context_course::instance($course->id);
Línea 1228... Línea 1228...
1228
     * When moving from a course category context down into an activity context
1228
     * When moving from a course category context down into an activity context
1229
     * all question context tags and course tags (where the course is a parent of
1229
     * all question context tags and course tags (where the course is a parent of
1230
     * the activity) should move into the new context. Tags in course contexts
1230
     * the activity) should move into the new context. Tags in course contexts
1231
     * that are not a parent of the activity context should be deleted.
1231
     * that are not a parent of the activity context should be deleted.
1232
     */
1232
     */
1233
    public function test_question_move_question_tags_to_new_context_course_cat_to_activity_orphaned_tags() {
1233
    public function test_question_move_question_tags_to_new_context_course_cat_to_activity_orphaned_tags(): void {
1234
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
1234
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
1235
        $question1 = $questions[0];
1235
        $question1 = $questions[0];
1236
        $question2 = $questions[1];
1236
        $question2 = $questions[1];
1237
        $qcontext = \context::instance_by_id($qcat->contextid);
1237
        $qcontext = \context::instance_by_id($qcat->contextid);
1238
        $coursecontext = \context_course::instance($course->id);
1238
        $coursecontext = \context_course::instance($course->id);
Línea 1273... Línea 1273...
1273
 
1273
 
1274
    /**
1274
    /**
1275
     * When moving from a course context down into an activity context all of the
1275
     * When moving from a course context down into an activity context all of the
1276
     * course tags should move into the activity context.
1276
     * course tags should move into the activity context.
1277
     */
1277
     */
1278
    public function test_question_move_question_tags_to_new_context_course_to_activity_qtags() {
1278
    public function test_question_move_question_tags_to_new_context_course_to_activity_qtags(): void {
1279
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('course');
1279
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('course');
1280
        $question1 = $questions[0];
1280
        $question1 = $questions[0];
1281
        $question2 = $questions[1];
1281
        $question2 = $questions[1];
1282
        $qcontext = \context::instance_by_id($qcat->contextid);
1282
        $qcontext = \context::instance_by_id($qcat->contextid);
Línea 1303... Línea 1303...
1303
 
1303
 
1304
    /**
1304
    /**
1305
     * When moving from a course context down into an activity context all of the
1305
     * When moving from a course context down into an activity context all of the
1306
     * course tags should move into the activity context.
1306
     * course tags should move into the activity context.
1307
     */
1307
     */
1308
    public function test_question_move_question_tags_to_new_context_activity_to_course_qtags() {
1308
    public function test_question_move_question_tags_to_new_context_activity_to_course_qtags(): void {
1309
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions();
1309
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions();
1310
        $question1 = $questions[0];
1310
        $question1 = $questions[0];
1311
        $question2 = $questions[1];
1311
        $question2 = $questions[1];
1312
        $qcontext = \context::instance_by_id($qcat->contextid);
1312
        $qcontext = \context::instance_by_id($qcat->contextid);
Línea 1338... Línea 1338...
1338
     *
1338
     *
1339
     * Course tags within the new category context should remain while any course
1339
     * Course tags within the new category context should remain while any course
1340
     * tags in course contexts that can no longer access the question should be
1340
     * tags in course contexts that can no longer access the question should be
1341
     * deleted.
1341
     * deleted.
1342
     */
1342
     */
1343
    public function test_question_move_question_tags_to_new_context_system_to_course_cat_with_orphaned_tags() {
1343
    public function test_question_move_question_tags_to_new_context_system_to_course_cat_with_orphaned_tags(): void {
1344
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('system');
1344
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('system');
1345
        $question1 = $questions[0];
1345
        $question1 = $questions[0];
1346
        $question2 = $questions[1];
1346
        $question2 = $questions[1];
1347
        $othercategory = $this->getDataGenerator()->create_category();
1347
        $othercategory = $this->getDataGenerator()->create_category();
1348
        $othercourse = $this->getDataGenerator()->create_course(['category' => $othercategory->id]);
1348
        $othercourse = $this->getDataGenerator()->create_course(['category' => $othercategory->id]);
Línea 1391... Línea 1391...
1391
    }
1391
    }
Línea 1392... Línea 1392...
1392
 
1392
 
1393
    /**
1393
    /**
1394
     * question_sort_tags() includes the tags for all questions in the list.
1394
     * question_sort_tags() includes the tags for all questions in the list.
1395
     */
1395
     */
Línea 1396... Línea 1396...
1396
    public function test_question_sort_tags_includes_question_tags() {
1396
    public function test_question_sort_tags_includes_question_tags(): void {
1397
 
1397
 
1398
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
1398
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
1399
        $question1 = $questions[0];
1399
        $question1 = $questions[0];
Línea 1429... Línea 1429...
1429
    }
1429
    }
Línea 1430... Línea 1430...
1430
 
1430
 
1431
    /**
1431
    /**
1432
     * question_sort_tags() includes course tags for all questions in the list.
1432
     * question_sort_tags() includes course tags for all questions in the list.
1433
     */
1433
     */
1434
    public function test_question_sort_tags_includes_question_course_tags() {
1434
    public function test_question_sort_tags_includes_question_course_tags(): void {
Línea 1435... Línea 1435...
1435
        global $DB;
1435
        global $DB;
1436
 
1436
 
1437
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
1437
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
Línea 1468... Línea 1468...
1468
    }
1468
    }
Línea 1469... Línea 1469...
1469
 
1469
 
1470
    /**
1470
    /**
1471
     * question_sort_tags() should return tags from all course contexts by default.
1471
     * question_sort_tags() should return tags from all course contexts by default.
1472
     */
1472
     */
1473
    public function test_question_sort_tags_includes_multiple_courses_tags() {
1473
    public function test_question_sort_tags_includes_multiple_courses_tags(): void {
Línea 1474... Línea 1474...
1474
        global $DB;
1474
        global $DB;
1475
 
1475
 
1476
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
1476
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
Línea 1503... Línea 1503...
1503
    }
1503
    }
Línea 1504... Línea 1504...
1504
 
1504
 
1505
    /**
1505
    /**
1506
     * question_sort_tags() should filter the course tags by the given list of courses.
1506
     * question_sort_tags() should filter the course tags by the given list of courses.
1507
     */
1507
     */
1508
    public function test_question_sort_tags_includes_filter_course_tags() {
1508
    public function test_question_sort_tags_includes_filter_course_tags(): void {
Línea 1509... Línea 1509...
1509
        global $DB;
1509
        global $DB;
1510
 
1510
 
1511
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
1511
        list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
Línea 1658... Línea 1658...
1658
    }
1658
    }
Línea 1659... Línea 1659...
1659
 
1659
 
1660
    /**
1660
    /**
1661
     * Tests that question_has_capability_on does not throw exception on broken questions.
1661
     * Tests that question_has_capability_on does not throw exception on broken questions.
1662
     */
1662
     */
1663
    public function test_question_has_capability_on_broken_question() {
1663
    public function test_question_has_capability_on_broken_question(): void {
Línea 1664... Línea 1664...
1664
        global $DB;
1664
        global $DB;
1665
 
1665
 
1666
        // Create the test data.
1666
        // Create the test data.
Línea 1696... Línea 1696...
1696
     * @param   array   $capabilities The capability assignments to set.
1696
     * @param   array   $capabilities The capability assignments to set.
1697
     * @param   string  $capability The capability to test
1697
     * @param   string  $capability The capability to test
1698
     * @param   bool    $isowner Whether the user to create the question should be the owner or not.
1698
     * @param   bool    $isowner Whether the user to create the question should be the owner or not.
1699
     * @param   bool    $expect The expected result.
1699
     * @param   bool    $expect The expected result.
1700
     */
1700
     */
1701
    public function test_question_has_capability_on_using_stdClass($capabilities, $capability, $isowner, $expect) {
1701
    public function test_question_has_capability_on_using_stdClass($capabilities, $capability, $isowner, $expect): void {
1702
        $this->resetAfterTest();
1702
        $this->resetAfterTest();
Línea 1703... Línea 1703...
1703
 
1703
 
1704
        // Create the test data.
1704
        // Create the test data.
1705
        $user = $this->getDataGenerator()->create_user();
1705
        $user = $this->getDataGenerator()->create_user();
Línea 1740... Línea 1740...
1740
     * @param   array   $capabilities The capability assignments to set.
1740
     * @param   array   $capabilities The capability assignments to set.
1741
     * @param   string  $capability The capability to test
1741
     * @param   string  $capability The capability to test
1742
     * @param   bool    $isowner Whether the user to create the question should be the owner or not.
1742
     * @param   bool    $isowner Whether the user to create the question should be the owner or not.
1743
     * @param   bool    $expect The expected result.
1743
     * @param   bool    $expect The expected result.
1744
     */
1744
     */
1745
    public function test_question_has_capability_on_using_question_definition($capabilities, $capability, $isowner, $expect) {
1745
    public function test_question_has_capability_on_using_question_definition($capabilities, $capability, $isowner, $expect): void {
1746
        $this->resetAfterTest();
1746
        $this->resetAfterTest();
Línea 1747... Línea 1747...
1747
 
1747
 
1748
        // Create the test data.
1748
        // Create the test data.
1749
        $generator = $this->getDataGenerator();
1749
        $generator = $this->getDataGenerator();
Línea 1787... Línea 1787...
1787
     * @param   array   $capabilities The capability assignments to set.
1787
     * @param   array   $capabilities The capability assignments to set.
1788
     * @param   string  $capability The capability to test
1788
     * @param   string  $capability The capability to test
1789
     * @param   bool    $isowner Whether the user to create the question should be the owner or not.
1789
     * @param   bool    $isowner Whether the user to create the question should be the owner or not.
1790
     * @param   bool    $expect The expected result.
1790
     * @param   bool    $expect The expected result.
1791
     */
1791
     */
1792
    public function test_question_has_capability_on_using_question_id($capabilities, $capability, $isowner, $expect) {
1792
    public function test_question_has_capability_on_using_question_id($capabilities, $capability, $isowner, $expect): void {
1793
        $this->resetAfterTest();
1793
        $this->resetAfterTest();
Línea 1794... Línea 1794...
1794
 
1794
 
1795
        // Create the test data.
1795
        // Create the test data.
1796
        $generator = $this->getDataGenerator();
1796
        $generator = $this->getDataGenerator();
Línea 1834... Línea 1834...
1834
     * @param   array   $capabilities The capability assignments to set.
1834
     * @param   array   $capabilities The capability assignments to set.
1835
     * @param   string  $capability The capability to test
1835
     * @param   string  $capability The capability to test
1836
     * @param   bool    $isowner Whether the user to create the question should be the owner or not.
1836
     * @param   bool    $isowner Whether the user to create the question should be the owner or not.
1837
     * @param   bool    $expect The expected result.
1837
     * @param   bool    $expect The expected result.
1838
     */
1838
     */
1839
    public function test_question_has_capability_on_using_question_string_id($capabilities, $capability, $isowner, $expect) {
1839
    public function test_question_has_capability_on_using_question_string_id($capabilities, $capability, $isowner, $expect): void {
1840
        $this->resetAfterTest();
1840
        $this->resetAfterTest();
Línea 1841... Línea 1841...
1841
 
1841
 
1842
        // Create the test data.
1842
        // Create the test data.
1843
        $generator = $this->getDataGenerator();
1843
        $generator = $this->getDataGenerator();
Línea 1881... Línea 1881...
1881
     * @param   array   $capabilities The capability assignments to set.
1881
     * @param   array   $capabilities The capability assignments to set.
1882
     * @param   string  $capability The capability to test
1882
     * @param   string  $capability The capability to test
1883
     * @param   bool    $isowner Whether the user to create the question should be the owner or not.
1883
     * @param   bool    $isowner Whether the user to create the question should be the owner or not.
1884
     * @param   bool    $expect The expected result.
1884
     * @param   bool    $expect The expected result.
1885
     */
1885
     */
1886
    public function test_question_has_capability_on_using_moved_question($capabilities, $capability, $isowner, $expect) {
1886
    public function test_question_has_capability_on_using_moved_question($capabilities, $capability, $isowner, $expect): void {
1887
        $this->resetAfterTest();
1887
        $this->resetAfterTest();
Línea 1888... Línea 1888...
1888
 
1888
 
1889
        // Create the test data.
1889
        // Create the test data.
1890
        $generator = $this->getDataGenerator();
1890
        $generator = $this->getDataGenerator();
Línea 1938... Línea 1938...
1938
     * @param   array   $capabilities The capability assignments to set.
1938
     * @param   array   $capabilities The capability assignments to set.
1939
     * @param   string  $capability The capability to test
1939
     * @param   string  $capability The capability to test
1940
     * @param   bool    $isowner Whether the user to create the question should be the owner or not.
1940
     * @param   bool    $isowner Whether the user to create the question should be the owner or not.
1941
     * @param   bool    $expect The expected result.
1941
     * @param   bool    $expect The expected result.
1942
     */
1942
     */
1943
    public function test_question_has_capability_on_using_question($capabilities, $capability, $isowner, $expect) {
1943
    public function test_question_has_capability_on_using_question($capabilities, $capability, $isowner, $expect): void {
1944
        $this->resetAfterTest();
1944
        $this->resetAfterTest();
Línea 1945... Línea 1945...
1945
 
1945
 
1946
        // Create the test data.
1946
        // Create the test data.
1947
        $generator = $this->getDataGenerator();
1947
        $generator = $this->getDataGenerator();
Línea 1977... Línea 1977...
1977
    }
1977
    }
Línea 1978... Línea 1978...
1978
 
1978
 
1979
    /**
1979
    /**
1980
     * Tests that question_has_capability_on throws an exception for wrong parameter types.
1980
     * Tests that question_has_capability_on throws an exception for wrong parameter types.
1981
     */
1981
     */
1982
    public function test_question_has_capability_on_wrong_param_type() {
1982
    public function test_question_has_capability_on_wrong_param_type(): void {
1983
        // Create the test data.
1983
        // Create the test data.
1984
        $generator = $this->getDataGenerator();
1984
        $generator = $this->getDataGenerator();
1985
        /** @var \core_question_generator $questiongenerator */
1985
        /** @var \core_question_generator $questiongenerator */
1986
        $questiongenerator = $generator->get_plugin_generator('core_question');
1986
        $questiongenerator = $generator->get_plugin_generator('core_question');
Línea 2007... Línea 2007...
2007
        $this->expectExceptionMessage('$questionorid parameter needs to be an integer or an object.');
2007
        $this->expectExceptionMessage('$questionorid parameter needs to be an integer or an object.');
2008
        question_has_capability_on('one', 'tag');
2008
        question_has_capability_on('one', 'tag');
2009
    }
2009
    }
Línea 2010... Línea 2010...
2010
 
2010
 
-
 
2011
    /**
-
 
2012
     * Test question_has_capability_on with an invalid question ID
-
 
2013
     */
-
 
2014
    public function test_question_has_capability_on_invalid_question(): void {
-
 
2015
        try {
-
 
2016
            question_has_capability_on(42, 'tag');
-
 
2017
            $this->fail('Expected exception');
-
 
2018
        } catch (\moodle_exception $exception) {
-
 
2019
            $this->assertInstanceOf(\dml_missing_record_exception::class, $exception);
-
 
2020
 
-
 
2021
            // We also get debugging from initial attempt to load question data.
-
 
2022
            $this->assertDebuggingCalled();
-
 
2023
        }
-
 
2024
    }
-
 
2025
 
-
 
2026
    /**
-
 
2027
     * Test that question_has_capability_on does not fail when passed an object with a null
-
 
2028
     * createdby property.
-
 
2029
     */
-
 
2030
    public function test_question_has_capability_on_object_with_null_createdby(): void {
-
 
2031
        $this->resetAfterTest();
-
 
2032
        $generator = $this->getDataGenerator();
-
 
2033
        $user = $generator->create_user();
-
 
2034
        $category = $generator->create_category();
-
 
2035
        $context = \context_coursecat::instance($category->id);
-
 
2036
 
-
 
2037
        $role = $generator->create_role();
-
 
2038
        role_assign($role, $user->id, $context->id);
-
 
2039
        assign_capability('moodle/question:editmine', CAP_ALLOW, $role, $context->id);
-
 
2040
 
-
 
2041
        $this->setUser($user);
-
 
2042
 
-
 
2043
        $fakequestion = (object) [
-
 
2044
            'contextid' => $context->id,
-
 
2045
            'createdby' => null,
-
 
2046
        ];
-
 
2047
 
-
 
2048
        $this->assertFalse(question_has_capability_on($fakequestion, 'edit'));
-
 
2049
 
-
 
2050
        $fakequestion->createdby = $user->id;
-
 
2051
 
-
 
2052
        $this->assertTrue(question_has_capability_on($fakequestion, 'edit'));
-
 
2053
    }
-
 
2054
 
2011
    /**
2055
    /**
2012
     * Test of question_categorylist function.
2056
     * Test of question_categorylist function.
2013
     *
2057
     *
2014
     * @covers ::question_categorylist()
2058
     * @covers ::question_categorylist()
2015
     */
2059
     */
Línea 2152... Línea 2196...
2152
     *
2196
     *
2153
     * @dataProvider find_next_unused_idnumber_cases
2197
     * @dataProvider find_next_unused_idnumber_cases
2154
     * @param string|null $oldidnumber value to pass to core_question_find_next_unused_idnumber.
2198
     * @param string|null $oldidnumber value to pass to core_question_find_next_unused_idnumber.
2155
     * @param string|null $expectednewidnumber expected result.
2199
     * @param string|null $expectednewidnumber expected result.
2156
     */
2200
     */
2157
    public function test_core_question_find_next_unused_idnumber(?string $oldidnumber, ?string $expectednewidnumber) {
2201
    public function test_core_question_find_next_unused_idnumber(?string $oldidnumber, ?string $expectednewidnumber): void {
2158
        $this->assertSame($expectednewidnumber, core_question_find_next_unused_idnumber($oldidnumber, 0));
2202
        $this->assertSame($expectednewidnumber, core_question_find_next_unused_idnumber($oldidnumber, 0));
2159
    }
2203
    }
Línea 2160... Línea 2204...
2160
 
2204
 
2161
    public function test_core_question_find_next_unused_idnumber_skips_used() {
2205
    public function test_core_question_find_next_unused_idnumber_skips_used(): void {
Línea 2162... Línea 2206...
2162
        $this->resetAfterTest();
2206
        $this->resetAfterTest();
2163
 
2207
 
2164
        /** @var core_question_generator $generator */
2208
        /** @var core_question_generator $generator */
Línea 2177... Línea 2221...
2177
    /**
2221
    /**
2178
     * Tests for the question_move_questions_to_category function.
2222
     * Tests for the question_move_questions_to_category function.
2179
     *
2223
     *
2180
     * @covers ::question_move_questions_to_category
2224
     * @covers ::question_move_questions_to_category
2181
     */
2225
     */
2182
    public function test_question_move_questions_to_category() {
2226
    public function test_question_move_questions_to_category(): void {
2183
        $this->resetAfterTest();
2227
        $this->resetAfterTest();
Línea 2184... Línea 2228...
2184
 
2228
 
2185
        // Create the test data.
2229
        // Create the test data.
2186
        list($category1, $course1, $quiz1, $questioncat1, $questions1) = $this->setup_quiz_and_questions();
2230
        list($category1, $course1, $quiz1, $questioncat1, $questions1) = $this->setup_quiz_and_questions();
Línea 2201... Línea 2245...
2201
    /**
2245
    /**
2202
     * Tests for the idnumber_exist_in_question_category function.
2246
     * Tests for the idnumber_exist_in_question_category function.
2203
     *
2247
     *
2204
     * @covers ::idnumber_exist_in_question_category
2248
     * @covers ::idnumber_exist_in_question_category
2205
     */
2249
     */
2206
    public function test_idnumber_exist_in_question_category() {
2250
    public function test_idnumber_exist_in_question_category(): void {
2207
        global $DB;
2251
        global $DB;
Línea 2208... Línea 2252...
2208
 
2252
 
Línea 2209... Línea 2253...
2209
        $this->resetAfterTest();
2253
        $this->resetAfterTest();
Línea 2246... Línea 2290...
2246
     * Test method is_latest().
2290
     * Test method is_latest().
2247
     *
2291
     *
2248
     * @covers ::is_latest
2292
     * @covers ::is_latest
2249
     *
2293
     *
2250
     */
2294
     */
2251
    public function test_is_latest() {
2295
    public function test_is_latest(): void {
2252
        global $DB;
2296
        global $DB;
2253
        $this->resetAfterTest();
2297
        $this->resetAfterTest();
2254
        /** @var \core_question_generator $generator */
2298
        /** @var \core_question_generator $generator */
2255
        $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
2299
        $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
2256
        $qcat1 = $generator->create_question_category(['name' => 'My category', 'sortorder' => 1, 'idnumber' => 'myqcat']);
2300
        $qcat1 = $generator->create_question_category(['name' => 'My category', 'sortorder' => 1, 'idnumber' => 'myqcat']);
Línea 2265... Línea 2309...
2265
    /**
2309
    /**
2266
     * Test question bank entry deletion.
2310
     * Test question bank entry deletion.
2267
     *
2311
     *
2268
     * @covers ::delete_question_bank_entry
2312
     * @covers ::delete_question_bank_entry
2269
     */
2313
     */
2270
    public function test_delete_question_bank_entry() {
2314
    public function test_delete_question_bank_entry(): void {
2271
        global $DB;
2315
        global $DB;
2272
        $this->resetAfterTest();
2316
        $this->resetAfterTest();
2273
        // Setup.
2317
        // Setup.
2274
        $context = \context_system::instance();
2318
        $context = \context_system::instance();
2275
        /** @var \core_question_generator $qgen */
2319
        /** @var \core_question_generator $qgen */
Línea 2302... Línea 2346...
2302
    /**
2346
    /**
2303
     * Test question bank entry object.
2347
     * Test question bank entry object.
2304
     *
2348
     *
2305
     * @covers ::get_question_bank_entry
2349
     * @covers ::get_question_bank_entry
2306
     */
2350
     */
2307
    public function test_get_question_bank_entry() {
2351
    public function test_get_question_bank_entry(): void {
2308
        global $DB;
2352
        global $DB;
2309
        $this->resetAfterTest();
2353
        $this->resetAfterTest();
2310
        // Setup.
2354
        // Setup.
2311
        $context = \context_system::instance();
2355
        $context = \context_system::instance();
2312
        /** @var \core_question_generator $qgen */
2356
        /** @var \core_question_generator $qgen */
Línea 2332... Línea 2376...
2332
    /**
2376
    /**
2333
     * Test the version objects for a question.
2377
     * Test the version objects for a question.
2334
     *
2378
     *
2335
     * @covers ::get_question_version
2379
     * @covers ::get_question_version
2336
     */
2380
     */
2337
    public function test_get_question_version() {
2381
    public function test_get_question_version(): void {
2338
        global $DB;
2382
        global $DB;
2339
        $this->resetAfterTest();
2383
        $this->resetAfterTest();
2340
        // Setup.
2384
        // Setup.
2341
        $context = \context_system::instance();
2385
        $context = \context_system::instance();
2342
        /** @var \core_question_generator $qgen */
2386
        /** @var \core_question_generator $qgen */
Línea 2363... Línea 2407...
2363
    /**
2407
    /**
2364
     * Test get next version of a question.
2408
     * Test get next version of a question.
2365
     *
2409
     *
2366
     * @covers ::get_next_version
2410
     * @covers ::get_next_version
2367
     */
2411
     */
2368
    public function test_get_next_version() {
2412
    public function test_get_next_version(): void {
2369
        global $DB;
2413
        global $DB;
2370
        $this->resetAfterTest();
2414
        $this->resetAfterTest();
2371
        // Setup.
2415
        // Setup.
2372
        $context = \context_system::instance();
2416
        $context = \context_system::instance();
2373
        /** @var \core_question_generator $qgen */
2417
        /** @var \core_question_generator $qgen */