Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 36... Línea 36...
36
 * @copyright  2012 Petr Skoda {@link http://skodak.org}
36
 * @copyright  2012 Petr Skoda {@link http://skodak.org}
37
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
38
 */
39
class enrollib_test extends advanced_testcase {
39
class enrollib_test extends advanced_testcase {
Línea 40... Línea 40...
40
 
40
 
41
    public function test_enrol_get_all_users_courses() {
41
    public function test_enrol_get_all_users_courses(): void {
Línea 42... Línea 42...
42
        global $DB, $CFG;
42
        global $DB, $CFG;
Línea 43... Línea 43...
43
 
43
 
Línea 232... Línea 232...
232
 
232
 
233
    /**
233
    /**
234
     * Test enrol_course_delete() without passing a user id. When a value for user id is not present, the method
234
     * Test enrol_course_delete() without passing a user id. When a value for user id is not present, the method
235
     * should delete all enrolment related data in the course.
235
     * should delete all enrolment related data in the course.
236
     */
236
     */
237
    public function test_enrol_course_delete_without_userid() {
237
    public function test_enrol_course_delete_without_userid(): void {
Línea 238... Línea 238...
238
        global $DB;
238
        global $DB;
Línea 239... Línea 239...
239
 
239
 
Línea 295... Línea 295...
295
     *
295
     *
296
     * @dataProvider enrol_course_delete_with_userid_provider
296
     * @dataProvider enrol_course_delete_with_userid_provider
297
     * @param array $excludedcapabilities The capabilities that should be excluded from the user's role
297
     * @param array $excludedcapabilities The capabilities that should be excluded from the user's role
298
     * @param bool $expected The expected results
298
     * @param bool $expected The expected results
299
     */
299
     */
300
    public function test_enrol_course_delete_with_userid($excludedcapabilities, $expected) {
300
    public function test_enrol_course_delete_with_userid($excludedcapabilities, $expected): void {
301
        global $DB;
301
        global $DB;
Línea 302... Línea 302...
302
 
302
 
303
        $this->resetAfterTest();
303
        $this->resetAfterTest();
304
        // Create users.
304
        // Create users.
Línea 441... Línea 441...
441
                ],
441
                ],
442
        ];
442
        ];
443
    }
443
    }
Línea 444... Línea 444...
444
 
444
 
445
 
445
 
Línea 446... Línea 446...
446
    public function test_enrol_user_sees_own_courses() {
446
    public function test_enrol_user_sees_own_courses(): void {
Línea 447... Línea 447...
447
        global $DB, $CFG;
447
        global $DB, $CFG;
Línea 540... Línea 540...
540
        $reads = $DB->perf_get_reads();
540
        $reads = $DB->perf_get_reads();
541
        $this->assertTrue(enrol_user_sees_own_courses());
541
        $this->assertTrue(enrol_user_sees_own_courses());
542
        $this->assertEquals($reads, $DB->perf_get_reads());
542
        $this->assertEquals($reads, $DB->perf_get_reads());
543
    }
543
    }
Línea 544... Línea 544...
544
 
544
 
545
    public function test_enrol_get_shared_courses() {
545
    public function test_enrol_get_shared_courses(): void {
Línea 546... Línea 546...
546
        $this->resetAfterTest();
546
        $this->resetAfterTest();
547
 
547
 
548
        $user1 = $this->getDataGenerator()->create_user();
548
        $user1 = $this->getDataGenerator()->create_user();
Línea 569... Línea 569...
569
        $sharedcourse = array_shift($sharedcourses);
569
        $sharedcourse = array_shift($sharedcourses);
570
        // It should be course 1.
570
        // It should be course 1.
571
        $this->assertEquals($sharedcourse->id, $course1->id);
571
        $this->assertEquals($sharedcourse->id, $course1->id);
572
    }
572
    }
Línea 573... Línea 573...
573
 
573
 
574
    public function test_enrol_get_shared_courses_different_methods() {
574
    public function test_enrol_get_shared_courses_different_methods(): void {
Línea 575... Línea 575...
575
        global $DB, $CFG;
575
        global $DB, $CFG;
Línea 576... Línea 576...
576
 
576
 
Línea 628... Línea 628...
628
    }
628
    }
Línea 629... Línea 629...
629
 
629
 
630
    /**
630
    /**
631
     * Test user enrolment created event.
631
     * Test user enrolment created event.
632
     */
632
     */
633
    public function test_user_enrolment_created_event() {
633
    public function test_user_enrolment_created_event(): void {
Línea 634... Línea 634...
634
        global $DB;
634
        global $DB;
Línea 635... Línea 635...
635
 
635
 
Línea 662... Línea 662...
662
    }
662
    }
Línea 663... Línea 663...
663
 
663
 
664
    /**
664
    /**
665
     * Test user_enrolment_deleted event.
665
     * Test user_enrolment_deleted event.
666
     */
666
     */
667
    public function test_user_enrolment_deleted_event() {
667
    public function test_user_enrolment_deleted_event(): void {
Línea 668... Línea 668...
668
        global $DB;
668
        global $DB;
Línea 669... Línea 669...
669
 
669
 
Línea 696... Línea 696...
696
    }
696
    }
Línea 697... Línea 697...
697
 
697
 
698
    /**
698
    /**
699
     * Test enrol_instance_created, enrol_instance_updated and enrol_instance_deleted events.
699
     * Test enrol_instance_created, enrol_instance_updated and enrol_instance_deleted events.
700
     */
700
     */
701
    public function test_instance_events() {
701
    public function test_instance_events(): void {
Línea 702... Línea 702...
702
        global $DB;
702
        global $DB;
Línea 703... Línea 703...
703
 
703
 
Línea 756... Línea 756...
756
    }
756
    }
Línea 757... Línea 757...
757
 
757
 
758
    /**
758
    /**
759
     * Confirms that timemodified field was updated after modification of user enrollment
759
     * Confirms that timemodified field was updated after modification of user enrollment
760
     */
760
     */
761
    public function test_enrollment_update_timemodified() {
761
    public function test_enrollment_update_timemodified(): void {
Línea 762... Línea 762...
762
        global $DB;
762
        global $DB;
763
 
763
 
Línea 811... Línea 811...
811
 
811
 
812
    /**
812
    /**
813
     * Test to confirm that enrol_get_my_courses only return the courses that
813
     * Test to confirm that enrol_get_my_courses only return the courses that
814
     * the logged in user is enrolled in.
814
     * the logged in user is enrolled in.
815
     */
815
     */
816
    public function test_enrol_get_my_courses_only_enrolled_courses() {
816
    public function test_enrol_get_my_courses_only_enrolled_courses(): void {
817
        $user = $this->getDataGenerator()->create_user();
817
        $user = $this->getDataGenerator()->create_user();
818
        $course1 = $this->getDataGenerator()->create_course();
818
        $course1 = $this->getDataGenerator()->create_course();
819
        $course2 = $this->getDataGenerator()->create_course();
819
        $course2 = $this->getDataGenerator()->create_course();
820
        $course3 = $this->getDataGenerator()->create_course();
820
        $course3 = $this->getDataGenerator()->create_course();
Línea 859... Línea 859...
859
     * should remove any courses hidden from the user's timeline
859
     * should remove any courses hidden from the user's timeline
860
     *
860
     *
861
     * @throws coding_exception
861
     * @throws coding_exception
862
     * @throws dml_exception
862
     * @throws dml_exception
863
     */
863
     */
864
    public function test_enrol_get_my_courses_include_hidden() {
864
    public function test_enrol_get_my_courses_include_hidden(): void {
865
        global $DB, $CFG;
865
        global $DB, $CFG;
Línea 866... Línea 866...
866
 
866
 
Línea 867... Línea 867...
867
        $this->resetAfterTest(true);
867
        $this->resetAfterTest(true);
Línea 910... Línea 910...
910
 
910
 
911
    /**
911
    /**
912
     * Tests the enrol_get_my_courses function when using the $allaccessible parameter, which
912
     * Tests the enrol_get_my_courses function when using the $allaccessible parameter, which
913
     * includes a wider range of courses (enrolled courses + other accessible ones).
913
     * includes a wider range of courses (enrolled courses + other accessible ones).
914
     */
914
     */
915
    public function test_enrol_get_my_courses_all_accessible() {
915
    public function test_enrol_get_my_courses_all_accessible(): void {
Línea 916... Línea 916...
916
        global $DB, $CFG;
916
        global $DB, $CFG;
Línea 917... Línea 917...
917
 
917
 
Línea 1079... Línea 1079...
1079
    /**
1079
    /**
1080
     * test_course_users
1080
     * test_course_users
1081
     *
1081
     *
1082
     * @return void
1082
     * @return void
1083
     */
1083
     */
1084
    public function test_course_users() {
1084
    public function test_course_users(): void {
1085
        $this->resetAfterTest();
1085
        $this->resetAfterTest();
Línea 1086... Línea 1086...
1086
 
1086
 
1087
        $user1 = $this->getDataGenerator()->create_user();
1087
        $user1 = $this->getDataGenerator()->create_user();
1088
        $user2 = $this->getDataGenerator()->create_user();
1088
        $user2 = $this->getDataGenerator()->create_user();
Línea 1113... Línea 1113...
1113
     * test_course_users in groups
1113
     * test_course_users in groups
1114
     *
1114
     *
1115
     * @covers \enrol_get_course_users()
1115
     * @covers \enrol_get_course_users()
1116
     * @return void
1116
     * @return void
1117
     */
1117
     */
1118
    public function test_course_users_in_groups() {
1118
    public function test_course_users_in_groups(): void {
1119
        $this->resetAfterTest();
1119
        $this->resetAfterTest();
Línea 1120... Línea 1120...
1120
 
1120
 
1121
        $user1 = $this->getDataGenerator()->create_user();
1121
        $user1 = $this->getDataGenerator()->create_user();
1122
        $user2 = $this->getDataGenerator()->create_user();
1122
        $user2 = $this->getDataGenerator()->create_user();
Línea 1149... Línea 1149...
1149
    /**
1149
    /**
1150
     * Test count of enrolled users
1150
     * Test count of enrolled users
1151
     *
1151
     *
1152
     * @return void
1152
     * @return void
1153
     */
1153
     */
1154
    public function test_count_enrolled_users() {
1154
    public function test_count_enrolled_users(): void {
1155
        global $DB;
1155
        global $DB;
Línea 1156... Línea 1156...
1156
 
1156
 
Línea 1157... Línea 1157...
1157
        $this->resetAfterTest(true);
1157
        $this->resetAfterTest(true);
Línea 1306... Línea 1306...
1306
        $unenrolledcoursesdata,
1306
        $unenrolledcoursesdata,
1307
        $sort,
1307
        $sort,
1308
        $limit,
1308
        $limit,
1309
        $offset,
1309
        $offset,
1310
        $expectedcourses
1310
        $expectedcourses
1311
    ) {
1311
    ): void {
1312
        global $DB, $CFG;
1312
        global $DB, $CFG;
Línea 1313... Línea 1313...
1313
 
1313
 
1314
        $this->resetAfterTest();
1314
        $this->resetAfterTest();
1315
        $generator = $this->getDataGenerator();
1315
        $generator = $this->getDataGenerator();
Línea 1372... Línea 1372...
1372
    /**
1372
    /**
1373
     * Test enrol_get_course_users_roles function.
1373
     * Test enrol_get_course_users_roles function.
1374
     *
1374
     *
1375
     * @return void
1375
     * @return void
1376
     */
1376
     */
1377
    public function test_enrol_get_course_users_roles() {
1377
    public function test_enrol_get_course_users_roles(): void {
1378
        global $DB;
1378
        global $DB;
Línea 1379... Línea 1379...
1379
 
1379
 
Línea 1380... Línea 1380...
1380
        $this->resetAfterTest();
1380
        $this->resetAfterTest();
Línea 1422... Línea 1422...
1422
    }
1422
    }
Línea 1423... Línea 1423...
1423
 
1423
 
1424
    /**
1424
    /**
1425
     * Test enrol_calculate_duration function
1425
     * Test enrol_calculate_duration function
1426
     */
1426
     */
1427
    public function test_enrol_calculate_duration() {
1427
    public function test_enrol_calculate_duration(): void {
1428
        // Start time 07/01/2019 @ 12:00am (UTC).
1428
        // Start time 07/01/2019 @ 12:00am (UTC).
1429
        $timestart = 1561939200;
1429
        $timestart = 1561939200;
1430
        // End time 07/05/2019 @ 12:00am (UTC).
1430
        // End time 07/05/2019 @ 12:00am (UTC).
1431
        $timeend = 1562284800;
1431
        $timeend = 1562284800;
Línea 1452... Línea 1452...
1452
    public function test_get_enrolled_with_capabilities_join_cannotmatchanyrows(
1452
    public function test_get_enrolled_with_capabilities_join_cannotmatchanyrows(
1453
        string $capability,
1453
        string $capability,
1454
        bool $useprohibit,
1454
        bool $useprohibit,
1455
        int $expectedmatch,
1455
        int $expectedmatch,
1456
        int $expectedcount
1456
        int $expectedcount
1457
    ) {
1457
    ): void {
1458
        global $DB, $CFG;
1458
        global $DB, $CFG;
Línea 1459... Línea 1459...
1459
 
1459
 
Línea 1460... Línea 1460...
1460
        $this->resetAfterTest();
1460
        $this->resetAfterTest();
Línea 1515... Línea 1515...
1515
 
1515
 
1516
    /**
1516
    /**
1517
     * Test last_time_enrolments_synced not recorded with "force" option for enrol_check_plugins.
1517
     * Test last_time_enrolments_synced not recorded with "force" option for enrol_check_plugins.
1518
     * @covers ::enrol_check_plugins
1518
     * @covers ::enrol_check_plugins
1519
     */
1519
     */
1520
    public function test_enrol_check_plugins_with_forced_option() {
1520
    public function test_enrol_check_plugins_with_forced_option(): void {
1521
        $this->resetAfterTest();
1521
        $this->resetAfterTest();
Línea 1522... Línea 1522...
1522
        $user = $this->getDataGenerator()->create_user();
1522
        $user = $this->getDataGenerator()->create_user();
1523
 
1523
 
Línea 1546... Línea 1546...
1546
     * @dataProvider empty_config_data_provider
1546
     * @dataProvider empty_config_data_provider
1547
     * @covers ::enrol_check_plugins
1547
     * @covers ::enrol_check_plugins
1548
     *
1548
     *
1549
     * @param mixed $config Config value.
1549
     * @param mixed $config Config value.
1550
     */
1550
     */
1551
    public function test_enrol_check_plugins_with_empty_config_value($config) {
1551
    public function test_enrol_check_plugins_with_empty_config_value($config): void {
1552
        global $CFG;
1552
        global $CFG;
Línea 1553... Línea 1553...
1553
 
1553
 
1554
        $this->resetAfterTest();
1554
        $this->resetAfterTest();
1555
        $CFG->enrolments_sync_interval = $config;
1555
        $CFG->enrolments_sync_interval = $config;
Línea 1562... Línea 1562...
1562
 
1562
 
1563
    /**
1563
    /**
1564
     * Test last_time_enrolments_synced is recorded without "force" option for enrol_check_plugins.
1564
     * Test last_time_enrolments_synced is recorded without "force" option for enrol_check_plugins.
1565
     * @covers ::enrol_check_plugins
1565
     * @covers ::enrol_check_plugins
1566
     */
1566
     */
1567
    public function test_last_time_enrolments_synced_is_set_if_not_forced() {
1567
    public function test_last_time_enrolments_synced_is_set_if_not_forced(): void {
1568
        $this->resetAfterTest();
1568
        $this->resetAfterTest();
Línea 1569... Línea 1569...
1569
        $user = $this->getDataGenerator()->create_user();
1569
        $user = $this->getDataGenerator()->create_user();
Línea 1583... Línea 1583...
1583
 
1583
 
1584
    /**
1584
    /**
1585
     * Test last_time_enrolments_synced is recorded correctly without "force" option for enrol_check_plugins.
1585
     * Test last_time_enrolments_synced is recorded correctly without "force" option for enrol_check_plugins.
1586
     * @covers ::enrol_check_plugins
1586
     * @covers ::enrol_check_plugins
1587
     */
1587
     */
1588
    public function test_last_time_enrolments_synced_is_set_if_not_forced_if_have_not_passed_interval() {
1588
    public function test_last_time_enrolments_synced_is_set_if_not_forced_if_have_not_passed_interval(): void {
Línea 1589... Línea 1589...
1589
        global $CFG;
1589
        global $CFG;
1590
 
1590
 
1591
        $this->resetAfterTest();
1591
        $this->resetAfterTest();
Línea 1608... Línea 1608...
1608
    /**
1608
    /**
1609
     * Test enrol_selfenrol_available function behavior.
1609
     * Test enrol_selfenrol_available function behavior.
1610
     *
1610
     *
1611
     * @covers ::enrol_selfenrol_available
1611
     * @covers ::enrol_selfenrol_available
1612
     */
1612
     */
1613
    public function test_enrol_selfenrol_available() {
1613
    public function test_enrol_selfenrol_available(): void {
1614
        global $DB, $CFG;
1614
        global $DB, $CFG;
Línea 1615... Línea 1615...
1615
 
1615
 
1616
        $this->resetAfterTest();
1616
        $this->resetAfterTest();