Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 62... Línea 62...
62
 * @package    core_course
62
 * @package    core_course
63
 * @category   test
63
 * @category   test
64
 * @copyright  2012 Petr Skoda {@link http://skodak.org}
64
 * @copyright  2012 Petr Skoda {@link http://skodak.org}
65
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
65
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
66
 */
66
 */
67
class courselib_test extends advanced_testcase {
67
final class courselib_test extends advanced_testcase {
Línea 68... Línea 68...
68
 
68
 
69
    /**
69
    /**
70
     * Load required libraries and fixtures.
70
     * Load required libraries and fixtures.
71
     */
71
     */
72
    public static function setUpBeforeClass(): void {
72
    public static function setUpBeforeClass(): void {
Línea 73... Línea 73...
73
        global $CFG;
73
        global $CFG;
74
 
74
 
-
 
75
        require_once($CFG->dirroot . '/course/tests/fixtures/course_capability_assignment.php');
75
        require_once($CFG->dirroot . '/course/tests/fixtures/course_capability_assignment.php');
76
        require_once($CFG->dirroot . '/enrol/imsenterprise/tests/imsenterprise_test.php');
Línea 76... Línea 77...
76
        require_once($CFG->dirroot . '/enrol/imsenterprise/tests/imsenterprise_test.php');
77
        parent::setUpBeforeClass();
77
    }
78
    }
78
 
79
 
Línea 635... Línea 636...
635
    /**
636
    /**
636
     * Data provider for course_delete module
637
     * Data provider for course_delete module
637
     *
638
     *
638
     * @return array An array of arrays contain test data
639
     * @return array An array of arrays contain test data
639
     */
640
     */
640
    public function provider_course_delete_module() {
641
    public static function provider_course_delete_module(): array {
641
        $data = array();
642
        $data = array();
Línea 642... Línea 643...
642
 
643
 
643
        $data['assign'] = array('assign', array('duedate' => time()));
644
        $data['assign'] = array('assign', array('duedate' => time()));
Línea 808... Línea 809...
808
    }
809
    }
Línea 809... Línea 810...
809
 
810
 
810
    /**
811
    /**
811
     * Relative dates mode settings provider for course creation.
812
     * Relative dates mode settings provider for course creation.
812
     */
813
     */
813
    public function create_course_relative_dates_provider() {
814
    public static function create_course_relative_dates_provider(): array {
814
        return [
815
        return [
815
            [0, 0, 0],
816
            [0, 0, 0],
816
            [0, 1, 0],
817
            [0, 1, 0],
817
            [1, 0, 0],
818
            [1, 0, 0],
Línea 877... Línea 878...
877
 
878
 
878
        // Trash modinfo.
879
        // Trash modinfo.
Línea 879... Línea 880...
879
        rebuild_course_cache($course->id, true);
880
        rebuild_course_cache($course->id, true);
-
 
881
 
-
 
882
        // Create some cms for testing.
880
 
883
        $mods = $DB->get_records('modules');
881
        // Create some cms for testing.
884
        $mod = reset($mods);
882
        $cmids = array();
885
        $cmids = array();
883
        for ($i=0; $i<4; $i++) {
886
        for ($i=0; $i<4; $i++) {
Línea 884... Línea 887...
884
            $cmids[$i] = $DB->insert_record('course_modules', array('course' => $course->id));
887
            $cmids[$i] = $DB->insert_record('course_modules', ['course' => $course->id, 'module' => $mod->id]);
885
        }
888
        }
Línea 886... Línea 889...
886
 
889
 
887
        // Add it to section that exists.
890
        // Add it to section that exists.
888
        course_add_cm_to_section($course, $cmids[0], 1);
891
        course_add_cm_to_section($course, $cmids[0], 1, null, $mod->name);
Línea 889... Línea 892...
889
 
892
 
890
        // Check it got added to sequence.
893
        // Check it got added to sequence.
891
        $sequence = $DB->get_field('course_sections', 'sequence', array('course' => $course->id, 'section' => 1));
894
        $sequence = $DB->get_field('course_sections', 'sequence', array('course' => $course->id, 'section' => 1));
892
        $this->assertEquals($cmids[0], $sequence);
895
        $this->assertEquals($cmids[0], $sequence);
893
 
896
 
Línea 894... Línea 897...
894
        // Add a second, this time using courseid variant of parameters.
897
        // Add a second, this time using courseid variant of parameters.
895
        $coursecacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
898
        $coursecacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
896
        course_add_cm_to_section($course->id, $cmids[1], 1);
899
        course_add_cm_to_section($course->id, $cmids[1], 1, null, $mod->name);
897
        $sequence = $DB->get_field('course_sections', 'sequence', array('course' => $course->id, 'section' => 1));
900
        $sequence = $DB->get_field('course_sections', 'sequence', array('course' => $course->id, 'section' => 1));
Línea 898... Línea 901...
898
        $this->assertEquals($cmids[0] . ',' . $cmids[1], $sequence);
901
        $this->assertEquals($cmids[0] . ',' . $cmids[1], $sequence);
899
 
902
 
900
        // Check that modinfo cache was reset but not rebuilt (important for performance if calling repeatedly).
903
        // Check that modinfo cache was reset but not rebuilt (important for performance if calling repeatedly).
901
        $newcacherev = $DB->get_field('course', 'cacherev', ['id' => $course->id]);
904
        $newcacherev = $DB->get_field('course', 'cacherev', ['id' => $course->id]);
902
        $this->assertGreaterThan($coursecacherev, $newcacherev);
905
        $this->assertGreaterThan($coursecacherev, $newcacherev);
Línea 903... Línea 906...
903
        $this->assertEmpty(cache::make('core', 'coursemodinfo')->get_versioned($course->id, $newcacherev));
906
        $this->assertEmpty(cache::make('core', 'coursemodinfo')->get_versioned($course->id, $newcacherev));
904
 
907
 
905
        // Add one to section that doesn't exist (this might rebuild modinfo).
908
        // Add one to section that doesn't exist (this might rebuild modinfo).
906
        course_add_cm_to_section($course, $cmids[2], 2);
909
        course_add_cm_to_section($course, $cmids[2], 2, null, $mod->name);
907
        $this->assertEquals(3, $DB->count_records('course_sections', array('course' => $course->id)));
910
        $this->assertEquals(3, $DB->count_records('course_sections', array('course' => $course->id)));
908
        $sequence = $DB->get_field('course_sections', 'sequence', array('course' => $course->id, 'section' => 2));
911
        $sequence = $DB->get_field('course_sections', 'sequence', array('course' => $course->id, 'section' => 2));
Línea -... Línea 912...
-
 
912
        $this->assertEquals($cmids[2], $sequence);
-
 
913
 
-
 
914
        // Add using the 'before' option.
-
 
915
        course_add_cm_to_section($course, $cmids[3], 2, $cmids[2], $mod->name);
-
 
916
        $this->assertEquals(3, $DB->count_records('course_sections', array('course' => $course->id)));
-
 
917
        $sequence = $DB->get_field('course_sections', 'sequence', array('course' => $course->id, 'section' => 2));
-
 
918
        $this->assertEquals($cmids[3] . ',' . $cmids[2], $sequence);
-
 
919
    }
-
 
920
 
-
 
921
    /**
-
 
922
     * Module types that have FEATURE_CAN_DISPLAY flag set to false cannot be in any section other than 0.
-
 
923
     *
-
 
924
     * @return void
-
 
925
     * @covers ::course_add_cm_to_section()
-
 
926
     */
-
 
927
    public function test_add_non_display_types_to_cm_section(): void {
-
 
928
        global $DB;
-
 
929
 
-
 
930
        $this->resetAfterTest(true);
-
 
931
        $generator = self::getDataGenerator();
-
 
932
 
-
 
933
        // Create course with 1 section.
-
 
934
        $course = self::getDataGenerator()->create_course(
-
 
935
            [
-
 
936
                'shortname' => 'GrowingCourse',
-
 
937
                'fullname' => 'Growing Course',
-
 
938
                'numsections' => 1,
-
 
939
            ],
-
 
940
            ['createsections' => true]
-
 
941
        );
-
 
942
 
-
 
943
        // Create the module and assert in section 0.
-
 
944
        $sectionzero = $DB->get_record('course_sections', ['course' => $course->id, 'section' => 0], '*', MUST_EXIST);
-
 
945
        $module = $generator->create_module('qbank', ['course' => $course, 'section' => $sectionzero->section]);
-
 
946
 
-
 
947
        // Try to add to section 1.
-
 
948
        $this->expectExceptionMessage("Modules with FEATURE_CAN_DISPLAY set to false can not be moved from section 0");
-
 
949
 
-
 
950
        try {
909
        $this->assertEquals($cmids[2], $sequence);
951
            course_add_cm_to_section($course, $module->cmid, 1, null, 'qbank');
910
 
952
        } finally {
911
        // Add using the 'before' option.
953
            // Assert still in section 0.
Línea 912... Línea 954...
912
        course_add_cm_to_section($course, $cmids[3], 2, $cmids[2]);
954
            $cm = $DB->get_record('course_modules', ['id' => $module->cmid]);
Línea 1319... Línea 1361...
1319
        $newsection = $DB->get_record('course_sections', array('id' => $newsection->id));
1361
        $newsection = $DB->get_record('course_sections', array('id' => $newsection->id));
1320
        $newsequences = explode(',', $newsection->sequence);
1362
        $newsequences = explode(',', $newsection->sequence);
1321
        $this->assertTrue(in_array($cm->id, $newsequences));
1363
        $this->assertTrue(in_array($cm->id, $newsequences));
1322
    }
1364
    }
Línea -... Línea 1365...
-
 
1365
 
-
 
1366
    /**
-
 
1367
     * Ensure that qbank module which has feature flag FEATURE_CAN_DISPLAY set to false cannot be moved from section 0.
-
 
1368
     *
-
 
1369
     * @return void
-
 
1370
     * @covers ::moveto_module()
-
 
1371
     */
-
 
1372
    public function test_move_feature_cannot_display(): void {
-
 
1373
        $this->resetAfterTest(true);
-
 
1374
        // Setup fixture.
-
 
1375
        $course = $this->getDataGenerator()->create_course(['numsections' => 5], ['createsections' => true]);
-
 
1376
        $qbank = $this->getDataGenerator()->create_module('qbank', ['course' => $course->id]);
-
 
1377
        $qbankcms = get_fast_modinfo($course)->get_instances_of('qbank');
-
 
1378
        $qbankcm = reset($qbankcms);
-
 
1379
 
-
 
1380
        // Check that mods with FEATURE_CAN_DISPLAY set to false cannot be moved from section 0.
-
 
1381
        $newsection = get_fast_modinfo($course)->get_section_info(3);
-
 
1382
 
-
 
1383
        $codingerror = "/ .* Modules with FEATURE_CAN_DISPLAY set to false can not be moved from section 0/";
-
 
1384
 
-
 
1385
        // Try to perform the move.
-
 
1386
        $this->expectExceptionMessageMatches($codingerror);
-
 
1387
        try {
-
 
1388
            moveto_module($qbankcm, $newsection);
-
 
1389
        } finally {
-
 
1390
            $qbankcms = get_fast_modinfo($course)->get_instances_of('qbank');
-
 
1391
            $qbankcm = reset($qbankcms);
-
 
1392
            $this->assertEquals(0, $qbankcm->sectionnum);
-
 
1393
        }
-
 
1394
    }
1323
 
1395
 
1324
    public function test_module_visibility(): void {
1396
    public function test_module_visibility(): void {
1325
        $this->setAdminUser();
1397
        $this->setAdminUser();
Línea 1326... Línea 1398...
1326
        $this->resetAfterTest(true);
1398
        $this->resetAfterTest(true);
Línea 1934... Línea 2006...
1934
        delete_course($course);
2006
        delete_course($course);
1935
        ob_end_clean();
2007
        ob_end_clean();
Línea 1936... Línea 2008...
1936
 
2008
 
1937
        // Create the XML file we want to use.
2009
        // Create the XML file we want to use.
-
 
2010
        $course->category = (array)$course->category;
-
 
2011
 
-
 
2012
        // Note: this is a violation of component communication principles.
1938
        $course->category = (array)$course->category;
2013
        // TODO MDL-83789.
1939
        $imstestcase = new imsenterprise_test();
2014
        $imstestcase = new imsenterprise_test('courselib_imsenterprise_test');
1940
        $imstestcase->imsplugin = enrol_get_plugin('imsenterprise');
2015
        $imstestcase->imsplugin = enrol_get_plugin('imsenterprise');
1941
        $imstestcase->set_test_config();
2016
        $imstestcase->set_test_config();
Línea 1942... Línea 2017...
1942
        $imstestcase->set_xml_file(false, array($course));
2017
        $imstestcase->set_xml_file(false, array($course));
Línea 3131... Línea 3206...
3131
        $newoverrides = $DB->get_records('role_assignments', ['contextid' => $newcmcontext->id]);
3206
        $newoverrides = $DB->get_records('role_assignments', ['contextid' => $newcmcontext->id]);
3132
        $this->assertEquals(count($overrides), count($newoverrides));
3207
        $this->assertEquals(count($overrides), count($newoverrides));
3133
    }
3208
    }
Línea 3134... Línea 3209...
3134
 
3209
 
-
 
3210
    /**
-
 
3211
     * Ensure that modules with the feature flag FEATURE_CAN_DISPLAY set to false cannot be duplicated into a section other than 0.
-
 
3212
     * @covers ::duplicate_module()
-
 
3213
     */
-
 
3214
    public function test_duplicate_cannot_display_mods(): void {
-
 
3215
        self::setAdminUser();
-
 
3216
        $this->resetAfterTest();
-
 
3217
        $course = self::getDataGenerator()->create_course(['numsections' => 2], ['createsections' => true]);
-
 
3218
        $res = self::getDataGenerator()->create_module('qbank', ['course' => $course]);
-
 
3219
        $cm = get_coursemodule_from_id('qbank', $res->cmid, 0, false, MUST_EXIST);
-
 
3220
        $sectionid = get_fast_modinfo($course)->get_section_info(1)->id;
-
 
3221
 
-
 
3222
        $this->expectExceptionMessage("Modules with FEATURE_CAN_DISPLAY set to false can not be moved from section 0");
-
 
3223
        duplicate_module($course, $cm, $sectionid);
-
 
3224
    }
-
 
3225
 
3135
    /**
3226
    /**
3136
     * Tests that when creating or updating a module, if the availability settings
3227
     * Tests that when creating or updating a module, if the availability settings
3137
     * are present but set to an empty tree, availability is set to null in
3228
     * are present but set to an empty tree, availability is set to null in
3138
     * database.
3229
     * database.
3139
     */
3230
     */
Línea 3557... Línea 3648...
3557
    /**
3648
    /**
3558
     * Provider for test_course_enddate.
3649
     * Provider for test_course_enddate.
3559
     *
3650
     *
3560
     * @return array
3651
     * @return array
3561
     */
3652
     */
3562
    public function course_enddate_provider() {
3653
    public static function course_enddate_provider(): array {
3563
        // Each provided example contains startdate, enddate and the expected exception error code if there is any.
3654
        // Each provided example contains startdate, enddate and the expected exception error code if there is any.
3564
        return [
3655
        return [
3565
            [
3656
            [
3566
                111,
3657
                111,
3567
                222,
3658
                222,
Línea 3639... Línea 3730...
3639
    /**
3730
    /**
3640
     * Provider for test_course_dates_reset.
3731
     * Provider for test_course_dates_reset.
3641
     *
3732
     *
3642
     * @return array
3733
     * @return array
3643
     */
3734
     */
3644
    public function course_dates_reset_provider() {
3735
    public static function course_dates_reset_provider(): array {
Línea 3645... Línea 3736...
3645
 
3736
 
3646
        // Each example contains the following:
3737
        // Each example contains the following:
3647
        // - course startdate
3738
        // - course startdate
3648
        // - course enddate
3739
        // - course enddate
Línea 3694... Línea 3785...
3694
                $time + DAYSECS,
3785
                $time + DAYSECS,
3695
                $time + WEEKSECS,
3786
                $time + WEEKSECS,
3696
                $time + YEARSECS,
3787
                $time + YEARSECS,
3697
                $time + WEEKSECS,
3788
                $time + WEEKSECS,
3698
                $time + YEARSECS
3789
                $time + YEARSECS
3699
            ]
3790
            ],
-
 
3791
            // Time shift is between exact times, not midnight(s) (MDL-65233).
-
 
3792
            [
-
 
3793
                $time + HOURSECS,
-
 
3794
                $time + DAYSECS,
-
 
3795
                $time + WEEKSECS + HOURSECS,
-
 
3796
                false,
-
 
3797
                $time + WEEKSECS + HOURSECS,
-
 
3798
                $time + WEEKSECS + DAYSECS,
-
 
3799
            ],
3700
        ];
3800
        ];
3701
    }
3801
    }
Línea 3702... Línea 3802...
3702
 
3802
 
3703
    /**
3803
    /**
Línea 4540... Línea 4640...
4540
    }
4640
    }
Línea 4541... Línea 4641...
4541
 
4641
 
4542
    /**
4642
    /**
4543
     * Test cases for the course_classify_courses_for_timeline test.
4643
     * Test cases for the course_classify_courses_for_timeline test.
4544
     */
4644
     */
4545
    public function get_course_classify_courses_for_timeline_test_cases() {
4645
    public static function get_course_classify_courses_for_timeline_test_cases(): array {
4546
        $now = time();
4646
        $now = time();
Línea 4547... Línea 4647...
4547
        $day = 86400;
4647
        $day = 86400;
4548
 
4648
 
Línea 4651... Línea 4751...
4651
    }
4751
    }
Línea 4652... Línea 4752...
4652
 
4752
 
4653
    /**
4753
    /**
4654
     * Test the course_classify_courses_for_timeline function.
4754
     * Test the course_classify_courses_for_timeline function.
4655
     *
4755
     *
4656
     * @dataProvider get_course_classify_courses_for_timeline_test_cases()
4756
     * @dataProvider get_course_classify_courses_for_timeline_test_cases
4657
     * @param array $coursesdata Courses to create
4757
     * @param array $coursesdata Courses to create
4658
     * @param array $expected Expected test results.
4758
     * @param array $expected Expected test results.
4659
     */
4759
     */
4660
    public function test_course_classify_courses_for_timeline($coursesdata, $expected): void {
4760
    public function test_course_classify_courses_for_timeline($coursesdata, $expected): void {
Línea 4693... Línea 4793...
4693
    }
4793
    }
Línea 4694... Línea 4794...
4694
 
4794
 
4695
    /**
4795
    /**
4696
     * Test cases for the course_get_enrolled_courses_for_logged_in_user tests.
4796
     * Test cases for the course_get_enrolled_courses_for_logged_in_user tests.
4697
     */
4797
     */
4698
    public function get_course_get_enrolled_courses_for_logged_in_user_test_cases() {
4798
    public static function get_course_get_enrolled_courses_for_logged_in_user_test_cases(): array {
4699
        $buildexpectedresult = function($limit, $offset) {
4799
        $buildexpectedresult = function($limit, $offset) {
4700
            $result = [];
4800
            $result = [];
4701
            for ($i = $offset; $i < $offset + $limit; $i++) {
4801
            for ($i = $offset; $i < $offset + $limit; $i++) {
4702
                $result[] = "testcourse{$i}";
4802
                $result[] = "testcourse{$i}";
Línea 4781... Línea 4881...
4781
    }
4881
    }
Línea 4782... Línea 4882...
4782
 
4882
 
4783
    /**
4883
    /**
4784
     * Test the course_get_enrolled_courses_for_logged_in_user function.
4884
     * Test the course_get_enrolled_courses_for_logged_in_user function.
4785
     *
4885
     *
4786
     * @dataProvider get_course_get_enrolled_courses_for_logged_in_user_test_cases()
4886
     * @dataProvider get_course_get_enrolled_courses_for_logged_in_user_test_cases
4787
     * @param int $dbquerylimit Number of records to load per DB request
4887
     * @param int $dbquerylimit Number of records to load per DB request
4788
     * @param int $totalcourses Number of courses to create
4888
     * @param int $totalcourses Number of courses to create
4789
     * @param int $limit Maximum number of results to get.
4889
     * @param int $limit Maximum number of results to get.
4790
     * @param int $offset Skip this number of results from the start of the result set.
4890
     * @param int $offset Skip this number of results from the start of the result set.
Línea 4829... Línea 4929...
4829
    }
4929
    }
Línea 4830... Línea 4930...
4830
 
4930
 
4831
    /**
4931
    /**
4832
     * Test cases for the course_filter_courses_by_timeline_classification tests.
4932
     * Test cases for the course_filter_courses_by_timeline_classification tests.
4833
     */
4933
     */
4834
    public function get_course_filter_courses_by_timeline_classification_test_cases() {
4934
    public static function get_course_filter_courses_by_timeline_classification_test_cases(): array {
4835
        $now = time();
4935
        $now = time();
Línea 4836... Línea 4936...
4836
        $day = 86400;
4936
        $day = 86400;
4837
 
4937
 
Línea 5079... Línea 5179...
5079
    }
5179
    }
Línea 5080... Línea 5180...
5080
 
5180
 
5081
    /**
5181
    /**
5082
     * Test the course_filter_courses_by_timeline_classification function.
5182
     * Test the course_filter_courses_by_timeline_classification function.
5083
     *
5183
     *
5084
     * @dataProvider get_course_filter_courses_by_timeline_classification_test_cases()
5184
     * @dataProvider get_course_filter_courses_by_timeline_classification_test_cases
5085
     * @param array $coursedata Course test data to create.
5185
     * @param array $coursedata Course test data to create.
5086
     * @param string $classification Timeline classification.
5186
     * @param string $classification Timeline classification.
5087
     * @param int $limit Maximum number of results to return.
5187
     * @param int $limit Maximum number of results to return.
5088
     * @param int $offset Results to skip at the start of the result set.
5188
     * @param int $offset Results to skip at the start of the result set.
Línea 5128... Línea 5228...
5128
    }
5228
    }
Línea 5129... Línea 5229...
5129
 
5229
 
5130
    /**
5230
    /**
5131
     * Test cases for the course_filter_courses_by_timeline_classification tests.
5231
     * Test cases for the course_filter_courses_by_timeline_classification tests.
5132
     */
5232
     */
5133
    public function get_course_filter_courses_by_customfield_test_cases() {
5233
    public static function get_course_filter_courses_by_customfield_test_cases(): array {
5134
        global $CFG;
5234
        global $CFG;
5135
        require_once($CFG->dirroot.'/blocks/myoverview/lib.php');
5235
        require_once($CFG->dirroot.'/blocks/myoverview/lib.php');
5136
        $coursedata = [
5236
        $coursedata = [
5137
            [
5237
            [
Línea 5298... Línea 5398...
5298
    }
5398
    }
Línea 5299... Línea 5399...
5299
 
5399
 
5300
    /**
5400
    /**
5301
     * Test the course_filter_courses_by_customfield function.
5401
     * Test the course_filter_courses_by_customfield function.
5302
     *
5402
     *
5303
     * @dataProvider get_course_filter_courses_by_customfield_test_cases()
5403
     * @dataProvider get_course_filter_courses_by_customfield_test_cases
5304
     * @param array $coursedata Course test data to create.
5404
     * @param array $coursedata Course test data to create.
5305
     * @param string $customfield Shortname of the customfield.
5405
     * @param string $customfield Shortname of the customfield.
5306
     * @param string $customfieldvalue the value to filter by.
5406
     * @param string $customfieldvalue the value to filter by.
5307
     * @param int $limit Maximum number of results to return.
5407
     * @param int $limit Maximum number of results to return.
Línea 5384... Línea 5484...
5384
    }
5484
    }
Línea 5385... Línea 5485...
5385
 
5485
 
5386
    /**
5486
    /**
5387
     * Test cases for the course_filter_courses_by_timeline_classification w/ hidden courses tests.
5487
     * Test cases for the course_filter_courses_by_timeline_classification w/ hidden courses tests.
5388
     */
5488
     */
5389
    public function get_course_filter_courses_by_timeline_classification_hidden_courses_test_cases() {
5489
    public static function get_course_filter_courses_by_timeline_classification_hidden_courses_test_cases(): array {
5390
        $now = time();
5490
        $now = time();
Línea 5391... Línea 5491...
5391
        $day = 86400;
5491
        $day = 86400;
5392
 
5492
 
Línea 5543... Línea 5643...
5543
    }
5643
    }
Línea 5544... Línea 5644...
5544
 
5644
 
5545
    /**
5645
    /**
5546
     * Test the course_filter_courses_by_timeline_classification function hidden courses.
5646
     * Test the course_filter_courses_by_timeline_classification function hidden courses.
5547
     *
5647
     *
5548
     * @dataProvider get_course_filter_courses_by_timeline_classification_hidden_courses_test_cases()
5648
     * @dataProvider get_course_filter_courses_by_timeline_classification_hidden_courses_test_cases
5549
     * @param array $coursedata Course test data to create.
5649
     * @param array $coursedata Course test data to create.
5550
     * @param string $classification Timeline classification.
5650
     * @param string $classification Timeline classification.
5551
     * @param int $limit Maximum number of results to return.
5651
     * @param int $limit Maximum number of results to return.
5552
     * @param int $offset Results to skip at the start of the result set.
5652
     * @param int $offset Results to skip at the start of the result set.
Línea 5753... Línea 5853...
5753
    /**
5853
    /**
5754
     * Data provider for test_course_get_recent_courses_sort_validation().
5854
     * Data provider for test_course_get_recent_courses_sort_validation().
5755
     *
5855
     *
5756
     * @return array
5856
     * @return array
5757
     */
5857
     */
5758
    function course_get_recent_courses_sort_validation_provider() {
5858
    public static function course_get_recent_courses_sort_validation_provider(): array {
5759
        return [
5859
        return [
5760
            'Invalid sort format (SQL injection attempt)' =>
5860
            'Invalid sort format (SQL injection attempt)' =>
5761
                [
5861
                [
5762
                    'shortname DESC LIMIT 1--',
5862
                    'shortname DESC LIMIT 1--',
5763
                    'Invalid structure of the sort parameter, allowed structure: fieldname [ASC|DESC].',
5863
                    'Invalid structure of the sort parameter, allowed structure: fieldname [ASC|DESC].',
Línea 5827... Línea 5927...
5827
    }
5927
    }
Línea 5828... Línea 5928...
5828
 
5928
 
5829
    /**
5929
    /**
5830
     * Test cases for the course_get_course_dates_for_user_ids tests.
5930
     * Test cases for the course_get_course_dates_for_user_ids tests.
5831
     */
5931
     */
5832
    public function get_course_get_course_dates_for_user_ids_test_cases() {
5932
    public static function get_course_get_course_dates_for_user_ids_test_cases(): array {
5833
        $now = time();
5933
        $now = time();
5834
        $pastcoursestart = $now - 100;
5934
        $pastcoursestart = $now - 100;
Línea 5835... Línea 5935...
5835
        $futurecoursestart = $now + 100;
5935
        $futurecoursestart = $now + 100;
Línea 7041... Línea 7141...
7041
    }
7141
    }
Línea 7042... Línea 7142...
7042
 
7142
 
7043
    /**
7143
    /**
7044
     * Test the course_get_course_dates_for_user_ids function.
7144
     * Test the course_get_course_dates_for_user_ids function.
7045
     *
7145
     *
7046
     * @dataProvider get_course_get_course_dates_for_user_ids_test_cases()
7146
     * @dataProvider get_course_get_course_dates_for_user_ids_test_cases
7047
     * @param bool $relativedatemode Set the course to relative dates mode
7147
     * @param bool $relativedatemode Set the course to relative dates mode
7048
     * @param int $coursestart Course start date
7148
     * @param int $coursestart Course start date
7049
     * @param int $usercount Number of users to create
7149
     * @param int $usercount Number of users to create
7050
     * @param array $enrolmentmethods Enrolment methods to set for the course
7150
     * @param array $enrolmentmethods Enrolment methods to set for the course
Línea 7134... Línea 7234...
7134
    /**
7234
    /**
7135
     * Data provider for test_course_modules_pending_deletion.
7235
     * Data provider for test_course_modules_pending_deletion.
7136
     *
7236
     *
7137
     * @return array An array of arrays contain test data
7237
     * @return array An array of arrays contain test data
7138
     */
7238
     */
7139
    public function provider_course_modules_pending_deletion() {
7239
    public static function provider_course_modules_pending_deletion(): array {
7140
        return [
7240
        return [
7141
            'Non-gradable activity, check all'              => [['forum'], 0, false, true],
7241
            'Non-gradable activity, check all'              => [['forum'], 0, false, true],
7142
            'Gradable activity, check all'                  => [['assign'], 0, false, true],
7242
            'Gradable activity, check all'                  => [['assign'], 0, false, true],
7143
            'Non-gradable activity, check gradables'        => [['forum'], 0, true, false],
7243
            'Non-gradable activity, check gradables'        => [['forum'], 0, true, false],
7144
            'Gradable activity, check gradables'            => [['assign'], 0, true, true],
7244
            'Gradable activity, check gradables'            => [['assign'], 0, true, true],
Línea 7499... Línea 7599...
7499
        $this->assertInstanceOf('\core\event\section_viewed', $event);
7599
        $this->assertInstanceOf('\core\event\section_viewed', $event);
7500
        $this->assertEquals(context_course::instance($course->id), $event->get_context());
7600
        $this->assertEquals(context_course::instance($course->id), $event->get_context());
7501
        $this->assertEquals('course_sections', $event->objecttable);
7601
        $this->assertEquals('course_sections', $event->objecttable);
7502
        $this->assertEquals($section->id, $event->objectid);
7602
        $this->assertEquals($section->id, $event->objectid);
7503
    }
7603
    }
-
 
7604
 
-
 
7605
    /**
-
 
7606
     * Tests get_sorted_course_formats returns plugins in cases where plugins are
-
 
7607
     * installed previously but no longer exist, or not installed yet.
-
 
7608
     *
-
 
7609
     * @covers ::get_sorted_course_formats()
-
 
7610
     */
-
 
7611
    public function test_get_sorted_course_formats_installed_or_not(): void {
-
 
7612
        global $DB;
-
 
7613
 
-
 
7614
        $this->resetAfterTest();
-
 
7615
 
-
 
7616
        // If there is an extra format installed that no longer exists, include in list (at end).
-
 
7617
        $DB->insert_record('config_plugins', [
-
 
7618
            'plugin' => 'format_frogs',
-
 
7619
            'name' => 'version',
-
 
7620
            'value' => '20240916',
-
 
7621
        ]);
-
 
7622
        \core\plugin_manager::reset_caches();
-
 
7623
        $formats = get_sorted_course_formats();
-
 
7624
        $this->assertContains('frogs', $formats);
-
 
7625
 
-
 
7626
        // If one of the formats is not installed yet, we still return it.
-
 
7627
        $DB->delete_records('config_plugins', ['plugin' => 'format_weeks']);
-
 
7628
        \core\plugin_manager::reset_caches();
-
 
7629
        $formats = get_sorted_course_formats();
-
 
7630
        $this->assertContains('weeks', $formats);
-
 
7631
    }
7504
}
7632
}