Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 43... Línea 43...
43
    }
43
    }
Línea 44... Línea 44...
44
 
44
 
45
    /**
45
    /**
46
     * Verify comparison of context instances in phpunit asserts.
46
     * Verify comparison of context instances in phpunit asserts.
47
     */
47
     */
48
    public function test_context_comparisons() {
48
    public function test_context_comparisons(): void {
49
        $frontpagecontext1 = context_course::instance(SITEID);
49
        $frontpagecontext1 = context_course::instance(SITEID);
50
        context_helper::reset_caches();
50
        context_helper::reset_caches();
51
        $frontpagecontext2 = context_course::instance(SITEID);
51
        $frontpagecontext2 = context_course::instance(SITEID);
Línea 59... Línea 59...
59
    /**
59
    /**
60
     * Test resetting works.
60
     * Test resetting works.
61
     *
61
     *
62
     * @covers ::accesslib_clear_all_caches_for_unit_testing
62
     * @covers ::accesslib_clear_all_caches_for_unit_testing
63
     */
63
     */
64
    public function test_accesslib_clear_all_caches() {
64
    public function test_accesslib_clear_all_caches(): void {
65
        global $ACCESSLIB_PRIVATE;
65
        global $ACCESSLIB_PRIVATE;
Línea 66... Línea 66...
66
 
66
 
Línea 67... Línea 67...
67
        $this->resetAfterTest();
67
        $this->resetAfterTest();
Línea 76... Línea 76...
76
    }
76
    }
Línea 77... Línea 77...
77
 
77
 
78
    /**
78
    /**
79
     * Check modifying capability record is not exposed to other code.
79
     * Check modifying capability record is not exposed to other code.
80
     */
80
     */
81
    public function test_capabilities_mutation() {
81
    public function test_capabilities_mutation(): void {
82
        $oldcap = get_capability_info('moodle/site:config');
82
        $oldcap = get_capability_info('moodle/site:config');
83
        $cap = get_capability_info('moodle/site:config');
83
        $cap = get_capability_info('moodle/site:config');
84
        unset($cap->name);
84
        unset($cap->name);
Línea 92... Línea 92...
92
    /**
92
    /**
93
     * Test getting of role access
93
     * Test getting of role access
94
     *
94
     *
95
     * @covers ::get_role_access
95
     * @covers ::get_role_access
96
     */
96
     */
97
    public function test_get_role_access() {
97
    public function test_get_role_access(): void {
98
        global $DB;
98
        global $DB;
Línea 99... Línea 99...
99
 
99
 
100
        $roles = $DB->get_records('role');
100
        $roles = $DB->get_records('role');
101
        foreach ($roles as $role) {
101
        foreach ($roles as $role) {
Línea 116... Línea 116...
116
    /**
116
    /**
117
     * Test getting of guest role.
117
     * Test getting of guest role.
118
     *
118
     *
119
     * @covers ::get_guest_role
119
     * @covers ::get_guest_role
120
     */
120
     */
121
    public function test_get_guest_role() {
121
    public function test_get_guest_role(): void {
122
        global $CFG;
122
        global $CFG;
Línea 123... Línea 123...
123
 
123
 
124
        $guest = get_guest_role();
124
        $guest = get_guest_role();
125
        $this->assertEquals('guest', $guest->archetype);
125
        $this->assertEquals('guest', $guest->archetype);
Línea 131... Línea 131...
131
    /**
131
    /**
132
     * Test if user is admin.
132
     * Test if user is admin.
133
     *
133
     *
134
     * @covers ::is_siteadmin
134
     * @covers ::is_siteadmin
135
     */
135
     */
136
    public function test_is_siteadmin() {
136
    public function test_is_siteadmin(): void {
137
        global $DB, $CFG;
137
        global $DB, $CFG;
Línea 138... Línea 138...
138
 
138
 
Línea 139... Línea 139...
139
        $this->resetAfterTest();
139
        $this->resetAfterTest();
Línea 175... Línea 175...
175
    /**
175
    /**
176
     * Test if user is enrolled in a course
176
     * Test if user is enrolled in a course
177
     *
177
     *
178
     * @covers ::is_enrolled
178
     * @covers ::is_enrolled
179
     */
179
     */
180
    public function test_is_enrolled() {
180
    public function test_is_enrolled(): void {
181
        global $DB;
181
        global $DB;
Línea 182... Línea 182...
182
 
182
 
Línea 183... Línea 183...
183
        $this->resetAfterTest();
183
        $this->resetAfterTest();
Línea 227... Línea 227...
227
    /**
227
    /**
228
     * Test logged in test.
228
     * Test logged in test.
229
     *
229
     *
230
     * @covers ::isloggedin
230
     * @covers ::isloggedin
231
     */
231
     */
232
    public function test_isloggedin() {
232
    public function test_isloggedin(): void {
233
        global $USER;
233
        global $USER;
Línea 234... Línea 234...
234
 
234
 
Línea 235... Línea 235...
235
        $this->resetAfterTest();
235
        $this->resetAfterTest();
Línea 243... Línea 243...
243
    /**
243
    /**
244
     * Test guest user test.
244
     * Test guest user test.
245
     *
245
     *
246
     * @covers ::isguestuser
246
     * @covers ::isguestuser
247
     */
247
     */
248
    public function test_isguestuser() {
248
    public function test_isguestuser(): void {
249
        global $DB;
249
        global $DB;
Línea 250... Línea 250...
250
 
250
 
Línea 251... Línea 251...
251
        $this->resetAfterTest();
251
        $this->resetAfterTest();
Línea 272... Línea 272...
272
    /**
272
    /**
273
     * Test capability riskiness.
273
     * Test capability riskiness.
274
     *
274
     *
275
     * @covers ::is_safe_capability
275
     * @covers ::is_safe_capability
276
     */
276
     */
277
    public function test_is_safe_capability() {
277
    public function test_is_safe_capability(): void {
278
        global $DB;
278
        global $DB;
279
        // Note: there is not much to test, just make sure no notices are throw for the most dangerous cap.
279
        // Note: there is not much to test, just make sure no notices are throw for the most dangerous cap.
280
        $capability = $DB->get_record('capabilities', array('name'=>'moodle/site:config'), '*', MUST_EXIST);
280
        $capability = $DB->get_record('capabilities', array('name'=>'moodle/site:config'), '*', MUST_EXIST);
281
        $this->assertFalse(is_safe_capability($capability));
281
        $this->assertFalse(is_safe_capability($capability));
282
    }
282
    }
Línea 284... Línea 284...
284
    /**
284
    /**
285
     * Test context fetching.
285
     * Test context fetching.
286
     *
286
     *
287
     * @covers ::get_context_info_array
287
     * @covers ::get_context_info_array
288
     */
288
     */
289
    public function test_get_context_info_array() {
289
    public function test_get_context_info_array(): void {
290
        $this->resetAfterTest();
290
        $this->resetAfterTest();
Línea 291... Línea 291...
291
 
291
 
292
        $syscontext = context_system::instance();
292
        $syscontext = context_system::instance();
293
        $user = $this->getDataGenerator()->create_user();
293
        $user = $this->getDataGenerator()->create_user();
Línea 353... Línea 353...
353
    /**
353
    /**
354
     * Test looking for course contacts.
354
     * Test looking for course contacts.
355
     *
355
     *
356
     * @covers ::has_coursecontact_role
356
     * @covers ::has_coursecontact_role
357
     */
357
     */
358
    public function test_has_coursecontact_role() {
358
    public function test_has_coursecontact_role(): void {
359
        global $DB, $CFG;
359
        global $DB, $CFG;
Línea 360... Línea 360...
360
 
360
 
Línea 361... Línea 361...
361
        $this->resetAfterTest();
361
        $this->resetAfterTest();
Línea 379... Línea 379...
379
    /**
379
    /**
380
     * Test creation of roles.
380
     * Test creation of roles.
381
     *
381
     *
382
     * @covers ::create_role
382
     * @covers ::create_role
383
     */
383
     */
384
    public function test_create_role() {
384
    public function test_create_role(): void {
385
        global $DB;
385
        global $DB;
Línea 386... Línea 386...
386
 
386
 
Línea 387... Línea 387...
387
        $this->resetAfterTest();
387
        $this->resetAfterTest();
Línea 413... Línea 413...
413
    /**
413
    /**
414
     * Test adding of capabilities to roles.
414
     * Test adding of capabilities to roles.
415
     *
415
     *
416
     * @covers ::assign_capability
416
     * @covers ::assign_capability
417
     */
417
     */
418
    public function test_assign_capability() {
418
    public function test_assign_capability(): void {
419
        global $DB, $USER;
419
        global $DB, $USER;
Línea 420... Línea 420...
420
 
420
 
Línea 421... Línea 421...
421
        $this->resetAfterTest();
421
        $this->resetAfterTest();
Línea 488... Línea 488...
488
    /**
488
    /**
489
     * Test removing of capabilities from roles.
489
     * Test removing of capabilities from roles.
490
     *
490
     *
491
     * @covers ::unassign_capability
491
     * @covers ::unassign_capability
492
     */
492
     */
493
    public function test_unassign_capability() {
493
    public function test_unassign_capability(): void {
494
        global $DB, $USER;
494
        global $DB, $USER;
Línea 495... Línea 495...
495
 
495
 
Línea 496... Línea 496...
496
        $this->resetAfterTest();
496
        $this->resetAfterTest();
Línea 540... Línea 540...
540
    /**
540
    /**
541
     * Test role assigning.
541
     * Test role assigning.
542
     *
542
     *
543
     * @covers ::role_assign
543
     * @covers ::role_assign
544
     */
544
     */
545
    public function test_role_assign() {
545
    public function test_role_assign(): void {
546
        global $DB, $USER;
546
        global $DB, $USER;
Línea 547... Línea 547...
547
 
547
 
Línea 548... Línea 548...
548
        $this->resetAfterTest();
548
        $this->resetAfterTest();
Línea 597... Línea 597...
597
    /**
597
    /**
598
     * Test role unassigning.
598
     * Test role unassigning.
599
     *
599
     *
600
     * @covers ::role_unassign
600
     * @covers ::role_unassign
601
     */
601
     */
602
    public function test_role_unassign() {
602
    public function test_role_unassign(): void {
603
        global $DB, $USER;
603
        global $DB, $USER;
Línea 604... Línea 604...
604
 
604
 
Línea 605... Línea 605...
605
        $this->resetAfterTest();
605
        $this->resetAfterTest();
Línea 643... Línea 643...
643
    /**
643
    /**
644
     * Test role unassigning.
644
     * Test role unassigning.
645
     *
645
     *
646
     * @covers ::role_unassign_all
646
     * @covers ::role_unassign_all
647
     */
647
     */
648
    public function test_role_unassign_all() {
648
    public function test_role_unassign_all(): void {
649
        global $DB;
649
        global $DB;
Línea 650... Línea 650...
650
 
650
 
Línea 651... Línea 651...
651
        $this->resetAfterTest();
651
        $this->resetAfterTest();
Línea 700... Línea 700...
700
    /**
700
    /**
701
     * Test role queries.
701
     * Test role queries.
702
     *
702
     *
703
     * @covers ::get_roles_with_capability
703
     * @covers ::get_roles_with_capability
704
     */
704
     */
705
    public function test_get_roles_with_capability() {
705
    public function test_get_roles_with_capability(): void {
706
        global $DB;
706
        global $DB;
Línea 707... Línea 707...
707
 
707
 
Línea 708... Línea 708...
708
        $this->resetAfterTest();
708
        $this->resetAfterTest();
Línea 735... Línea 735...
735
    /**
735
    /**
736
     * Test deleting of roles.
736
     * Test deleting of roles.
737
     *
737
     *
738
     * @covers ::delete_role
738
     * @covers ::delete_role
739
     */
739
     */
740
    public function test_delete_role() {
740
    public function test_delete_role(): void {
741
        global $DB;
741
        global $DB;
Línea 742... Línea 742...
742
 
742
 
Línea 743... Línea 743...
743
        $this->resetAfterTest();
743
        $this->resetAfterTest();
Línea 790... Línea 790...
790
    /**
790
    /**
791
     * Test fetching of all roles.
791
     * Test fetching of all roles.
792
     *
792
     *
793
     * @covers ::get_all_roles
793
     * @covers ::get_all_roles
794
     */
794
     */
795
    public function test_get_all_roles() {
795
    public function test_get_all_roles(): void {
796
        global $DB;
796
        global $DB;
Línea 797... Línea 797...
797
 
797
 
Línea 798... Línea 798...
798
        $this->resetAfterTest();
798
        $this->resetAfterTest();
Línea 847... Línea 847...
847
    /**
847
    /**
848
     * Test getting of all archetypes.
848
     * Test getting of all archetypes.
849
     *
849
     *
850
     * @covers ::get_role_archetypes
850
     * @covers ::get_role_archetypes
851
     */
851
     */
852
    public function test_get_role_archetypes() {
852
    public function test_get_role_archetypes(): void {
853
        $archetypes = get_role_archetypes();
853
        $archetypes = get_role_archetypes();
854
        $this->assertCount(8, $archetypes); // There are 8 archetypes in standard install.
854
        $this->assertCount(8, $archetypes); // There are 8 archetypes in standard install.
855
        foreach ($archetypes as $k => $v) {
855
        foreach ($archetypes as $k => $v) {
856
            $this->assertSame($k, $v);
856
            $this->assertSame($k, $v);
857
        }
857
        }
Línea 860... Línea 860...
860
    /**
860
    /**
861
     * Test getting of roles with given archetype.
861
     * Test getting of roles with given archetype.
862
     *
862
     *
863
     * @covers ::get_archetype_roles
863
     * @covers ::get_archetype_roles
864
     */
864
     */
865
    public function test_get_archetype_roles() {
865
    public function test_get_archetype_roles(): void {
866
        $this->resetAfterTest();
866
        $this->resetAfterTest();
Línea 867... Línea 867...
867
 
867
 
868
        // New install should have at least 1 role for each archetype.
868
        // New install should have at least 1 role for each archetype.
869
        $archetypes = get_role_archetypes();
869
        $archetypes = get_role_archetypes();
Línea 882... Línea 882...
882
    /**
882
    /**
883
     * Test aliased role names.
883
     * Test aliased role names.
884
     *
884
     *
885
     * @covers ::role_get_name
885
     * @covers ::role_get_name
886
     */
886
     */
887
    public function test_role_get_name() {
887
    public function test_role_get_name(): void {
888
        global $DB;
888
        global $DB;
Línea 889... Línea 889...
889
 
889
 
Línea 890... Línea 890...
890
        $this->resetAfterTest();
890
        $this->resetAfterTest();
Línea 935... Línea 935...
935
    /**
935
    /**
936
     * Test tweaking of role name arrays.
936
     * Test tweaking of role name arrays.
937
     *
937
     *
938
     * @covers ::role_fix_names
938
     * @covers ::role_fix_names
939
     */
939
     */
940
    public function test_role_fix_names() {
940
    public function test_role_fix_names(): void {
941
        global $DB;
941
        global $DB;
Línea 942... Línea 942...
942
 
942
 
Línea 943... Línea 943...
943
        $this->resetAfterTest();
943
        $this->resetAfterTest();
Línea 993... Línea 993...
993
    /**
993
    /**
994
     * Test role default allows.
994
     * Test role default allows.
995
     *
995
     *
996
     * @covers ::get_default_role_archetype_allows
996
     * @covers ::get_default_role_archetype_allows
997
     */
997
     */
998
    public function test_get_default_role_archetype_allows() {
998
    public function test_get_default_role_archetype_allows(): void {
999
        $archetypes = get_role_archetypes();
999
        $archetypes = get_role_archetypes();
1000
        foreach ($archetypes as $archetype) {
1000
        foreach ($archetypes as $archetype) {
Línea 1001... Línea 1001...
1001
 
1001
 
1002
            $result = get_default_role_archetype_allows('assign', $archetype);
1002
            $result = get_default_role_archetype_allows('assign', $archetype);
Línea 1044... Línea 1044...
1044
    /**
1044
    /**
1045
     * Test allowing of role assignments.
1045
     * Test allowing of role assignments.
1046
     *
1046
     *
1047
     * @covers ::core_role_set_assign_allowed
1047
     * @covers ::core_role_set_assign_allowed
1048
     */
1048
     */
1049
    public function test_core_role_set_assign_allowed() {
1049
    public function test_core_role_set_assign_allowed(): void {
1050
        global $DB, $CFG;
1050
        global $DB, $CFG;
Línea 1051... Línea 1051...
1051
 
1051
 
Línea 1052... Línea 1052...
1052
        $this->resetAfterTest();
1052
        $this->resetAfterTest();
Línea 1075... Línea 1075...
1075
    /**
1075
    /**
1076
     * Test allowing of role overrides.
1076
     * Test allowing of role overrides.
1077
     *
1077
     *
1078
     * @covers ::core_role_set_override_allowed
1078
     * @covers ::core_role_set_override_allowed
1079
     */
1079
     */
1080
    public function test_core_role_set_override_allowed() {
1080
    public function test_core_role_set_override_allowed(): void {
1081
        global $DB, $CFG;
1081
        global $DB, $CFG;
Línea 1082... Línea 1082...
1082
 
1082
 
Línea 1083... Línea 1083...
1083
        $this->resetAfterTest();
1083
        $this->resetAfterTest();
Línea 1106... Línea 1106...
1106
    /**
1106
    /**
1107
     * Test allowing of role switching.
1107
     * Test allowing of role switching.
1108
     *
1108
     *
1109
     * @covers ::core_role_set_switch_allowed
1109
     * @covers ::core_role_set_switch_allowed
1110
     */
1110
     */
1111
    public function test_core_role_set_switch_allowed() {
1111
    public function test_core_role_set_switch_allowed(): void {
1112
        global $DB, $CFG;
1112
        global $DB, $CFG;
Línea 1113... Línea 1113...
1113
 
1113
 
Línea 1114... Línea 1114...
1114
        $this->resetAfterTest();
1114
        $this->resetAfterTest();
Línea 1137... Línea 1137...
1137
    /**
1137
    /**
1138
     * Test allowing of role switching.
1138
     * Test allowing of role switching.
1139
     *
1139
     *
1140
     * @covers ::core_role_set_view_allowed
1140
     * @covers ::core_role_set_view_allowed
1141
     */
1141
     */
1142
    public function test_core_role_set_view_allowed() {
1142
    public function test_core_role_set_view_allowed(): void {
1143
        global $DB, $CFG;
1143
        global $DB, $CFG;
Línea 1144... Línea 1144...
1144
 
1144
 
Línea 1145... Línea 1145...
1145
        $this->resetAfterTest();
1145
        $this->resetAfterTest();
Línea 1168... Línea 1168...
1168
    /**
1168
    /**
1169
     * Test returning of assignable roles in context.
1169
     * Test returning of assignable roles in context.
1170
     *
1170
     *
1171
     * @covers ::get_assignable_roles
1171
     * @covers ::get_assignable_roles
1172
     */
1172
     */
1173
    public function test_get_assignable_roles() {
1173
    public function test_get_assignable_roles(): void {
1174
        global $DB;
1174
        global $DB;
Línea 1175... Línea 1175...
1175
 
1175
 
Línea 1176... Línea 1176...
1176
        $this->resetAfterTest();
1176
        $this->resetAfterTest();
Línea 1277... Línea 1277...
1277
    /**
1277
    /**
1278
     * Test user count of assignable roles in context where users are assigned the role via different components.
1278
     * Test user count of assignable roles in context where users are assigned the role via different components.
1279
     *
1279
     *
1280
     * @covers ::get_assignable_roles
1280
     * @covers ::get_assignable_roles
1281
     */
1281
     */
1282
    public function test_get_assignable_roles_distinct_usercount() {
1282
    public function test_get_assignable_roles_distinct_usercount(): void {
1283
        global $DB;
1283
        global $DB;
Línea 1284... Línea 1284...
1284
 
1284
 
Línea 1285... Línea 1285...
1285
        $this->resetAfterTest(true);
1285
        $this->resetAfterTest(true);
Línea 1312... Línea 1312...
1312
    /**
1312
    /**
1313
     * Test getting of all switchable roles.
1313
     * Test getting of all switchable roles.
1314
     *
1314
     *
1315
     * @covers ::get_switchable_roles
1315
     * @covers ::get_switchable_roles
1316
     */
1316
     */
1317
    public function test_get_switchable_roles() {
1317
    public function test_get_switchable_roles(): void {
1318
        global $DB;
1318
        global $DB;
Línea 1319... Línea 1319...
1319
 
1319
 
Línea 1320... Línea 1320...
1320
        $this->resetAfterTest();
1320
        $this->resetAfterTest();
Línea 1372... Línea 1372...
1372
    /**
1372
    /**
1373
     * Test getting of all overridable roles.
1373
     * Test getting of all overridable roles.
1374
     *
1374
     *
1375
     * @covers ::get_overridable_roles
1375
     * @covers ::get_overridable_roles
1376
     */
1376
     */
1377
    public function test_get_overridable_roles() {
1377
    public function test_get_overridable_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 1467... Línea 1467...
1467
    /**
1467
    /**
1468
     * Test getting of all overridable roles.
1468
     * Test getting of all overridable roles.
1469
     *
1469
     *
1470
     * @covers ::get_viewable_roles
1470
     * @covers ::get_viewable_roles
1471
     */
1471
     */
1472
    public function test_get_viewable_roles_course() {
1472
    public function test_get_viewable_roles_course(): void {
1473
        global $DB;
1473
        global $DB;
Línea 1474... Línea 1474...
1474
 
1474
 
Línea 1475... Línea 1475...
1475
        $this->resetAfterTest();
1475
        $this->resetAfterTest();
Línea 1504... Línea 1504...
1504
    /**
1504
    /**
1505
     * Test getting of all overridable roles.
1505
     * Test getting of all overridable roles.
1506
     *
1506
     *
1507
     * @covers ::get_viewable_roles
1507
     * @covers ::get_viewable_roles
1508
     */
1508
     */
1509
    public function test_get_viewable_roles_system() {
1509
    public function test_get_viewable_roles_system(): void {
1510
        global $DB;
1510
        global $DB;
Línea 1511... Línea 1511...
1511
 
1511
 
Línea 1512... Línea 1512...
1512
        $this->resetAfterTest();
1512
        $this->resetAfterTest();
Línea 1539... Línea 1539...
1539
    /**
1539
    /**
1540
     * Test we have context level defaults.
1540
     * Test we have context level defaults.
1541
     *
1541
     *
1542
     * @covers ::get_default_contextlevels
1542
     * @covers ::get_default_contextlevels
1543
     */
1543
     */
1544
    public function test_get_default_contextlevels() {
1544
    public function test_get_default_contextlevels(): void {
1545
        $archetypes = get_role_archetypes();
1545
        $archetypes = get_role_archetypes();
1546
        $alllevels = context_helper::get_all_levels();
1546
        $alllevels = context_helper::get_all_levels();
1547
        foreach ($archetypes as $archetype) {
1547
        foreach ($archetypes as $archetype) {
1548
            $defaults = get_default_contextlevels($archetype);
1548
            $defaults = get_default_contextlevels($archetype);
1549
            $this->assertIsArray($defaults);
1549
            $this->assertIsArray($defaults);
Línea 1556... Línea 1556...
1556
    /**
1556
    /**
1557
     * Test role context level setup.
1557
     * Test role context level setup.
1558
     *
1558
     *
1559
     * @covers ::set_role_contextlevels
1559
     * @covers ::set_role_contextlevels
1560
     */
1560
     */
1561
    public function test_set_role_contextlevels() {
1561
    public function test_set_role_contextlevels(): void {
1562
        global $DB;
1562
        global $DB;
Línea 1563... Línea 1563...
1563
 
1563
 
Línea 1564... Línea 1564...
1564
        $this->resetAfterTest();
1564
        $this->resetAfterTest();
Línea 1582... Línea 1582...
1582
    /**
1582
    /**
1583
     * Test getting of role context levels
1583
     * Test getting of role context levels
1584
     *
1584
     *
1585
     * @covers ::get_roles_for_contextlevels
1585
     * @covers ::get_roles_for_contextlevels
1586
     */
1586
     */
1587
    public function test_get_roles_for_contextlevels() {
1587
    public function test_get_roles_for_contextlevels(): void {
1588
        global $DB;
1588
        global $DB;
Línea 1589... Línea 1589...
1589
 
1589
 
1590
        $allroles = get_all_roles();
1590
        $allroles = get_all_roles();
1591
        foreach (context_helper::get_all_levels() as $level => $unused) {
1591
        foreach (context_helper::get_all_levels() as $level => $unused) {
Línea 1604... Línea 1604...
1604
    /**
1604
    /**
1605
     * Test default enrol roles.
1605
     * Test default enrol roles.
1606
     *
1606
     *
1607
     * @covers ::get_default_enrol_roles
1607
     * @covers ::get_default_enrol_roles
1608
     */
1608
     */
1609
    public function test_get_default_enrol_roles() {
1609
    public function test_get_default_enrol_roles(): void {
1610
        $this->resetAfterTest();
1610
        $this->resetAfterTest();
Línea 1611... Línea 1611...
1611
 
1611
 
1612
        $course = $this->getDataGenerator()->create_course();
1612
        $course = $this->getDataGenerator()->create_course();
Línea 1634... Línea 1634...
1634
    /**
1634
    /**
1635
     * Test getting of role users.
1635
     * Test getting of role users.
1636
     *
1636
     *
1637
     * @covers ::get_role_users
1637
     * @covers ::get_role_users
1638
     */
1638
     */
1639
    public function test_get_role_users() {
1639
    public function test_get_role_users(): void {
1640
        global $DB;
1640
        global $DB;
Línea 1641... Línea 1641...
1641
 
1641
 
Línea 1642... Línea 1642...
1642
        $this->resetAfterTest();
1642
        $this->resetAfterTest();
Línea 1739... Línea 1739...
1739
    /**
1739
    /**
1740
     * Test used role query.
1740
     * Test used role query.
1741
     *
1741
     *
1742
     * @covers ::get_roles_used_in_context
1742
     * @covers ::get_roles_used_in_context
1743
     */
1743
     */
1744
    public function test_get_roles_used_in_context() {
1744
    public function test_get_roles_used_in_context(): void {
1745
        global $DB;
1745
        global $DB;
Línea 1746... Línea 1746...
1746
 
1746
 
Línea 1747... Línea 1747...
1747
        $this->resetAfterTest();
1747
        $this->resetAfterTest();
Línea 1781... Línea 1781...
1781
    /**
1781
    /**
1782
     * Test roles used in course.
1782
     * Test roles used in course.
1783
     *
1783
     *
1784
     * @covers ::get_user_roles_in_course
1784
     * @covers ::get_user_roles_in_course
1785
     */
1785
     */
1786
    public function test_get_user_roles_in_course() {
1786
    public function test_get_user_roles_in_course(): void {
1787
        global $DB, $CFG;
1787
        global $DB, $CFG;
Línea 1788... Línea 1788...
1788
 
1788
 
Línea 1789... Línea 1789...
1789
        $this->resetAfterTest();
1789
        $this->resetAfterTest();
Línea 1849... Línea 1849...
1849
    /**
1849
    /**
1850
     * Test get_user_roles and get_users_roles
1850
     * Test get_user_roles and get_users_roles
1851
     *
1851
     *
1852
     * @covers ::get_user_roles
1852
     * @covers ::get_user_roles
1853
     */
1853
     */
1854
    public function test_get_user_roles() {
1854
    public function test_get_user_roles(): void {
1855
        global $DB, $CFG;
1855
        global $DB, $CFG;
Línea 1856... Línea 1856...
1856
 
1856
 
Línea 1857... Línea 1857...
1857
        $this->resetAfterTest();
1857
        $this->resetAfterTest();
Línea 1889... Línea 1889...
1889
     *
1889
     *
1890
     * @covers ::has_capability
1890
     * @covers ::has_capability
1891
     * @covers ::has_any_capability
1891
     * @covers ::has_any_capability
1892
     * @covers ::has_all_capabilities
1892
     * @covers ::has_all_capabilities
1893
     */
1893
     */
1894
    public function test_has_capability_and_friends() {
1894
    public function test_has_capability_and_friends(): void {
1895
        global $DB;
1895
        global $DB;
Línea 1896... Línea 1896...
1896
 
1896
 
Línea 1897... Línea 1897...
1897
        $this->resetAfterTest();
1897
        $this->resetAfterTest();
Línea 1987... Línea 1987...
1987
    /**
1987
    /**
1988
     * Test get_deprecated_capability_info()
1988
     * Test get_deprecated_capability_info()
1989
     *
1989
     *
1990
     * @covers ::get_deprecated_capability_info
1990
     * @covers ::get_deprecated_capability_info
1991
     */
1991
     */
1992
    public function test_get_deprecated_capability_info() {
1992
    public function test_get_deprecated_capability_info(): void {
1993
        $this->resetAfterTest();
1993
        $this->resetAfterTest();
1994
        $course = $this->getDataGenerator()->create_course();
1994
        $course = $this->getDataGenerator()->create_course();
1995
        $coursecontext = context_course::instance($course->id);
1995
        $coursecontext = context_course::instance($course->id);
1996
        $user = $this->getDataGenerator()->create_and_enrol($course);
1996
        $user = $this->getDataGenerator()->create_and_enrol($course);
1997
        $this->setup_fake_plugin('access');
1997
        $this->setup_fake_plugin('access');
Línea 2006... Línea 2006...
2006
    /**
2006
    /**
2007
     * Test get_deprecated_capability_info() through has_capability
2007
     * Test get_deprecated_capability_info() through has_capability
2008
     *
2008
     *
2009
     * @covers ::get_deprecated_capability_info
2009
     * @covers ::get_deprecated_capability_info
2010
     */
2010
     */
2011
    public function test_get_deprecated_capability_info_through_has_capability() {
2011
    public function test_get_deprecated_capability_info_through_has_capability(): void {
2012
        $this->resetAfterTest();
2012
        $this->resetAfterTest();
2013
        $course = $this->getDataGenerator()->create_course();
2013
        $course = $this->getDataGenerator()->create_course();
2014
        $coursecontext = context_course::instance($course->id);
2014
        $coursecontext = context_course::instance($course->id);
2015
        $user = $this->getDataGenerator()->create_and_enrol($course);
2015
        $user = $this->getDataGenerator()->create_and_enrol($course);
2016
        $this->setup_fake_plugin('access');
2016
        $this->setup_fake_plugin('access');
Línea 2025... Línea 2025...
2025
    /**
2025
    /**
2026
     * Test get_deprecated_capability_info() through get_user_capability_contexts()
2026
     * Test get_deprecated_capability_info() through get_user_capability_contexts()
2027
     *
2027
     *
2028
     * @covers ::get_deprecated_capability_info
2028
     * @covers ::get_deprecated_capability_info
2029
     */
2029
     */
2030
    public function test_get_deprecated_capability_info_through_get_user_capability_contexts() {
2030
    public function test_get_deprecated_capability_info_through_get_user_capability_contexts(): void {
2031
        $this->resetAfterTest();
2031
        $this->resetAfterTest();
2032
        $category = $this->getDataGenerator()->create_category();
2032
        $category = $this->getDataGenerator()->create_category();
2033
        $course = $this->getDataGenerator()->create_course(['categoryid' => $category->id]);
2033
        $course = $this->getDataGenerator()->create_course(['categoryid' => $category->id]);
2034
        $user = $this->getDataGenerator()->create_and_enrol($course);
2034
        $user = $this->getDataGenerator()->create_and_enrol($course);
2035
        $this->setup_fake_plugin('access');
2035
        $this->setup_fake_plugin('access');
Línea 2049... Línea 2049...
2049
     * @param bool $expectedexisting does the capability exist
2049
     * @param bool $expectedexisting does the capability exist
2050
     * @covers ::get_deprecated_capability_info
2050
     * @covers ::get_deprecated_capability_info
2051
     * @dataProvider deprecated_capabilities_use_cases
2051
     * @dataProvider deprecated_capabilities_use_cases
2052
     */
2052
     */
2053
    public function test_get_deprecated_capability_specific_cases(string $capability, array $debugmessages,
2053
    public function test_get_deprecated_capability_specific_cases(string $capability, array $debugmessages,
2054
        bool $expectedexisting) {
2054
        bool $expectedexisting): void {
2055
        $this->resetAfterTest();
2055
        $this->resetAfterTest();
2056
        $course = $this->getDataGenerator()->create_course();
2056
        $course = $this->getDataGenerator()->create_course();
2057
        $coursecontext = context_course::instance($course->id);
2057
        $coursecontext = context_course::instance($course->id);
2058
        $user = $this->getDataGenerator()->create_and_enrol($course);
2058
        $user = $this->getDataGenerator()->create_and_enrol($course);
2059
        $this->setup_fake_plugin('access');
2059
        $this->setup_fake_plugin('access');
Línea 2120... Línea 2120...
2120
     * @covers ::get_users_by_capability
2120
     * @covers ::get_users_by_capability
2121
     * @covers ::get_with_capability_join
2121
     * @covers ::get_with_capability_join
2122
     * @covers ::get_with_capability_sql
2122
     * @covers ::get_with_capability_sql
2123
     * @covers ::has_capability
2123
     * @covers ::has_capability
2124
     */
2124
     */
2125
    public function test_fake_capability() {
2125
    public function test_fake_capability(): void {
2126
        global $DB;
2126
        global $DB;
Línea 2127... Línea 2127...
2127
 
2127
 
Línea 2128... Línea 2128...
2128
        $this->resetAfterTest();
2128
        $this->resetAfterTest();
Línea 2171... Línea 2171...
2171
    /**
2171
    /**
2172
     * Test that assigning a fake cap does not return.
2172
     * Test that assigning a fake cap does not return.
2173
     *
2173
     *
2174
     * @covers ::assign_capability
2174
     * @covers ::assign_capability
2175
     */
2175
     */
2176
    public function test_fake_capability_assign() {
2176
    public function test_fake_capability_assign(): void {
2177
        global $DB;
2177
        global $DB;
Línea 2178... Línea 2178...
2178
 
2178
 
Línea 2179... Línea 2179...
2179
        $this->resetAfterTest();
2179
        $this->resetAfterTest();
Línea 2196... Línea 2196...
2196
    /**
2196
    /**
2197
     * Test that assigning a fake cap does not return.
2197
     * Test that assigning a fake cap does not return.
2198
     *
2198
     *
2199
     * @covers ::unassign_capability
2199
     * @covers ::unassign_capability
2200
     */
2200
     */
2201
    public function test_fake_capability_unassign() {
2201
    public function test_fake_capability_unassign(): void {
2202
        global $DB;
2202
        global $DB;
Línea 2203... Línea 2203...
2203
 
2203
 
Línea 2204... Línea 2204...
2204
        $this->resetAfterTest();
2204
        $this->resetAfterTest();
Línea 2223... Línea 2223...
2223
     * works as intended.
2223
     * works as intended.
2224
     *
2224
     *
2225
     * @covers ::get_role_definitions
2225
     * @covers ::get_role_definitions
2226
     * @covers ::role_change_permission
2226
     * @covers ::role_change_permission
2227
     */
2227
     */
2228
    public function test_role_definition_caching() {
2228
    public function test_role_definition_caching(): void {
2229
        global $DB;
2229
        global $DB;
Línea 2230... Línea 2230...
2230
 
2230
 
Línea 2231... Línea 2231...
2231
        $this->resetAfterTest();
2231
        $this->resetAfterTest();
Línea 2292... Línea 2292...
2292
    /**
2292
    /**
2293
     * Tests get_user_capability_course() which checks a capability across all courses.
2293
     * Tests get_user_capability_course() which checks a capability across all courses.
2294
     *
2294
     *
2295
     * @covers ::get_user_capability_course
2295
     * @covers ::get_user_capability_course
2296
     */
2296
     */
2297
    public function test_get_user_capability_course() {
2297
    public function test_get_user_capability_course(): void {
2298
        global $CFG, $USER;
2298
        global $CFG, $USER;
Línea 2299... Línea 2299...
2299
 
2299
 
Línea 2300... Línea 2300...
2300
        $this->resetAfterTest();
2300
        $this->resetAfterTest();
Línea 2479... Línea 2479...
2479
     * Tests get_user_capability_contexts() which checks a capability across all courses and categories.
2479
     * Tests get_user_capability_contexts() which checks a capability across all courses and categories.
2480
     * Testing for categories only because courses results are covered by test_get_user_capability_course.
2480
     * Testing for categories only because courses results are covered by test_get_user_capability_course.
2481
     *
2481
     *
2482
     * @covers ::get_user_capability_contexts
2482
     * @covers ::get_user_capability_contexts
2483
     */
2483
     */
2484
    public function test_get_user_capability_contexts() {
2484
    public function test_get_user_capability_contexts(): void {
2485
        $this->resetAfterTest();
2485
        $this->resetAfterTest();
Línea 2486... Línea 2486...
2486
 
2486
 
2487
        $generator = $this->getDataGenerator();
2487
        $generator = $this->getDataGenerator();
2488
        $cap = 'moodle/contentbank:access';
2488
        $cap = 'moodle/contentbank:access';
Línea 2577... Línea 2577...
2577
     * Test if course creator future capability lookup works.
2577
     * Test if course creator future capability lookup works.
2578
     *
2578
     *
2579
     * @covers ::guess_if_creator_will_have_course_capability
2579
     * @covers ::guess_if_creator_will_have_course_capability
2580
     * @covers ::has_capability
2580
     * @covers ::has_capability
2581
     */
2581
     */
2582
    public function test_guess_if_creator_will_have_course_capability() {
2582
    public function test_guess_if_creator_will_have_course_capability(): void {
2583
        global $DB, $CFG, $USER;
2583
        global $DB, $CFG, $USER;
Línea 2584... Línea 2584...
2584
 
2584
 
Línea 2585... Línea 2585...
2585
        $this->resetAfterTest();
2585
        $this->resetAfterTest();
Línea 2704... Línea 2704...
2704
    /**
2704
    /**
2705
     * Test require_capability() exceptions.
2705
     * Test require_capability() exceptions.
2706
     *
2706
     *
2707
     * @covers ::require_capability
2707
     * @covers ::require_capability
2708
     */
2708
     */
2709
    public function test_require_capability() {
2709
    public function test_require_capability(): void {
2710
        $this->resetAfterTest();
2710
        $this->resetAfterTest();
Línea 2711... Línea 2711...
2711
 
2711
 
Línea 2712... Línea 2712...
2712
        $syscontext = context_system::instance();
2712
        $syscontext = context_system::instance();
Línea 2747... Línea 2747...
2747
     * @covers ::get_enrolled_join
2747
     * @covers ::get_enrolled_join
2748
     * @covers ::get_with_capability_join
2748
     * @covers ::get_with_capability_join
2749
     * @covers ::groups_get_members_join
2749
     * @covers ::groups_get_members_join
2750
     * @covers ::get_suspended_userids
2750
     * @covers ::get_suspended_userids
2751
     */
2751
     */
2752
    public function test_get_enrolled_sql_different_course() {
2752
    public function test_get_enrolled_sql_different_course(): void {
2753
        global $DB;
2753
        global $DB;
Línea 2754... Línea 2754...
2754
 
2754
 
Línea 2755... Línea 2755...
2755
        $this->resetAfterTest();
2755
        $this->resetAfterTest();
Línea 2786... Línea 2786...
2786
     * @covers ::get_enrolled_join
2786
     * @covers ::get_enrolled_join
2787
     * @covers ::get_with_capability_join
2787
     * @covers ::get_with_capability_join
2788
     * @covers ::groups_get_members_join
2788
     * @covers ::groups_get_members_join
2789
     * @covers ::get_suspended_userids
2789
     * @covers ::get_suspended_userids
2790
     */
2790
     */
2791
    public function test_get_enrolled_sql_role_only() {
2791
    public function test_get_enrolled_sql_role_only(): void {
2792
        global $DB;
2792
        global $DB;
Línea 2793... Línea 2793...
2793
 
2793
 
Línea 2794... Línea 2794...
2794
        $this->resetAfterTest();
2794
        $this->resetAfterTest();
Línea 2822... Línea 2822...
2822
     * @covers ::get_enrolled_join
2822
     * @covers ::get_enrolled_join
2823
     * @covers ::get_with_capability_join
2823
     * @covers ::get_with_capability_join
2824
     * @covers ::groups_get_members_join
2824
     * @covers ::groups_get_members_join
2825
     * @covers ::get_suspended_userids
2825
     * @covers ::get_suspended_userids
2826
     */
2826
     */
2827
    public function test_get_enrolled_sql_multiple_enrolments() {
2827
    public function test_get_enrolled_sql_multiple_enrolments(): void {
2828
        global $DB;
2828
        global $DB;
Línea 2829... Línea 2829...
2829
 
2829
 
Línea 2830... Línea 2830...
2830
        $this->resetAfterTest();
2830
        $this->resetAfterTest();
Línea 2879... Línea 2879...
2879
     * @covers ::get_enrolled_join
2879
     * @covers ::get_enrolled_join
2880
     * @covers ::get_with_capability_join
2880
     * @covers ::get_with_capability_join
2881
     * @covers ::groups_get_members_join
2881
     * @covers ::groups_get_members_join
2882
     * @covers ::get_suspended_userids
2882
     * @covers ::get_suspended_userids
2883
     */
2883
     */
2884
    public function test_get_enrolled_sql_userswithgroups() {
2884
    public function test_get_enrolled_sql_userswithgroups(): void {
2885
        $this->resetAfterTest();
2885
        $this->resetAfterTest();
Línea 2886... Línea 2886...
2886
 
2886
 
2887
        $systemcontext = context_system::instance();
2887
        $systemcontext = context_system::instance();
2888
        $course = $this->getDataGenerator()->create_course();
2888
        $course = $this->getDataGenerator()->create_course();
Línea 2928... Línea 2928...
2928
     * @covers ::get_enrolled_join
2928
     * @covers ::get_enrolled_join
2929
     * @covers ::get_with_capability_join
2929
     * @covers ::get_with_capability_join
2930
     * @covers ::groups_get_members_join
2930
     * @covers ::groups_get_members_join
2931
     * @covers ::get_suspended_userids
2931
     * @covers ::get_suspended_userids
2932
     */
2932
     */
2933
    public function test_get_enrolled_sql_userswithoutgroup() {
2933
    public function test_get_enrolled_sql_userswithoutgroup(): void {
2934
        global $DB;
2934
        global $DB;
Línea 2935... Línea 2935...
2935
 
2935
 
Línea 2936... Línea 2936...
2936
        $this->resetAfterTest();
2936
        $this->resetAfterTest();
Línea 2970... Línea 2970...
2970
     * @covers ::get_enrolled_join
2970
     * @covers ::get_enrolled_join
2971
     * @covers ::get_with_capability_join
2971
     * @covers ::get_with_capability_join
2972
     * @covers ::groups_get_members_join
2972
     * @covers ::groups_get_members_join
2973
     * @covers ::get_suspended_userids
2973
     * @covers ::get_suspended_userids
2974
     */
2974
     */
2975
    public function test_get_enrolled_sql_userswithhiddengroups() {
2975
    public function test_get_enrolled_sql_userswithhiddengroups(): void {
2976
        $this->resetAfterTest();
2976
        $this->resetAfterTest();
Línea 2977... Línea 2977...
2977
 
2977
 
2978
        $course = $this->getDataGenerator()->create_course();
2978
        $course = $this->getDataGenerator()->create_course();
2979
        $coursecontext = context_course::instance($course->id);
2979
        $coursecontext = context_course::instance($course->id);
Línea 3158... Línea 3158...
3158
    /**
3158
    /**
3159
     * @dataProvider get_enrolled_sql_provider
3159
     * @dataProvider get_enrolled_sql_provider
3160
     * @covers ::get_enrolled_users
3160
     * @covers ::get_enrolled_users
3161
     * @covers ::get_suspended_userids
3161
     * @covers ::get_suspended_userids
3162
     */
3162
     */
3163
    public function test_get_enrolled_sql_course($users, $counts) {
3163
    public function test_get_enrolled_sql_course($users, $counts): void {
3164
        global $DB;
3164
        global $DB;
Línea 3165... Línea 3165...
3165
 
3165
 
Línea 3166... Línea 3166...
3166
        $this->resetAfterTest();
3166
        $this->resetAfterTest();
Línea 3222... Línea 3222...
3222
    }
3222
    }
Línea 3223... Línea 3223...
3223
 
3223
 
3224
    /**
3224
    /**
3225
     * A small functional test of permission evaluations.
3225
     * A small functional test of permission evaluations.
3226
     */
3226
     */
3227
    public function test_permission_evaluation() {
3227
    public function test_permission_evaluation(): void {
Línea 3228... Línea 3228...
3228
        global $USER, $SITE, $CFG, $DB, $ACCESSLIB_PRIVATE;
3228
        global $USER, $SITE, $CFG, $DB, $ACCESSLIB_PRIVATE;
Línea 3229... Línea 3229...
3229
 
3229
 
Línea 4088... Línea 4088...
4088
    /**
4088
    /**
4089
     * Test that context_system::get_capabilities returns capabilities relevant to all modules.
4089
     * Test that context_system::get_capabilities returns capabilities relevant to all modules.
4090
     *
4090
     *
4091
     * @covers \context_system::get_capabilities
4091
     * @covers \context_system::get_capabilities
4092
     */
4092
     */
4093
    public function test_context_module_caps_returned_by_get_capabilities_in_sys_context() {
4093
    public function test_context_module_caps_returned_by_get_capabilities_in_sys_context(): void {
4094
        $actual = context_system::instance()->get_capabilities();
4094
        $actual = context_system::instance()->get_capabilities();
Línea 4095... Línea 4095...
4095
 
4095
 
4096
        // Just test a few representative capabilities.
4096
        // Just test a few representative capabilities.
4097
        $expectedcapabilities = ['moodle/site:accessallgroups', 'moodle/site:viewfullnames',
4097
        $expectedcapabilities = ['moodle/site:accessallgroups', 'moodle/site:viewfullnames',
Línea 4103... Línea 4103...
4103
    /**
4103
    /**
4104
     * Test that context_coursecat::get_capabilities returns capabilities relevant to all modules.
4104
     * Test that context_coursecat::get_capabilities returns capabilities relevant to all modules.
4105
     *
4105
     *
4106
     * @covers \context_coursecat::get_capabilities
4106
     * @covers \context_coursecat::get_capabilities
4107
     */
4107
     */
4108
    public function test_context_module_caps_returned_by_get_capabilities_in_course_cat_context() {
4108
    public function test_context_module_caps_returned_by_get_capabilities_in_course_cat_context(): void {
4109
        $this->resetAfterTest(true);
4109
        $this->resetAfterTest(true);
4110
        $generator = $this->getDataGenerator();
4110
        $generator = $this->getDataGenerator();
4111
        $cat = $generator->create_category();
4111
        $cat = $generator->create_category();
Línea 4112... Línea 4112...
4112
 
4112
 
Línea 4122... Línea 4122...
4122
    /**
4122
    /**
4123
     * Test that context_course::get_capabilities returns capabilities relevant to all modules.
4123
     * Test that context_course::get_capabilities returns capabilities relevant to all modules.
4124
     *
4124
     *
4125
     * @covers \context_course::get_capabilities
4125
     * @covers \context_course::get_capabilities
4126
     */
4126
     */
4127
    public function test_context_module_caps_returned_by_get_capabilities_in_course_context() {
4127
    public function test_context_module_caps_returned_by_get_capabilities_in_course_context(): void {
4128
        $this->resetAfterTest(true);
4128
        $this->resetAfterTest(true);
4129
        $generator = $this->getDataGenerator();
4129
        $generator = $this->getDataGenerator();
4130
        $cat = $generator->create_category();
4130
        $cat = $generator->create_category();
4131
        $course = $generator->create_course(['category' => $cat->id]);
4131
        $course = $generator->create_course(['category' => $cat->id]);
Línea 4142... Línea 4142...
4142
    /**
4142
    /**
4143
     * Test that context_module::get_capabilities returns capabilities relevant to all modules.
4143
     * Test that context_module::get_capabilities returns capabilities relevant to all modules.
4144
     *
4144
     *
4145
     * @covers \context_module::get_capabilities
4145
     * @covers \context_module::get_capabilities
4146
     */
4146
     */
4147
    public function test_context_module_caps_returned_by_get_capabilities_mod_context() {
4147
    public function test_context_module_caps_returned_by_get_capabilities_mod_context(): void {
4148
        $this->resetAfterTest(true);
4148
        $this->resetAfterTest(true);
4149
        $generator = $this->getDataGenerator();
4149
        $generator = $this->getDataGenerator();
4150
        $cat = $generator->create_category();
4150
        $cat = $generator->create_category();
4151
        $course = $generator->create_course(['category' => $cat->id]);
4151
        $course = $generator->create_course(['category' => $cat->id]);
4152
        $page = $generator->create_module('page', ['course' => $course->id]);
4152
        $page = $generator->create_module('page', ['course' => $course->id]);
Línea 4220... Línea 4220...
4220
     * Test updating of role capabilities during upgrade
4220
     * Test updating of role capabilities during upgrade
4221
     *
4221
     *
4222
     * @covers ::update_capabilities
4222
     * @covers ::update_capabilities
4223
     * @covers ::update_capabilities
4223
     * @covers ::update_capabilities
4224
     */
4224
     */
4225
    public function test_update_capabilities() {
4225
    public function test_update_capabilities(): void {
4226
        global $DB, $SITE;
4226
        global $DB, $SITE;
Línea 4227... Línea 4227...
4227
 
4227
 
Línea 4228... Línea 4228...
4228
        $this->resetAfterTest(true);
4228
        $this->resetAfterTest(true);
Línea 4415... Línea 4415...
4415
    /**
4415
    /**
4416
     * Tests reset_role_capabilities function.
4416
     * Tests reset_role_capabilities function.
4417
     *
4417
     *
4418
     * @covers ::reset_role_capabilities
4418
     * @covers ::reset_role_capabilities
4419
     */
4419
     */
4420
    public function test_reset_role_capabilities() {
4420
    public function test_reset_role_capabilities(): void {
4421
        global $DB;
4421
        global $DB;
4422
        $this->resetAfterTest(true);
4422
        $this->resetAfterTest(true);
4423
        $generator = $this->getDataGenerator();
4423
        $generator = $this->getDataGenerator();
Línea 4424... Línea 4424...
4424
 
4424
 
Línea 4452... Línea 4452...
4452
    /**
4452
    /**
4453
     * Tests count_role_users function.
4453
     * Tests count_role_users function.
4454
     *
4454
     *
4455
     * @covers ::count_role_users
4455
     * @covers ::count_role_users
4456
     */
4456
     */
4457
    public function test_count_role_users() {
4457
    public function test_count_role_users(): void {
4458
        global $DB;
4458
        global $DB;
4459
        $this->resetAfterTest(true);
4459
        $this->resetAfterTest(true);
4460
        $generator = self::getDataGenerator();
4460
        $generator = self::getDataGenerator();
4461
        // Create a course in a category, and some users.
4461
        // Create a course in a category, and some users.
4462
        $category = $generator->create_category();
4462
        $category = $generator->create_category();
Línea 4492... Línea 4492...
4492
    /**
4492
    /**
4493
     * Test fetching users by capability.
4493
     * Test fetching users by capability.
4494
     *
4494
     *
4495
     * @covers ::get_users_by_capability
4495
     * @covers ::get_users_by_capability
4496
     */
4496
     */
4497
    public function test_get_users_by_capability() {
4497
    public function test_get_users_by_capability(): void {
4498
        global $DB;
4498
        global $DB;
Línea 4499... Línea 4499...
4499
 
4499
 
Línea 4500... Línea 4500...
4500
        $this->resetAfterTest();
4500
        $this->resetAfterTest();
Línea 4544... Línea 4544...
4544
 
4544
 
4545
 
4545
 
4546
    /**
4546
    /**
4547
     * @covers ::get_with_capability_sql
4547
     * @covers ::get_with_capability_sql
4548
     */
4548
     */
Línea 4549... Línea 4549...
4549
    public function test_get_with_capability_sql() {
4549
    public function test_get_with_capability_sql(): void {
Línea 4550... Línea 4550...
4550
        global $DB;
4550
        global $DB;
Línea 4623... Línea 4623...
4623
     *
4623
     *
4624
     * @param bool $studentshouldbereturned whether, with this combination of capabilities, the student should be in the results.
4624
     * @param bool $studentshouldbereturned whether, with this combination of capabilities, the student should be in the results.
4625
     * @param array $capabilitiestoprevent capabilities to override to prevent in the course context.
4625
     * @param array $capabilitiestoprevent capabilities to override to prevent in the course context.
4626
     */
4626
     */
4627
    public function test_get_with_capability_join_when_overrides_present(
4627
    public function test_get_with_capability_join_when_overrides_present(
4628
            bool $studentshouldbereturned, array $capabilitiestoprevent) {
4628
            bool $studentshouldbereturned, array $capabilitiestoprevent): void {
4629
        global $DB;
4629
        global $DB;
4630
        $this->resetAfterTest();
4630
        $this->resetAfterTest();
4631
        $generator = $this->getDataGenerator();
4631
        $generator = $this->getDataGenerator();
Línea 4632... Línea 4632...
4632
 
4632
 
Línea 4668... Línea 4668...
4668
    /**
4668
    /**
4669
     * Test the get_profile_roles() function.
4669
     * Test the get_profile_roles() function.
4670
     *
4670
     *
4671
     * @covers ::get_profile_roles
4671
     * @covers ::get_profile_roles
4672
     */
4672
     */
4673
    public function test_get_profile_roles() {
4673
    public function test_get_profile_roles(): void {
4674
        global $DB;
4674
        global $DB;
4675
        $this->resetAfterTest();
4675
        $this->resetAfterTest();
Línea 4676... Línea 4676...
4676
 
4676
 
4677
        $course = $this->getDataGenerator()->create_course();
4677
        $course = $this->getDataGenerator()->create_course();
Línea 5015... Línea 5015...
5015
    /**
5015
    /**
5016
     * Ensure that the get_parent_contexts() function limits the number of queries it performs.
5016
     * Ensure that the get_parent_contexts() function limits the number of queries it performs.
5017
     *
5017
     *
5018
     * @covers ::get_parent_contexts
5018
     * @covers ::get_parent_contexts
5019
     */
5019
     */
5020
    public function test_get_parent_contexts_preload() {
5020
    public function test_get_parent_contexts_preload(): void {
5021
        global $DB;
5021
        global $DB;
Línea 5022... Línea 5022...
5022
 
5022
 
Línea 5023... Línea 5023...
5023
        $this->resetAfterTest();
5023
        $this->resetAfterTest();
Línea 5059... Línea 5059...
5059
     * Ensure that get_with_capability_sql and get_with_capability_join respect context locking.
5059
     * Ensure that get_with_capability_sql and get_with_capability_join respect context locking.
5060
     *
5060
     *
5061
     * @covers ::get_with_capability_join
5061
     * @covers ::get_with_capability_join
5062
     * @covers ::get_with_capability_sql
5062
     * @covers ::get_with_capability_sql
5063
     */
5063
     */
5064
    public function test_get_with_capability_sql_locked() {
5064
    public function test_get_with_capability_sql_locked(): void {
5065
        global $DB;
5065
        global $DB;
Línea 5066... Línea 5066...
5066
 
5066
 
Línea 5067... Línea 5067...
5067
        $this->resetAfterTest();
5067
        $this->resetAfterTest();
Línea 5148... Línea 5148...
5148
    /**
5148
    /**
5149
     * Ensure that get_users_by_capability respects context freezing.
5149
     * Ensure that get_users_by_capability respects context freezing.
5150
     *
5150
     *
5151
     * @covers ::get_users_by_capability
5151
     * @covers ::get_users_by_capability
5152
     */
5152
     */
5153
    public function test_get_users_by_capability_locked() {
5153
    public function test_get_users_by_capability_locked(): void {
5154
        $this->resetAfterTest();
5154
        $this->resetAfterTest();
Línea 5155... Línea 5155...
5155
 
5155
 
Línea 5156... Línea 5156...
5156
        $generator = $this->getDataGenerator();
5156
        $generator = $this->getDataGenerator();
Línea 5227... Línea 5227...
5227
    /**
5227
    /**
5228
     * Test require_all_capabilities.
5228
     * Test require_all_capabilities.
5229
     *
5229
     *
5230
     * @covers ::require_all_capabilities
5230
     * @covers ::require_all_capabilities
5231
     */
5231
     */
5232
    public function test_require_all_capabilities() {
5232
    public function test_require_all_capabilities(): void {
5233
        global $DB;
5233
        global $DB;
Línea 5234... Línea 5234...
5234
 
5234
 
Línea 5235... Línea 5235...
5235
        $this->resetAfterTest();
5235
        $this->resetAfterTest();
Línea 5260... Línea 5260...
5260
    /**
5260
    /**
5261
     * Test get_navigation_filter_context.
5261
     * Test get_navigation_filter_context.
5262
     *
5262
     *
5263
     * @covers ::get_navigation_filter_context
5263
     * @covers ::get_navigation_filter_context
5264
     */
5264
     */
5265
    public function test_get_navigation_filter_context() {
5265
    public function test_get_navigation_filter_context(): void {
5266
        $this->resetAfterTest();
5266
        $this->resetAfterTest();
5267
        $course = $this->getDataGenerator()->create_course();
5267
        $course = $this->getDataGenerator()->create_course();
5268
        set_config('filternavigationwithsystemcontext', 0);
5268
        set_config('filternavigationwithsystemcontext', 0);
5269
        // First test passed values are returned if disabled.
5269
        // First test passed values are returned if disabled.
5270
        $this->assertNull(context_helper::get_navigation_filter_context(null));
5270
        $this->assertNull(context_helper::get_navigation_filter_context(null));