Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 35... Línea 35...
35
 
35
 
36
    /**
36
    /**
37
     * Ensure that the check_can_manage_data_registry function fails cap testing when a user without capabilities is
37
     * Ensure that the check_can_manage_data_registry function fails cap testing when a user without capabilities is
38
     * tested with the default context.
38
     * tested with the default context.
39
     */
39
     */
40
    public function test_check_can_manage_data_registry_admin() {
40
    public function test_check_can_manage_data_registry_admin(): void {
Línea 41... Línea 41...
41
        $this->resetAfterTest();
41
        $this->resetAfterTest();
42
 
42
 
43
        $this->setAdminUser();
43
        $this->setAdminUser();
Línea 47... Línea 47...
47
 
47
 
48
    /**
48
    /**
49
     * Ensure that the check_can_manage_data_registry function fails cap testing when a user without capabilities is
49
     * Ensure that the check_can_manage_data_registry function fails cap testing when a user without capabilities is
50
     * tested with the default context.
50
     * tested with the default context.
51
     */
51
     */
52
    public function test_check_can_manage_data_registry_without_cap_default() {
52
    public function test_check_can_manage_data_registry_without_cap_default(): void {
Línea 53... Línea 53...
53
        $this->resetAfterTest();
53
        $this->resetAfterTest();
54
 
54
 
Línea 61... Línea 61...
61
 
61
 
62
    /**
62
    /**
63
     * Ensure that the check_can_manage_data_registry function fails cap testing when a user without capabilities is
63
     * Ensure that the check_can_manage_data_registry function fails cap testing when a user without capabilities is
64
     * tested with the default context.
64
     * tested with the default context.
65
     */
65
     */
66
    public function test_check_can_manage_data_registry_without_cap_system() {
66
    public function test_check_can_manage_data_registry_without_cap_system(): void {
Línea 67... Línea 67...
67
        $this->resetAfterTest();
67
        $this->resetAfterTest();
68
 
68
 
Línea 75... Línea 75...
75
 
75
 
76
    /**
76
    /**
77
     * Ensure that the check_can_manage_data_registry function fails cap testing when a user without capabilities is
77
     * Ensure that the check_can_manage_data_registry function fails cap testing when a user without capabilities is
78
     * tested with the default context.
78
     * tested with the default context.
79
     */
79
     */
80
    public function test_check_can_manage_data_registry_without_cap_own_user() {
80
    public function test_check_can_manage_data_registry_without_cap_own_user(): void {
Línea 81... Línea 81...
81
        $this->resetAfterTest();
81
        $this->resetAfterTest();
82
 
82
 
Línea 88... Línea 88...
88
    }
88
    }
Línea 89... Línea 89...
89
 
89
 
90
    /**
90
    /**
91
     * Test for api::update_request_status().
91
     * Test for api::update_request_status().
92
     */
92
     */
93
    public function test_update_request_status() {
93
    public function test_update_request_status(): void {
Línea 94... Línea 94...
94
        $this->resetAfterTest();
94
        $this->resetAfterTest();
95
 
95
 
96
        $generator = new testing_data_generator();
96
        $generator = new testing_data_generator();
Línea 136... Línea 136...
136
    }
136
    }
Línea 137... Línea 137...
137
 
137
 
138
    /**
138
    /**
139
     * Test for api::get_site_dpos() when there are no users with the DPO role.
139
     * Test for api::get_site_dpos() when there are no users with the DPO role.
140
     */
140
     */
141
    public function test_get_site_dpos_no_dpos() {
141
    public function test_get_site_dpos_no_dpos(): void {
Línea 142... Línea 142...
142
        $this->resetAfterTest();
142
        $this->resetAfterTest();
Línea 143... Línea 143...
143
 
143
 
Línea 150... Línea 150...
150
    }
150
    }
Línea 151... Línea 151...
151
 
151
 
152
    /**
152
    /**
153
     * Test for api::get_site_dpos() when there are no users with the DPO role.
153
     * Test for api::get_site_dpos() when there are no users with the DPO role.
154
     */
154
     */
155
    public function test_get_site_dpos() {
155
    public function test_get_site_dpos(): void {
Línea 156... Línea 156...
156
        global $DB;
156
        global $DB;
Línea 157... Línea 157...
157
 
157
 
Línea 187... Línea 187...
187
    }
187
    }
Línea 188... Línea 188...
188
 
188
 
189
    /**
189
    /**
190
     * Test for \tool_dataprivacy\api::get_assigned_privacy_officer_roles().
190
     * Test for \tool_dataprivacy\api::get_assigned_privacy_officer_roles().
191
     */
191
     */
192
    public function test_get_assigned_privacy_officer_roles() {
192
    public function test_get_assigned_privacy_officer_roles(): void {
Línea 193... Línea 193...
193
        global $DB;
193
        global $DB;
Línea 194... Línea 194...
194
 
194
 
Línea 230... Línea 230...
230
    }
230
    }
Línea 231... Línea 231...
231
 
231
 
232
    /**
232
    /**
233
     * Test for api::approve_data_request().
233
     * Test for api::approve_data_request().
234
     */
234
     */
235
    public function test_approve_data_request() {
235
    public function test_approve_data_request(): void {
Línea 236... Línea 236...
236
        global $DB;
236
        global $DB;
Línea 237... Línea 237...
237
 
237
 
Línea 274... Línea 274...
274
    }
274
    }
Línea 275... Línea 275...
275
 
275
 
276
    /**
276
    /**
277
     * Test for api::approve_data_request() when allow filtering of exports by course.
277
     * Test for api::approve_data_request() when allow filtering of exports by course.
278
     */
278
     */
279
    public function test_approve_data_request_with_allow_filtering() {
279
    public function test_approve_data_request_with_allow_filtering(): void {
280
        global $DB;
280
        global $DB;
281
        $this->resetAfterTest();
281
        $this->resetAfterTest();
282
        set_config('allowfiltering', 1, 'tool_dataprivacy');
282
        set_config('allowfiltering', 1, 'tool_dataprivacy');
Línea 323... Línea 323...
323
    }
323
    }
Línea 324... Línea 324...
324
 
324
 
325
    /**
325
    /**
326
     * Test for api::approve_data_request() when called by a user who doesn't have the DPO role.
326
     * Test for api::approve_data_request() when called by a user who doesn't have the DPO role.
327
     */
327
     */
328
    public function test_approve_data_request_non_dpo_user() {
328
    public function test_approve_data_request_non_dpo_user(): void {
Línea 329... Línea 329...
329
        $this->resetAfterTest();
329
        $this->resetAfterTest();
330
 
330
 
331
        $generator = new testing_data_generator();
331
        $generator = new testing_data_generator();
Línea 345... Línea 345...
345
    }
345
    }
Línea 346... Línea 346...
346
 
346
 
347
    /**
347
    /**
348
     * Test for api::add_request_contexts_with_status().
348
     * Test for api::add_request_contexts_with_status().
349
     */
349
     */
350
    public function test_add_request_contexts_with_status() {
350
    public function test_add_request_contexts_with_status(): void {
351
        global $DB;
351
        global $DB;
352
        $this->resetAfterTest();
352
        $this->resetAfterTest();
Línea 353... Línea 353...
353
        set_config('allowfiltering', 1, 'tool_dataprivacy');
353
        set_config('allowfiltering', 1, 'tool_dataprivacy');
Línea 383... Línea 383...
383
    }
383
    }
Línea 384... Línea 384...
384
 
384
 
385
    /**
385
    /**
386
     * Test that deletion requests for the primary admin are rejected
386
     * Test that deletion requests for the primary admin are rejected
387
     */
387
     */
388
    public function test_reject_data_deletion_request_primary_admin() {
388
    public function test_reject_data_deletion_request_primary_admin(): void {
389
        $this->resetAfterTest();
389
        $this->resetAfterTest();
Línea 390... Línea 390...
390
        $this->setAdminUser();
390
        $this->setAdminUser();
Línea 406... Línea 406...
406
    }
406
    }
Línea 407... Línea 407...
407
 
407
 
408
    /**
408
    /**
409
     * Test for api::can_contact_dpo()
409
     * Test for api::can_contact_dpo()
410
     */
410
     */
411
    public function test_can_contact_dpo() {
411
    public function test_can_contact_dpo(): void {
Línea 412... Línea 412...
412
        $this->resetAfterTest();
412
        $this->resetAfterTest();
413
 
413
 
Línea 424... Línea 424...
424
    }
424
    }
Línea 425... Línea 425...
425
 
425
 
426
    /**
426
    /**
427
     * Test for api::can_manage_data_requests()
427
     * Test for api::can_manage_data_requests()
428
     */
428
     */
429
    public function test_can_manage_data_requests() {
429
    public function test_can_manage_data_requests(): void {
Línea 430... Línea 430...
430
        global $DB;
430
        global $DB;
Línea 431... Línea 431...
431
 
431
 
Línea 469... Línea 469...
469
 
469
 
470
    /**
470
    /**
471
     * Test that a user who has no capability to make any data requests for children cannot create data requests for any
471
     * Test that a user who has no capability to make any data requests for children cannot create data requests for any
472
     * other user.
472
     * other user.
473
     */
473
     */
474
    public function test_can_create_data_request_for_user_no() {
474
    public function test_can_create_data_request_for_user_no(): void {
Línea 475... Línea 475...
475
        $this->resetAfterTest();
475
        $this->resetAfterTest();
476
 
476
 
Línea 483... Línea 483...
483
 
483
 
484
    /**
484
    /**
485
     * Test that a user who has the capability to make any data requests for one other user cannot create data requests
485
     * Test that a user who has the capability to make any data requests for one other user cannot create data requests
486
     * for any other user.
486
     * for any other user.
487
     */
487
     */
488
    public function test_can_create_data_request_for_user_some() {
488
    public function test_can_create_data_request_for_user_some(): void {
Línea 489... Línea 489...
489
        $this->resetAfterTest();
489
        $this->resetAfterTest();
490
 
490
 
491
        $parent = $this->getDataGenerator()->create_user();
491
        $parent = $this->getDataGenerator()->create_user();
Línea 503... Línea 503...
503
 
503
 
504
    /**
504
    /**
505
     * Test that a user who has the capability to make any data requests for one other user cannot create data requests
505
     * Test that a user who has the capability to make any data requests for one other user cannot create data requests
506
     * for any other user.
506
     * for any other user.
507
     */
507
     */
508
    public function test_can_create_data_request_for_user_own_child() {
508
    public function test_can_create_data_request_for_user_own_child(): void {
Línea 509... Línea 509...
509
        $this->resetAfterTest();
509
        $this->resetAfterTest();
510
 
510
 
Línea 522... Línea 522...
522
 
522
 
523
    /**
523
    /**
524
     * Test that a user who has no capability to make any data requests for children cannot create data requests for any
524
     * Test that a user who has no capability to make any data requests for children cannot create data requests for any
525
     * other user.
525
     * other user.
526
     */
526
     */
527
    public function test_require_can_create_data_request_for_user_no() {
527
    public function test_require_can_create_data_request_for_user_no(): void {
Línea 528... Línea 528...
528
        $this->resetAfterTest();
528
        $this->resetAfterTest();
529
 
529
 
Línea 537... Línea 537...
537
 
537
 
538
    /**
538
    /**
539
     * Test that a user who has the capability to make any data requests for one other user cannot create data requests
539
     * Test that a user who has the capability to make any data requests for one other user cannot create data requests
540
     * for any other user.
540
     * for any other user.
541
     */
541
     */
542
    public function test_require_can_create_data_request_for_user_some() {
542
    public function test_require_can_create_data_request_for_user_some(): void {
Línea 543... Línea 543...
543
        $this->resetAfterTest();
543
        $this->resetAfterTest();
544
 
544
 
545
        $parent = $this->getDataGenerator()->create_user();
545
        $parent = $this->getDataGenerator()->create_user();
Línea 558... Línea 558...
558
 
558
 
559
    /**
559
    /**
560
     * Test that a user who has the capability to make any data requests for one other user cannot create data requests
560
     * Test that a user who has the capability to make any data requests for one other user cannot create data requests
561
     * for any other user.
561
     * for any other user.
562
     */
562
     */
563
    public function test_require_can_create_data_request_for_user_own_child() {
563
    public function test_require_can_create_data_request_for_user_own_child(): void {
Línea 564... Línea 564...
564
        $this->resetAfterTest();
564
        $this->resetAfterTest();
565
 
565
 
Línea 576... Línea 576...
576
    }
576
    }
Línea 577... Línea 577...
577
 
577
 
578
    /**
578
    /**
579
     * Test for api::can_download_data_request_for_user()
579
     * Test for api::can_download_data_request_for_user()
580
     */
580
     */
581
    public function test_can_download_data_request_for_user() {
581
    public function test_can_download_data_request_for_user(): void {
Línea 582... Línea 582...
582
        $this->resetAfterTest();
582
        $this->resetAfterTest();
Línea 583... Línea 583...
583
 
583
 
Línea 698... Línea 698...
698
        $automaticapproval,
698
        $automaticapproval,
699
        $expecteddpoval,
699
        $expecteddpoval,
700
        $expectedstatus,
700
        $expectedstatus,
701
        $expectedtaskcount,
701
        $expectedtaskcount,
702
        $allowfiltering,
702
        $allowfiltering,
703
    ) {
703
    ): void {
704
        global $USER;
704
        global $USER;
Línea 705... Línea 705...
705
 
705
 
Línea 706... Línea 706...
706
        $this->resetAfterTest();
706
        $this->resetAfterTest();
Línea 749... Línea 749...
749
    }
749
    }
Línea 750... Línea 750...
750
 
750
 
751
    /**
751
    /**
752
     * Test for api::create_data_request() made by a parent.
752
     * Test for api::create_data_request() made by a parent.
753
     */
753
     */
754
    public function test_create_data_request_by_parent() {
754
    public function test_create_data_request_by_parent(): void {
Línea 755... Línea 755...
755
        global $DB;
755
        global $DB;
Línea 756... Línea 756...
756
 
756
 
Línea 784... Línea 784...
784
    }
784
    }
Línea 785... Línea 785...
785
 
785
 
786
    /**
786
    /**
787
     * Test for api::deny_data_request()
787
     * Test for api::deny_data_request()
788
     */
788
     */
789
    public function test_deny_data_request() {
789
    public function test_deny_data_request(): void {
Línea 790... Línea 790...
790
        $this->resetAfterTest();
790
        $this->resetAfterTest();
791
 
791
 
792
        $generator = new testing_data_generator();
792
        $generator = new testing_data_generator();
Línea 839... Línea 839...
839
     * @dataProvider get_data_requests_provider
839
     * @dataProvider get_data_requests_provider
840
     * @param string $usertype The type of the user logging in.
840
     * @param string $usertype The type of the user logging in.
841
     * @param boolean $fetchall Whether to fetch all records.
841
     * @param boolean $fetchall Whether to fetch all records.
842
     * @param int[] $statuses Status filters.
842
     * @param int[] $statuses Status filters.
843
     */
843
     */
844
    public function test_get_data_requests($usertype, $fetchall, $statuses) {
844
    public function test_get_data_requests($usertype, $fetchall, $statuses): void {
845
        $this->resetAfterTest();
845
        $this->resetAfterTest();
Línea 846... Línea 846...
846
 
846
 
847
        $generator = new testing_data_generator();
847
        $generator = new testing_data_generator();
848
        $user1 = $generator->create_user();
848
        $user1 = $generator->create_user();
Línea 950... Línea 950...
950
    }
950
    }
Línea 951... Línea 951...
951
 
951
 
952
    /**
952
    /**
953
     * Test for api::get_approved_contextlist_collection_for_request.
953
     * Test for api::get_approved_contextlist_collection_for_request.
954
     */
954
     */
955
    public function test_get_approved_contextlist_collection_for_request() {
955
    public function test_get_approved_contextlist_collection_for_request(): void {
956
        $this->resetAfterTest();
956
        $this->resetAfterTest();
957
        set_config('allowfiltering', 1, 'tool_dataprivacy');
957
        set_config('allowfiltering', 1, 'tool_dataprivacy');
Línea 958... Línea 958...
958
        $this->setAdminUser();
958
        $this->setAdminUser();
Línea 1019... Línea 1019...
1019
     *
1019
     *
1020
     * @dataProvider status_provider
1020
     * @dataProvider status_provider
1021
     * @param int $status The request status.
1021
     * @param int $status The request status.
1022
     * @param bool $expected The expected result.
1022
     * @param bool $expected The expected result.
1023
     */
1023
     */
1024
    public function test_has_ongoing_request($status, $expected) {
1024
    public function test_has_ongoing_request($status, $expected): void {
1025
        $this->resetAfterTest();
1025
        $this->resetAfterTest();
Línea 1026... Línea 1026...
1026
 
1026
 
1027
        $generator = new testing_data_generator();
1027
        $generator = new testing_data_generator();
Línea 1043... Línea 1043...
1043
     *
1043
     *
1044
     * @dataProvider status_provider
1044
     * @dataProvider status_provider
1045
     * @param int $status The request status
1045
     * @param int $status The request status
1046
     * @param bool $expected The expected result
1046
     * @param bool $expected The expected result
1047
     */
1047
     */
1048
    public function test_is_active($status, $expected) {
1048
    public function test_is_active($status, $expected): void {
1049
        // Check if this request is ongoing.
1049
        // Check if this request is ongoing.
1050
        $result = api::is_active($status);
1050
        $result = api::is_active($status);
1051
        $this->assertEquals($expected, $result);
1051
        $this->assertEquals($expected, $result);
1052
    }
1052
    }
Línea 1053... Línea 1053...
1053
 
1053
 
1054
    /**
1054
    /**
1055
     * Test for api::is_site_dpo()
1055
     * Test for api::is_site_dpo()
1056
     */
1056
     */
1057
    public function test_is_site_dpo() {
1057
    public function test_is_site_dpo(): void {
Línea 1058... Línea 1058...
1058
        global $DB;
1058
        global $DB;
Línea 1059... Línea 1059...
1059
 
1059
 
Línea 1106... Línea 1106...
1106
     * @param bool $byadmin Whether the admin requests data on behalf of the user
1106
     * @param bool $byadmin Whether the admin requests data on behalf of the user
1107
     * @param int $type The request type
1107
     * @param int $type The request type
1108
     * @param string $typestringid The request lang string identifier
1108
     * @param string $typestringid The request lang string identifier
1109
     * @param string $comments The requestor's message to the DPO.
1109
     * @param string $comments The requestor's message to the DPO.
1110
     */
1110
     */
1111
    public function test_notify_dpo($byadmin, $type, $typestringid, $comments) {
1111
    public function test_notify_dpo($byadmin, $type, $typestringid, $comments): void {
1112
        $this->resetAfterTest();
1112
        $this->resetAfterTest();
Línea 1113... Línea 1113...
1113
 
1113
 
1114
        $generator = new testing_data_generator();
1114
        $generator = new testing_data_generator();
1115
        $user1 = $generator->create_user();
1115
        $user1 = $generator->create_user();
Línea 1148... Línea 1148...
1148
    /**
1148
    /**
1149
     * Test data purposes CRUD actions.
1149
     * Test data purposes CRUD actions.
1150
     *
1150
     *
1151
     * @return null
1151
     * @return null
1152
     */
1152
     */
1153
    public function test_purpose_crud() {
1153
    public function test_purpose_crud(): void {
1154
        $this->resetAfterTest();
1154
        $this->resetAfterTest();
Línea 1155... Línea 1155...
1155
 
1155
 
Línea 1156... Línea 1156...
1156
        $this->setAdminUser();
1156
        $this->setAdminUser();
Línea 1190... Línea 1190...
1190
    /**
1190
    /**
1191
     * Test data categories CRUD actions.
1191
     * Test data categories CRUD actions.
1192
     *
1192
     *
1193
     * @return null
1193
     * @return null
1194
     */
1194
     */
1195
    public function test_category_crud() {
1195
    public function test_category_crud(): void {
1196
        $this->resetAfterTest();
1196
        $this->resetAfterTest();
Línea 1197... Línea 1197...
1197
 
1197
 
Línea 1198... Línea 1198...
1198
        $this->setAdminUser();
1198
        $this->setAdminUser();
Línea 1228... Línea 1228...
1228
    /**
1228
    /**
1229
     * Test context instances.
1229
     * Test context instances.
1230
     *
1230
     *
1231
     * @return null
1231
     * @return null
1232
     */
1232
     */
1233
    public function test_context_instances() {
1233
    public function test_context_instances(): void {
1234
        global $DB;
1234
        global $DB;
Línea 1235... Línea 1235...
1235
 
1235
 
Línea 1236... Línea 1236...
1236
        $this->resetAfterTest();
1236
        $this->resetAfterTest();
Línea 1264... Línea 1264...
1264
    /**
1264
    /**
1265
     * Test contextlevel.
1265
     * Test contextlevel.
1266
     *
1266
     *
1267
     * @return null
1267
     * @return null
1268
     */
1268
     */
1269
    public function test_contextlevel() {
1269
    public function test_contextlevel(): void {
1270
        global $DB;
1270
        global $DB;
Línea 1271... Línea 1271...
1271
 
1271
 
Línea 1272... Línea 1272...
1272
        $this->resetAfterTest();
1272
        $this->resetAfterTest();
Línea 1300... Línea 1300...
1300
    /**
1300
    /**
1301
     * Test effective context levels purpose and category defaults.
1301
     * Test effective context levels purpose and category defaults.
1302
     *
1302
     *
1303
     * @return null
1303
     * @return null
1304
     */
1304
     */
1305
    public function test_effective_contextlevel_defaults() {
1305
    public function test_effective_contextlevel_defaults(): void {
1306
        $this->setAdminUser();
1306
        $this->setAdminUser();
Línea 1307... Línea 1307...
1307
 
1307
 
Línea 1308... Línea 1308...
1308
        $this->resetAfterTest();
1308
        $this->resetAfterTest();
Línea 1338... Línea 1338...
1338
    }
1338
    }
Línea 1339... Línea 1339...
1339
 
1339
 
1340
    /**
1340
    /**
1341
     * Ensure that when nothing is configured, all values return false.
1341
     * Ensure that when nothing is configured, all values return false.
1342
     */
1342
     */
1343
    public function test_get_effective_contextlevel_unset() {
1343
    public function test_get_effective_contextlevel_unset(): void {
1344
        // Before setup, get_effective_contextlevel_purpose will return false.
1344
        // Before setup, get_effective_contextlevel_purpose will return false.
1345
        $this->assertFalse(api::get_effective_contextlevel_category(CONTEXT_SYSTEM));
1345
        $this->assertFalse(api::get_effective_contextlevel_category(CONTEXT_SYSTEM));
Línea 1346... Línea 1346...
1346
        $this->assertFalse(api::get_effective_contextlevel_purpose(CONTEXT_SYSTEM));
1346
        $this->assertFalse(api::get_effective_contextlevel_purpose(CONTEXT_SYSTEM));
Línea 1350... Línea 1350...
1350
    }
1350
    }
Línea 1351... Línea 1351...
1351
 
1351
 
1352
    /**
1352
    /**
1353
     * Ensure that when nothing is configured, all values return false.
1353
     * Ensure that when nothing is configured, all values return false.
1354
     */
1354
     */
1355
    public function test_get_effective_context_unset() {
1355
    public function test_get_effective_context_unset(): void {
1356
        // Before setup, get_effective_contextlevel_purpose will return false.
1356
        // Before setup, get_effective_contextlevel_purpose will return false.
1357
        $this->assertFalse(api::get_effective_context_category(\context_system::instance()));
1357
        $this->assertFalse(api::get_effective_context_category(\context_system::instance()));
1358
        $this->assertFalse(api::get_effective_context_purpose(\context_system::instance()));
1358
        $this->assertFalse(api::get_effective_context_purpose(\context_system::instance()));
Línea 1362... Línea 1362...
1362
     * Ensure that fetching the effective value for context levels is only available to system, and user context levels.
1362
     * Ensure that fetching the effective value for context levels is only available to system, and user context levels.
1363
     *
1363
     *
1364
     * @dataProvider invalid_effective_contextlevel_provider
1364
     * @dataProvider invalid_effective_contextlevel_provider
1365
     * @param   int $contextlevel
1365
     * @param   int $contextlevel
1366
     */
1366
     */
1367
    public function test_set_contextlevel_invalid_contextlevels($contextlevel) {
1367
    public function test_set_contextlevel_invalid_contextlevels($contextlevel): void {
Línea 1368... Línea 1368...
1368
 
1368
 
1369
        $this->expectException(\coding_exception::class);
1369
        $this->expectException(\coding_exception::class);
1370
        api::set_contextlevel((object) [
1370
        api::set_contextlevel((object) [
1371
                'contextlevel' => $contextlevel,
1371
                'contextlevel' => $contextlevel,
Línea 1374... Línea 1374...
1374
    }
1374
    }
Línea 1375... Línea 1375...
1375
 
1375
 
1376
    /**
1376
    /**
1377
     * Test effective contextlevel return.
1377
     * Test effective contextlevel return.
1378
     */
1378
     */
1379
    public function test_effective_contextlevel() {
1379
    public function test_effective_contextlevel(): void {
Línea 1380... Línea 1380...
1380
        $this->resetAfterTest();
1380
        $this->resetAfterTest();
1381
 
1381
 
1382
        // Set the initial purpose and category.
1382
        // Set the initial purpose and category.
Línea 1422... Línea 1422...
1422
     * Ensure that fetching the effective value for context levels is only available to system, and user context levels.
1422
     * Ensure that fetching the effective value for context levels is only available to system, and user context levels.
1423
     *
1423
     *
1424
     * @dataProvider invalid_effective_contextlevel_provider
1424
     * @dataProvider invalid_effective_contextlevel_provider
1425
     * @param   int $contextlevel
1425
     * @param   int $contextlevel
1426
     */
1426
     */
1427
    public function test_effective_contextlevel_invalid_contextlevels($contextlevel) {
1427
    public function test_effective_contextlevel_invalid_contextlevels($contextlevel): void {
1428
        $this->resetAfterTest();
1428
        $this->resetAfterTest();
Línea 1429... Línea 1429...
1429
 
1429
 
1430
        $purpose1 = api::create_purpose((object)['name' => 'p1', 'retentionperiod' => 'PT1H', 'lawfulbases' => 'gdpr_art_6_1_a']);
1430
        $purpose1 = api::create_purpose((object)['name' => 'p1', 'retentionperiod' => 'PT1H', 'lawfulbases' => 'gdpr_art_6_1_a']);
1431
        $category1 = api::create_category((object)['name' => 'a']);
1431
        $category1 = api::create_category((object)['name' => 'a']);
Línea 1452... Línea 1452...
1452
    }
1452
    }
Línea 1453... Línea 1453...
1453
 
1453
 
1454
    /**
1454
    /**
1455
     * Ensure that context inheritance works up the context tree.
1455
     * Ensure that context inheritance works up the context tree.
1456
     */
1456
     */
1457
    public function test_effective_context_inheritance() {
1457
    public function test_effective_context_inheritance(): void {
Línea 1458... Línea 1458...
1458
        $this->resetAfterTest();
1458
        $this->resetAfterTest();
Línea 1459... Línea 1459...
1459
 
1459
 
Línea 1732... Línea 1732...
1732
     * contextlevel.
1732
     * contextlevel.
1733
     *
1733
     *
1734
     * Although it should not be possible to set hard INHERIT values at this level, there may be legacy data which still
1734
     * Although it should not be possible to set hard INHERIT values at this level, there may be legacy data which still
1735
     * contains this.
1735
     * contains this.
1736
     */
1736
     */
1737
    public function test_effective_context_inheritance_explicitly_set() {
1737
    public function test_effective_context_inheritance_explicitly_set(): void {
1738
        $this->resetAfterTest();
1738
        $this->resetAfterTest();
Línea 1739... Línea 1739...
1739
 
1739
 
Línea 1740... Línea 1740...
1740
        $systemdata = $this->create_and_set_purpose_for_contextlevel('PT1S', CONTEXT_SYSTEM);
1740
        $systemdata = $this->create_and_set_purpose_for_contextlevel('PT1S', CONTEXT_SYSTEM);
Línea 1859... Línea 1859...
1859
    }
1859
    }
Línea 1860... Línea 1860...
1860
 
1860
 
1861
    /**
1861
    /**
1862
     * Test that delete requests do not filter out protected purpose contexts if the the site is properly configured.
1862
     * Test that delete requests do not filter out protected purpose contexts if the the site is properly configured.
1863
     */
1863
     */
1864
    public function test_get_approved_contextlist_collection_for_collection_delete_course_no_site_config() {
1864
    public function test_get_approved_contextlist_collection_for_collection_delete_course_no_site_config(): void {
Línea 1865... Línea 1865...
1865
        $this->resetAfterTest();
1865
        $this->resetAfterTest();
Línea 1866... Línea 1866...
1866
 
1866
 
Línea 1901... Línea 1901...
1901
    }
1901
    }
Línea 1902... Línea 1902...
1902
 
1902
 
1903
    /**
1903
    /**
1904
     * Test that delete requests do not filter out protected purpose contexts if they are already expired.
1904
     * Test that delete requests do not filter out protected purpose contexts if they are already expired.
1905
     */
1905
     */
1906
    public function test_get_approved_contextlist_collection_for_collection_delete_course_expired_protected() {
1906
    public function test_get_approved_contextlist_collection_for_collection_delete_course_expired_protected(): void {
Línea 1907... Línea 1907...
1907
        $this->resetAfterTest();
1907
        $this->resetAfterTest();
1908
 
1908
 
Línea 1934... Línea 1934...
1934
    }
1934
    }
Línea 1935... Línea 1935...
1935
 
1935
 
1936
    /**
1936
    /**
1937
     * Test that delete requests does filter out protected purpose contexts which are not expired.
1937
     * Test that delete requests does filter out protected purpose contexts which are not expired.
1938
     */
1938
     */
1939
    public function test_get_approved_contextlist_collection_for_collection_delete_course_unexpired_protected() {
1939
    public function test_get_approved_contextlist_collection_for_collection_delete_course_unexpired_protected(): void {
Línea 1940... Línea 1940...
1940
        $this->resetAfterTest();
1940
        $this->resetAfterTest();
1941
 
1941
 
Línea 1967... Línea 1967...
1967
    }
1967
    }
Línea 1968... Línea 1968...
1968
 
1968
 
1969
    /**
1969
    /**
1970
     * Test that delete requests do not filter out unexpired contexts if they are not protected.
1970
     * Test that delete requests do not filter out unexpired contexts if they are not protected.
1971
     */
1971
     */
1972
    public function test_get_approved_contextlist_collection_for_collection_delete_course_unexpired_unprotected() {
1972
    public function test_get_approved_contextlist_collection_for_collection_delete_course_unexpired_unprotected(): void {
Línea 1973... Línea 1973...
1973
        $this->resetAfterTest();
1973
        $this->resetAfterTest();
1974
 
1974
 
Línea 2038... Línea 2038...
2038
     * @param bool $inheritcategory Whether to set category value as INHERIT.
2038
     * @param bool $inheritcategory Whether to set category value as INHERIT.
2039
     * @param bool $inheritpurpose Whether to set purpose value as INHERIT.
2039
     * @param bool $inheritpurpose Whether to set purpose value as INHERIT.
2040
     * @param bool $foractivity Whether to set defaults for an activity.
2040
     * @param bool $foractivity Whether to set defaults for an activity.
2041
     * @param bool $override Whether to override instances.
2041
     * @param bool $override Whether to override instances.
2042
     */
2042
     */
2043
    public function test_set_context_defaults($contextlevel, $inheritcategory, $inheritpurpose, $foractivity, $override) {
2043
    public function test_set_context_defaults($contextlevel, $inheritcategory, $inheritpurpose, $foractivity, $override): void {
2044
        $this->resetAfterTest();
2044
        $this->resetAfterTest();
Línea 2045... Línea 2045...
2045
 
2045
 
Línea 2046... Línea 2046...
2046
        $generator = $this->getDataGenerator();
2046
        $generator = $this->getDataGenerator();
Línea 2222... Línea 2222...
2222
    }
2222
    }
Línea 2223... Línea 2223...
2223
 
2223
 
2224
    /**
2224
    /**
2225
     * Ensure that the find_ongoing_request_types_for_users only returns requests which are active.
2225
     * Ensure that the find_ongoing_request_types_for_users only returns requests which are active.
2226
     */
2226
     */
2227
    public function test_find_ongoing_request_types_for_users() {
2227
    public function test_find_ongoing_request_types_for_users(): void {
Línea 2228... Línea 2228...
2228
        $this->resetAfterTest();
2228
        $this->resetAfterTest();
2229
 
2229
 
2230
        // Create users and their requests:.
2230
        // Create users and their requests:.
Línea 2358... Línea 2358...
2358
     * Test user cannot create data deletion request for themselves if they don't have
2358
     * Test user cannot create data deletion request for themselves if they don't have
2359
     * "tool/dataprivacy:requestdelete" capability.
2359
     * "tool/dataprivacy:requestdelete" capability.
2360
     *
2360
     *
2361
     * @throws coding_exception
2361
     * @throws coding_exception
2362
     */
2362
     */
2363
    public function test_can_create_data_deletion_request_for_self_no() {
2363
    public function test_can_create_data_deletion_request_for_self_no(): void {
2364
        $this->resetAfterTest();
2364
        $this->resetAfterTest();
2365
        $userid = $this->getDataGenerator()->create_user()->id;
2365
        $userid = $this->getDataGenerator()->create_user()->id;
2366
        $roleid = $this->getDataGenerator()->create_role();
2366
        $roleid = $this->getDataGenerator()->create_role();
2367
        assign_capability('tool/dataprivacy:requestdelete', CAP_PROHIBIT, $roleid, \context_user::instance($userid));
2367
        assign_capability('tool/dataprivacy:requestdelete', CAP_PROHIBIT, $roleid, \context_user::instance($userid));
2368
        role_assign($roleid, $userid, \context_user::instance($userid));
2368
        role_assign($roleid, $userid, \context_user::instance($userid));
Línea 2371... Línea 2371...
2371
    }
2371
    }
Línea 2372... Línea 2372...
2372
 
2372
 
2373
    /**
2373
    /**
2374
     * Test primary admin cannot create data deletion request for themselves
2374
     * Test primary admin cannot create data deletion request for themselves
2375
     */
2375
     */
2376
    public function test_can_create_data_deletion_request_for_self_primary_admin() {
2376
    public function test_can_create_data_deletion_request_for_self_primary_admin(): void {
2377
        $this->resetAfterTest();
2377
        $this->resetAfterTest();
2378
        $this->setAdminUser();
2378
        $this->setAdminUser();
2379
        $this->assertFalse(api::can_create_data_deletion_request_for_self());
2379
        $this->assertFalse(api::can_create_data_deletion_request_for_self());
Línea 2380... Línea 2380...
2380
    }
2380
    }
2381
 
2381
 
2382
    /**
2382
    /**
2383
     * Test secondary admin can create data deletion request for themselves
2383
     * Test secondary admin can create data deletion request for themselves
2384
     */
2384
     */
Línea 2385... Línea 2385...
2385
    public function test_can_create_data_deletion_request_for_self_secondary_admin() {
2385
    public function test_can_create_data_deletion_request_for_self_secondary_admin(): void {
2386
        $this->resetAfterTest();
2386
        $this->resetAfterTest();
Línea 2401... Línea 2401...
2401
     * Test user can create data deletion request for themselves if they have
2401
     * Test user can create data deletion request for themselves if they have
2402
     * "tool/dataprivacy:requestdelete" capability.
2402
     * "tool/dataprivacy:requestdelete" capability.
2403
     *
2403
     *
2404
     * @throws coding_exception
2404
     * @throws coding_exception
2405
     */
2405
     */
2406
    public function test_can_create_data_deletion_request_for_self_yes() {
2406
    public function test_can_create_data_deletion_request_for_self_yes(): void {
2407
        $this->resetAfterTest();
2407
        $this->resetAfterTest();
2408
        $userid = $this->getDataGenerator()->create_user()->id;
2408
        $userid = $this->getDataGenerator()->create_user()->id;
2409
        $this->setUser($userid);
2409
        $this->setUser($userid);
2410
        $this->assertTrue(api::can_create_data_deletion_request_for_self());
2410
        $this->assertTrue(api::can_create_data_deletion_request_for_self());
2411
    }
2411
    }
Línea 2415... Línea 2415...
2415
     * don't have "tool/dataprivacy:requestdeleteforotheruser" capability.
2415
     * don't have "tool/dataprivacy:requestdeleteforotheruser" capability.
2416
     *
2416
     *
2417
     * @throws coding_exception
2417
     * @throws coding_exception
2418
     * @throws dml_exception
2418
     * @throws dml_exception
2419
     */
2419
     */
2420
    public function test_can_create_data_deletion_request_for_other_no() {
2420
    public function test_can_create_data_deletion_request_for_other_no(): void {
2421
        $this->resetAfterTest();
2421
        $this->resetAfterTest();
2422
        $userid = $this->getDataGenerator()->create_user()->id;
2422
        $userid = $this->getDataGenerator()->create_user()->id;
2423
        $this->setUser($userid);
2423
        $this->setUser($userid);
2424
        $this->assertFalse(api::can_create_data_deletion_request_for_other());
2424
        $this->assertFalse(api::can_create_data_deletion_request_for_other());
2425
    }
2425
    }
Línea 2428... Línea 2428...
2428
     * Test user can create data deletion request for another user if they
2428
     * Test user can create data deletion request for another user if they
2429
     * don't have "tool/dataprivacy:requestdeleteforotheruser" capability.
2429
     * don't have "tool/dataprivacy:requestdeleteforotheruser" capability.
2430
     *
2430
     *
2431
     * @throws coding_exception
2431
     * @throws coding_exception
2432
     */
2432
     */
2433
    public function test_can_create_data_deletion_request_for_other_yes() {
2433
    public function test_can_create_data_deletion_request_for_other_yes(): void {
2434
        $this->resetAfterTest();
2434
        $this->resetAfterTest();
2435
        $userid = $this->getDataGenerator()->create_user()->id;
2435
        $userid = $this->getDataGenerator()->create_user()->id;
2436
        $roleid = $this->getDataGenerator()->create_role();
2436
        $roleid = $this->getDataGenerator()->create_role();
2437
        $contextsystem = \context_system::instance();
2437
        $contextsystem = \context_system::instance();
2438
        assign_capability('tool/dataprivacy:requestdeleteforotheruser', CAP_ALLOW, $roleid, $contextsystem);
2438
        assign_capability('tool/dataprivacy:requestdeleteforotheruser', CAP_ALLOW, $roleid, $contextsystem);
Línea 2446... Línea 2446...
2446
     * but not other users.
2446
     * but not other users.
2447
     *
2447
     *
2448
     * @throws coding_exception
2448
     * @throws coding_exception
2449
     * @throws dml_exception
2449
     * @throws dml_exception
2450
     */
2450
     */
2451
    public function test_can_create_data_deletion_request_for_children() {
2451
    public function test_can_create_data_deletion_request_for_children(): void {
2452
        $this->resetAfterTest();
2452
        $this->resetAfterTest();
Línea 2453... Línea 2453...
2453
 
2453
 
2454
        $parent = $this->getDataGenerator()->create_user();
2454
        $parent = $this->getDataGenerator()->create_user();
2455
        $child = $this->getDataGenerator()->create_user();
2455
        $child = $this->getDataGenerator()->create_user();
Línea 2488... Línea 2488...
2488
     * Test for \tool_dataprivacy\api::queue_data_request_task().
2488
     * Test for \tool_dataprivacy\api::queue_data_request_task().
2489
     *
2489
     *
2490
     * @dataProvider queue_data_request_task_provider
2490
     * @dataProvider queue_data_request_task_provider
2491
     * @param bool $withuserid
2491
     * @param bool $withuserid
2492
     */
2492
     */
2493
    public function test_queue_data_request_task(bool $withuserid) {
2493
    public function test_queue_data_request_task(bool $withuserid): void {
2494
        $this->resetAfterTest();
2494
        $this->resetAfterTest();
Línea 2495... Línea 2495...
2495
 
2495
 
Línea 2496... Línea 2496...
2496
        $this->setAdminUser();
2496
        $this->setAdminUser();
Línea 2544... Línea 2544...
2544
     * @param string $setting The automatic approval setting.
2544
     * @param string $setting The automatic approval setting.
2545
     * @param int $type The data request type.
2545
     * @param int $type The data request type.
2546
     * @param bool $value The setting's value.
2546
     * @param bool $value The setting's value.
2547
     * @param bool $expected The expected result.
2547
     * @param bool $expected The expected result.
2548
     */
2548
     */
2549
    public function test_is_automatic_request_approval_on($setting, $type, $value, $expected) {
2549
    public function test_is_automatic_request_approval_on($setting, $type, $value, $expected): void {
2550
        $this->resetAfterTest();
2550
        $this->resetAfterTest();
Línea 2551... Línea 2551...
2551
 
2551
 
2552
        if ($value !== null) {
2552
        if ($value !== null) {
2553
            set_config($setting, $value, 'tool_dataprivacy');
2553
            set_config($setting, $value, 'tool_dataprivacy');
Línea 2711... Línea 2711...
2711
    }
2711
    }
Línea 2712... Línea 2712...
2712
 
2712
 
2713
    /**
2713
    /**
2714
     * Test api validate_create_data_request.
2714
     * Test api validate_create_data_request.
2715
     */
2715
     */
2716
    public function test_validate_create_data_request() {
2716
    public function test_validate_create_data_request(): void {
Línea 2717... Línea 2717...
2717
        $this->resetAfterTest();
2717
        $this->resetAfterTest();
2718
 
2718
 
2719
        $systemcontext = \context_system::instance();
2719
        $systemcontext = \context_system::instance();