Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 132... Línea 132...
132
    }
132
    }
Línea 133... Línea 133...
133
 
133
 
134
    /**
134
    /**
135
     * Test get databases by courses
135
     * Test get databases by courses
136
     */
136
     */
137
    public function test_mod_data_get_databases_by_courses() {
137
    public function test_mod_data_get_databases_by_courses(): void {
Línea 138... Línea 138...
138
        global $DB;
138
        global $DB;
Línea 139... Línea 139...
139
 
139
 
Línea 276... Línea 276...
276
    }
276
    }
Línea 277... Línea 277...
277
 
277
 
278
    /**
278
    /**
279
     * Test view_database invalid id.
279
     * Test view_database invalid id.
280
     */
280
     */
Línea 281... Línea 281...
281
    public function test_view_database_invalid_id() {
281
    public function test_view_database_invalid_id(): void {
282
 
282
 
283
        // Test invalid instance id.
283
        // Test invalid instance id.
284
        $this->expectException('moodle_exception');
284
        $this->expectException('moodle_exception');
Línea 285... Línea 285...
285
        mod_data_external::view_database(0);
285
        mod_data_external::view_database(0);
286
    }
286
    }
287
 
287
 
288
    /**
288
    /**
Línea 289... Línea 289...
289
     * Test view_database not enrolled user.
289
     * Test view_database not enrolled user.
290
     */
290
     */
Línea 291... Línea 291...
291
    public function test_view_database_not_enrolled_user() {
291
    public function test_view_database_not_enrolled_user(): void {
Línea 298... Línea 298...
298
    }
298
    }
Línea 299... Línea 299...
299
 
299
 
300
    /**
300
    /**
301
     * Test view_database no capabilities.
301
     * Test view_database no capabilities.
302
     */
302
     */
303
    public function test_view_database_no_capabilities() {
303
    public function test_view_database_no_capabilities(): void {
304
        // Test user with no capabilities.
304
        // Test user with no capabilities.
305
        // We need a explicit prohibit since this capability is allowed for students by default.
305
        // We need a explicit prohibit since this capability is allowed for students by default.
306
        assign_capability('mod/data:view', CAP_PROHIBIT, $this->studentrole->id, $this->context->id);
306
        assign_capability('mod/data:view', CAP_PROHIBIT, $this->studentrole->id, $this->context->id);
Línea 311... Línea 311...
311
    }
311
    }
Línea 312... Línea 312...
312
 
312
 
313
    /**
313
    /**
314
     * Test view_database.
314
     * Test view_database.
315
     */
315
     */
Línea 316... Línea 316...
316
    public function test_view_database() {
316
    public function test_view_database(): void {
317
 
317
 
Línea 318... Línea 318...
318
        // Test user with full capabilities.
318
        // Test user with full capabilities.
Línea 338... Línea 338...
338
    }
338
    }
Línea 339... Línea 339...
339
 
339
 
340
    /**
340
    /**
341
     * Test get_data_access_information for student.
341
     * Test get_data_access_information for student.
342
     */
342
     */
343
    public function test_get_data_access_information_student() {
343
    public function test_get_data_access_information_student(): void {
Línea 344... Línea 344...
344
        global $DB;
344
        global $DB;
345
 
345
 
Línea 371... Línea 371...
371
    }
371
    }
Línea 372... Línea 372...
372
 
372
 
373
    /**
373
    /**
374
     * Test get_data_access_information for teacher.
374
     * Test get_data_access_information for teacher.
375
     */
375
     */
376
    public function test_get_data_access_information_teacher() {
376
    public function test_get_data_access_information_teacher(): void {
Línea 377... Línea 377...
377
        global $DB;
377
        global $DB;
378
 
378
 
Línea 404... Línea 404...
404
    }
404
    }
Línea 405... Línea 405...
405
 
405
 
406
    /**
406
    /**
407
     * Test get_data_access_information with groups.
407
     * Test get_data_access_information with groups.
408
     */
408
     */
409
    public function test_get_data_access_information_groups() {
409
    public function test_get_data_access_information_groups(): void {
Línea 410... Línea 410...
410
        global $DB;
410
        global $DB;
411
 
411
 
Línea 511... Línea 511...
511
    }
511
    }
Línea 512... Línea 512...
512
 
512
 
513
    /**
513
    /**
514
     * Test get_entries
514
     * Test get_entries
515
     */
515
     */
516
    public function test_get_entries() {
516
    public function test_get_entries(): void {
Línea 517... Línea 517...
517
        global $DB;
517
        global $DB;
518
 
518
 
519
        // Check the behaviour when the database has no entries.
519
        // Check the behaviour when the database has no entries.
Línea 643... Línea 643...
643
    }
643
    }
Línea 644... Línea 644...
644
 
644
 
645
    /**
645
    /**
646
     * Test get_entry_visible_groups.
646
     * Test get_entry_visible_groups.
647
     */
647
     */
648
    public function test_get_entry_visible_groups() {
648
    public function test_get_entry_visible_groups(): void {
Línea 649... Línea 649...
649
        global $DB;
649
        global $DB;
650
 
650
 
Línea 668... Línea 668...
668
    }
668
    }
Línea 669... Línea 669...
669
 
669
 
670
    /**
670
    /**
671
     * Test get_entry_separated_groups.
671
     * Test get_entry_separated_groups.
672
     */
672
     */
673
    public function test_get_entry_separated_groups() {
673
    public function test_get_entry_separated_groups(): void {
674
        global $DB;
674
        global $DB;
Línea 675... Línea 675...
675
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
675
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
676
 
676
 
Línea 736... Línea 736...
736
    }
736
    }
Línea 737... Línea 737...
737
 
737
 
738
    /**
738
    /**
739
     * Test get_entry from other group in separated groups.
739
     * Test get_entry from other group in separated groups.
740
     */
740
     */
741
    public function test_get_entry_other_group_separated_groups() {
741
    public function test_get_entry_other_group_separated_groups(): void {
Línea 742... Línea 742...
742
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
742
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
743
 
743
 
744
        // We should not be able to view other gropu entries (in separated groups).
744
        // We should not be able to view other gropu entries (in separated groups).
Línea 748... Línea 748...
748
    }
748
    }
Línea 749... Línea 749...
749
 
749
 
750
    /**
750
    /**
751
     * Test get_fields.
751
     * Test get_fields.
752
     */
752
     */
753
    public function test_get_fields() {
753
    public function test_get_fields(): void {
754
        global $DB;
754
        global $DB;
Línea 755... Línea 755...
755
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
755
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
756
 
756
 
Línea 766... Línea 766...
766
    }
766
    }
Línea 767... Línea 767...
767
 
767
 
768
    /**
768
    /**
769
     * Test get_fields_database_without_fields.
769
     * Test get_fields_database_without_fields.
770
     */
770
     */
Línea 771... Línea 771...
771
    public function test_get_fields_database_without_fields() {
771
    public function test_get_fields_database_without_fields(): void {
772
 
772
 
773
        $this->setUser($this->student1);
773
        $this->setUser($this->student1);
Línea 778... Línea 778...
778
    }
778
    }
Línea 779... Línea 779...
779
 
779
 
780
    /**
780
    /**
781
     * Test search_entries.
781
     * Test search_entries.
782
     */
782
     */
783
    public function test_search_entries() {
783
    public function test_search_entries(): void {
784
        global $DB;
784
        global $DB;
Línea 785... Línea 785...
785
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
785
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
786
 
786
 
Línea 890... Línea 890...
890
    }
890
    }
Línea 891... Línea 891...
891
 
891
 
892
    /**
892
    /**
893
     * Test approve_entry.
893
     * Test approve_entry.
894
     */
894
     */
895
    public function test_approve_entry() {
895
    public function test_approve_entry(): void {
896
        global $DB;
896
        global $DB;
Línea 897... Línea 897...
897
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
897
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
898
 
898
 
Línea 904... Línea 904...
904
    }
904
    }
Línea 905... Línea 905...
905
 
905
 
906
    /**
906
    /**
907
     * Test unapprove_entry.
907
     * Test unapprove_entry.
908
     */
908
     */
909
    public function test_unapprove_entry() {
909
    public function test_unapprove_entry(): void {
910
        global $DB;
910
        global $DB;
Línea 911... Línea 911...
911
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
911
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
912
 
912
 
Línea 918... Línea 918...
918
    }
918
    }
Línea 919... Línea 919...
919
 
919
 
920
    /**
920
    /**
921
     * Test approve_entry missing permissions.
921
     * Test approve_entry missing permissions.
922
     */
922
     */
923
    public function test_approve_entry_missing_permissions() {
923
    public function test_approve_entry_missing_permissions(): void {
924
        global $DB;
924
        global $DB;
Línea 925... Línea 925...
925
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
925
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
926
 
926
 
Línea 930... Línea 930...
930
    }
930
    }
Línea 931... Línea 931...
931
 
931
 
932
    /**
932
    /**
933
     * Test delete_entry as teacher. Check I can delete any entry.
933
     * Test delete_entry as teacher. Check I can delete any entry.
934
     */
934
     */
935
    public function test_delete_entry_as_teacher() {
935
    public function test_delete_entry_as_teacher(): void {
936
        global $DB;
936
        global $DB;
Línea 937... Línea 937...
937
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
937
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
938
 
938
 
Línea 948... Línea 948...
948
    }
948
    }
Línea 949... Línea 949...
949
 
949
 
950
    /**
950
    /**
951
     * Test delete_entry as student. Check I can delete my own entries.
951
     * Test delete_entry as student. Check I can delete my own entries.
952
     */
952
     */
953
    public function test_delete_entry_as_student() {
953
    public function test_delete_entry_as_student(): void {
954
        global $DB;
954
        global $DB;
Línea 955... Línea 955...
955
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
955
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
956
 
956
 
Línea 961... Línea 961...
961
    }
961
    }
Línea 962... Línea 962...
962
 
962
 
963
    /**
963
    /**
964
     * Test delete_entry as student in read only mode period. Check I cannot delete my own entries in that period.
964
     * Test delete_entry as student in read only mode period. Check I cannot delete my own entries in that period.
965
     */
965
     */
966
    public function test_delete_entry_as_student_in_read_only_period() {
966
    public function test_delete_entry_as_student_in_read_only_period(): void {
967
        global $DB;
967
        global $DB;
968
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
968
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
969
        // Set a time period.
969
        // Set a time period.
970
        $this->database->timeviewfrom = time() - HOURSECS;
970
        $this->database->timeviewfrom = time() - HOURSECS;
Línea 977... Línea 977...
977
    }
977
    }
Línea 978... Línea 978...
978
 
978
 
979
    /**
979
    /**
980
     * Test delete_entry with an user missing permissions.
980
     * Test delete_entry with an user missing permissions.
981
     */
981
     */
982
    public function test_delete_entry_missing_permissions() {
982
    public function test_delete_entry_missing_permissions(): void {
983
        global $DB;
983
        global $DB;
Línea 984... Línea 984...
984
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
984
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
985
 
985
 
Línea 989... Línea 989...
989
    }
989
    }
Línea 990... Línea 990...
990
 
990
 
991
    /**
991
    /**
992
     * Test add_entry.
992
     * Test add_entry.
993
     */
993
     */
994
    public function test_add_entry() {
994
    public function test_add_entry(): void {
995
        global $DB;
995
        global $DB;
996
        // First create the record structure and add some entries.
996
        // First create the record structure and add some entries.
Línea 997... Línea 997...
997
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
997
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
Línea 1129... Línea 1129...
1129
    }
1129
    }
Línea 1130... Línea 1130...
1130
 
1130
 
1131
    /**
1131
    /**
1132
     * Test add_entry empty_form.
1132
     * Test add_entry empty_form.
1133
     */
1133
     */
Línea 1134... Línea 1134...
1134
    public function test_add_entry_empty_form() {
1134
    public function test_add_entry_empty_form(): void {
1135
 
1135
 
Línea 1136... Línea 1136...
1136
        // Add a field to database to let users add new entries.
1136
        // Add a field to database to let users add new entries.
Línea 1145... Línea 1145...
1145
    }
1145
    }
Línea 1146... Línea 1146...
1146
 
1146
 
1147
    /**
1147
    /**
1148
     * Test add_entry read_only_period.
1148
     * Test add_entry read_only_period.
1149
     */
1149
     */
1150
    public function test_add_entry_read_only_period() {
1150
    public function test_add_entry_read_only_period(): void {
1151
        global $DB;
1151
        global $DB;
1152
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
1152
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
1153
        // Set a time period.
1153
        // Set a time period.
1154
        $this->database->timeviewfrom = time() - HOURSECS;
1154
        $this->database->timeviewfrom = time() - HOURSECS;
Línea 1162... Línea 1162...
1162
    }
1162
    }
Línea 1163... Línea 1163...
1163
 
1163
 
1164
    /**
1164
    /**
1165
     * Test add_entry max_num_entries.
1165
     * Test add_entry max_num_entries.
1166
     */
1166
     */
1167
    public function test_add_entry_max_num_entries() {
1167
    public function test_add_entry_max_num_entries(): void {
1168
        global $DB;
1168
        global $DB;
1169
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
1169
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
1170
        // Set a time period.
1170
        // Set a time period.
1171
        $this->database->maxentries = 1;
1171
        $this->database->maxentries = 1;
Línea 1178... Línea 1178...
1178
    }
1178
    }
Línea 1179... Línea 1179...
1179
 
1179
 
1180
    /**
1180
    /**
1181
     * Test add_entry invalid group.
1181
     * Test add_entry invalid group.
1182
     */
1182
     */
Línea 1183... Línea 1183...
1183
    public function test_add_entry_invalid_group() {
1183
    public function test_add_entry_invalid_group(): void {
1184
 
1184
 
Línea 1185... Línea 1185...
1185
        // Add a field to database to let users add new entries.
1185
        // Add a field to database to let users add new entries.
Línea 1194... Línea 1194...
1194
    /**
1194
    /**
1195
     * Test add_entry for an empty database (no fields).
1195
     * Test add_entry for an empty database (no fields).
1196
     *
1196
     *
1197
     * @covers ::add_entry
1197
     * @covers ::add_entry
1198
     */
1198
     */
1199
    public function test_add_entry_empty_database() {
1199
    public function test_add_entry_empty_database(): void {
1200
        $this->expectException('moodle_exception');
1200
        $this->expectException('moodle_exception');
1201
        mod_data_external::add_entry($this->database->id, 0, []);
1201
        mod_data_external::add_entry($this->database->id, 0, []);
1202
    }
1202
    }
Línea 1203... Línea 1203...
1203
 
1203
 
1204
    /**
1204
    /**
1205
     * Test update_entry.
1205
     * Test update_entry.
1206
     */
1206
     */
1207
    public function test_update_entry() {
1207
    public function test_update_entry(): void {
1208
        global $DB;
1208
        global $DB;
1209
        // First create the record structure and add some entries.
1209
        // First create the record structure and add some entries.
Línea 1210... Línea 1210...
1210
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
1210
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
Línea 1344... Línea 1344...
1344
    }
1344
    }
Línea 1345... Línea 1345...
1345
 
1345
 
1346
    /**
1346
    /**
1347
     * Test update_entry sending empty data.
1347
     * Test update_entry sending empty data.
1348
     */
1348
     */
1349
    public function test_update_entry_empty_data() {
1349
    public function test_update_entry_empty_data(): void {
Línea 1350... Línea 1350...
1350
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
1350
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
1351
 
1351
 
1352
        $this->setUser($this->student1);
1352
        $this->setUser($this->student1);
Línea 1359... Línea 1359...
1359
    }
1359
    }
Línea 1360... Línea 1360...
1360
 
1360
 
1361
    /**
1361
    /**
1362
     * Test update_entry in read only period.
1362
     * Test update_entry in read only period.
1363
     */
1363
     */
1364
    public function test_update_entry_read_only_period() {
1364
    public function test_update_entry_read_only_period(): void {
1365
        global $DB;
1365
        global $DB;
1366
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
1366
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
1367
        // Set a time period.
1367
        // Set a time period.
1368
        $this->database->timeviewfrom = time() - HOURSECS;
1368
        $this->database->timeviewfrom = time() - HOURSECS;
Línea 1376... Línea 1376...
1376
    }
1376
    }
Línea 1377... Línea 1377...
1377
 
1377
 
1378
    /**
1378
    /**
1379
     * Test update_entry other_user.
1379
     * Test update_entry other_user.
1380
     */
1380
     */
1381
    public function test_update_entry_other_user() {
1381
    public function test_update_entry_other_user(): void {
1382
        // Try to update other user entry.
1382
        // Try to update other user entry.
1383
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
1383
        list($entry11, $entry12, $entry13, $entry14, $entry21) = self::populate_database_with_entries();
1384
        $this->setUser($this->student2);
1384
        $this->setUser($this->student2);
1385
        $this->expectExceptionMessage(get_string('noaccess', 'data'));
1385
        $this->expectExceptionMessage(get_string('noaccess', 'data'));
Línea 1388... Línea 1388...
1388
    }
1388
    }
Línea 1389... Línea 1389...
1389
 
1389
 
1390
    /**
1390
    /**
1391
     * Test get_entry_rating_information.
1391
     * Test get_entry_rating_information.
1392
     */
1392
     */
1393
    public function test_get_entry_rating_information() {
1393
    public function test_get_entry_rating_information(): void {
1394
        global $DB, $CFG;
1394
        global $DB, $CFG;
Línea 1395... Línea 1395...
1395
        require_once($CFG->dirroot . '/rating/lib.php');
1395
        require_once($CFG->dirroot . '/rating/lib.php');
1396
 
1396