Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 134... Línea 134...
134
 
134
 
135
 
135
 
136
    /**
136
    /**
137
     * Test test_mod_lesson_get_lessons_by_courses
137
     * Test test_mod_lesson_get_lessons_by_courses
138
     */
138
     */
Línea 139... Línea 139...
139
    public function test_mod_lesson_get_lessons_by_courses() {
139
    public function test_mod_lesson_get_lessons_by_courses(): void {
140
        global $DB;
140
        global $DB;
Línea 269... Línea 269...
269
    }
269
    }
Línea 270... Línea 270...
270
 
270
 
271
    /**
271
    /**
272
     * Test the validate_attempt function.
272
     * Test the validate_attempt function.
273
     */
273
     */
274
    public function test_validate_attempt() {
274
    public function test_validate_attempt(): void {
Línea 275... Línea 275...
275
        global $DB;
275
        global $DB;
276
 
276
 
277
        $this->setUser($this->student);
277
        $this->setUser($this->student);
Línea 365... Línea 365...
365
    }
365
    }
Línea 366... Línea 366...
366
 
366
 
367
    /**
367
    /**
368
     * Test the get_lesson_access_information function.
368
     * Test the get_lesson_access_information function.
369
     */
369
     */
370
    public function test_get_lesson_access_information() {
370
    public function test_get_lesson_access_information(): void {
Línea 371... Línea 371...
371
        global $DB;
371
        global $DB;
372
 
372
 
373
        $this->setUser($this->student);
373
        $this->setUser($this->student);
Línea 407... Línea 407...
407
    }
407
    }
Línea 408... Línea 408...
408
 
408
 
409
    /**
409
    /**
410
     * Test test_view_lesson invalid id.
410
     * Test test_view_lesson invalid id.
411
     */
411
     */
412
    public function test_view_lesson_invalid_id() {
412
    public function test_view_lesson_invalid_id(): void {
413
        $this->expectException('moodle_exception');
413
        $this->expectException('moodle_exception');
414
        mod_lesson_external::view_lesson(0);
414
        mod_lesson_external::view_lesson(0);
Línea 415... Línea 415...
415
    }
415
    }
416
 
416
 
417
    /**
417
    /**
418
     * Test test_view_lesson user not enrolled.
418
     * Test test_view_lesson user not enrolled.
419
     */
419
     */
420
    public function test_view_lesson_user_not_enrolled() {
420
    public function test_view_lesson_user_not_enrolled(): void {
421
        // Test not-enrolled user.
421
        // Test not-enrolled user.
422
        $usernotenrolled = self::getDataGenerator()->create_user();
422
        $usernotenrolled = self::getDataGenerator()->create_user();
423
        $this->setUser($usernotenrolled);
423
        $this->setUser($usernotenrolled);
424
        $this->expectException('moodle_exception');
424
        $this->expectException('moodle_exception');
Línea 425... Línea 425...
425
        mod_lesson_external::view_lesson($this->lesson->id);
425
        mod_lesson_external::view_lesson($this->lesson->id);
426
    }
426
    }
427
 
427
 
428
    /**
428
    /**
429
     * Test test_view_lesson user student.
429
     * Test test_view_lesson user student.
430
     */
430
     */
Línea 431... Línea 431...
431
    public function test_view_lesson_user_student() {
431
    public function test_view_lesson_user_student(): void {
432
        // Test user with full capabilities.
432
        // Test user with full capabilities.
Línea 453... Línea 453...
453
    }
453
    }
Línea 454... Línea 454...
454
 
454
 
455
    /**
455
    /**
456
     * Test test_view_lesson user missing capabilities.
456
     * Test test_view_lesson user missing capabilities.
457
     */
457
     */
458
    public function test_view_lesson_user_missing_capabilities() {
458
    public function test_view_lesson_user_missing_capabilities(): void {
459
        // Test user with no capabilities.
459
        // Test user with no capabilities.
460
        // We need a explicit prohibit since this capability is only defined in authenticated user and guest roles.
460
        // We need a explicit prohibit since this capability is only defined in authenticated user and guest roles.
461
        assign_capability('mod/lesson:view', CAP_PROHIBIT, $this->studentrole->id, $this->context->id);
461
        assign_capability('mod/lesson:view', CAP_PROHIBIT, $this->studentrole->id, $this->context->id);
462
        // Empty all the caches that may be affected  by this change.
462
        // Empty all the caches that may be affected  by this change.
Línea 469... Línea 469...
469
    }
469
    }
Línea 470... Línea 470...
470
 
470
 
471
    /**
471
    /**
472
     * Test for get_questions_attempts
472
     * Test for get_questions_attempts
473
     */
473
     */
474
    public function test_get_questions_attempts() {
474
    public function test_get_questions_attempts(): void {
Línea 475... Línea 475...
475
        global $DB;
475
        global $DB;
476
 
476
 
Línea 533... Línea 533...
533
    }
533
    }
Línea 534... Línea 534...
534
 
534
 
535
    /**
535
    /**
536
     * Test get user grade.
536
     * Test get user grade.
537
     */
537
     */
538
    public function test_get_user_grade() {
538
    public function test_get_user_grade(): void {
Línea 539... Línea 539...
539
        global $DB;
539
        global $DB;
540
 
540
 
541
        // Add grades for the user.
541
        // Add grades for the user.
Línea 597... Línea 597...
597
    }
597
    }
Línea 598... Línea 598...
598
 
598
 
599
    /**
599
    /**
600
     * Test get_user_attempt_grade
600
     * Test get_user_attempt_grade
601
     */
601
     */
602
    public function test_get_user_attempt_grade() {
602
    public function test_get_user_attempt_grade(): void {
Línea 603... Línea 603...
603
        global $DB;
603
        global $DB;
604
 
604
 
605
        // Create a fake attempt for the first possible answer.
605
        // Create a fake attempt for the first possible answer.
Línea 648... Línea 648...
648
    }
648
    }
Línea 649... Línea 649...
649
 
649
 
650
    /**
650
    /**
651
     * Test get_content_pages_viewed
651
     * Test get_content_pages_viewed
652
     */
652
     */
653
    public function test_get_content_pages_viewed() {
653
    public function test_get_content_pages_viewed(): void {
Línea 654... Línea 654...
654
        global $DB;
654
        global $DB;
655
 
655
 
656
        // Create another content pages.
656
        // Create another content pages.
Línea 698... Línea 698...
698
    }
698
    }
Línea 699... Línea 699...
699
 
699
 
700
    /**
700
    /**
701
     * Test get_user_timers
701
     * Test get_user_timers
702
     */
702
     */
703
    public function test_get_user_timers() {
703
    public function test_get_user_timers(): void {
Línea 704... Línea 704...
704
        global $DB;
704
        global $DB;
705
 
705
 
706
        // Create a couple of timers for the current user.
706
        // Create a couple of timers for the current user.
Línea 737... Línea 737...
737
    }
737
    }
Línea 738... Línea 738...
738
 
738
 
739
    /**
739
    /**
740
     * Test for get_pages
740
     * Test for get_pages
741
     */
741
     */
742
    public function test_get_pages() {
742
    public function test_get_pages(): void {
Línea 743... Línea 743...
743
        global $DB;
743
        global $DB;
744
 
744
 
745
        $this->setAdminUser();
745
        $this->setAdminUser();
Línea 806... Línea 806...
806
    }
806
    }
Línea 807... Línea 807...
807
 
807
 
808
    /**
808
    /**
809
     * Test launch_attempt. Time restrictions already tested in test_validate_attempt.
809
     * Test launch_attempt. Time restrictions already tested in test_validate_attempt.
810
     */
810
     */
811
    public function test_launch_attempt() {
811
    public function test_launch_attempt(): void {
Línea 812... Línea 812...
812
        global $DB, $SESSION;
812
        global $DB, $SESSION;
813
 
813
 
814
        // Test time limit restriction.
814
        // Test time limit restriction.
Línea 839... Línea 839...
839
    }
839
    }
Línea 840... Línea 840...
840
 
840
 
841
    /**
841
    /**
842
     * Test launch_attempt not finished forcing review mode.
842
     * Test launch_attempt not finished forcing review mode.
843
     */
843
     */
844
    public function test_launch_attempt_not_finished_in_review_mode() {
844
    public function test_launch_attempt_not_finished_in_review_mode(): void {
Línea 845... Línea 845...
845
        global $DB, $SESSION;
845
        global $DB, $SESSION;
846
 
846
 
847
        // Create a timer for the current user.
847
        // Create a timer for the current user.
Línea 869... Línea 869...
869
    }
869
    }
Línea 870... Línea 870...
870
 
870
 
871
    /**
871
    /**
872
     * Test launch_attempt just finished forcing review mode.
872
     * Test launch_attempt just finished forcing review mode.
873
     */
873
     */
874
    public function test_launch_attempt_just_finished_in_review_mode() {
874
    public function test_launch_attempt_just_finished_in_review_mode(): void {
Línea 875... Línea 875...
875
        global $DB, $SESSION, $USER;
875
        global $DB, $SESSION, $USER;
876
 
876
 
877
        // Create a timer for the current user.
877
        // Create a timer for the current user.
Línea 917... Línea 917...
917
    }
917
    }
Línea 918... Línea 918...
918
 
918
 
919
    /**
919
    /**
920
     * Test launch_attempt not just finished forcing review mode.
920
     * Test launch_attempt not just finished forcing review mode.
921
     */
921
     */
922
    public function test_launch_attempt_not_just_finished_in_review_mode() {
922
    public function test_launch_attempt_not_just_finished_in_review_mode(): void {
Línea 923... Línea 923...
923
        global $DB, $CFG, $SESSION;
923
        global $DB, $CFG, $SESSION;
924
 
924
 
925
        // Create a timer for the current user.
925
        // Create a timer for the current user.
Línea 948... Línea 948...
948
    }
948
    }
Línea 949... Línea 949...
949
 
949
 
950
    /*
950
    /*
951
     * Test get_page_data
951
     * Test get_page_data
952
     */
952
     */
953
    public function test_get_page_data() {
953
    public function test_get_page_data(): void {
Línea 954... Línea 954...
954
        global $DB;
954
        global $DB;
955
 
955
 
956
        // Test a content page first (page1).
956
        // Test a content page first (page1).
Línea 989... Línea 989...
989
    }
989
    }
Línea 990... Línea 990...
990
 
990
 
991
    /**
991
    /**
992
     * Test get_page_data as student
992
     * Test get_page_data as student
993
     */
993
     */
994
    public function test_get_page_data_student() {
994
    public function test_get_page_data_student(): void {
995
        // Now check using a normal student account.
995
        // Now check using a normal student account.
996
        $this->setUser($this->student);
996
        $this->setUser($this->student);
997
        // First we need to launch the lesson so the timer is on.
997
        // First we need to launch the lesson so the timer is on.
998
        mod_lesson_external::launch_attempt($this->lesson->id);
998
        mod_lesson_external::launch_attempt($this->lesson->id);
Línea 1010... Línea 1010...
1010
    }
1010
    }
Línea 1011... Línea 1011...
1011
 
1011
 
1012
    /**
1012
    /**
1013
     * Test get_page_data without launching attempt.
1013
     * Test get_page_data without launching attempt.
1014
     */
1014
     */
1015
    public function test_get_page_data_without_launch() {
1015
    public function test_get_page_data_without_launch(): void {
1016
        // Now check using a normal student account.
1016
        // Now check using a normal student account.
Línea 1017... Línea 1017...
1017
        $this->setUser($this->student);
1017
        $this->setUser($this->student);
1018
 
1018
 
Línea 1073... Línea 1073...
1073
    }
1073
    }
Línea 1074... Línea 1074...
1074
 
1074
 
1075
    /**
1075
    /**
1076
     * Test process_page
1076
     * Test process_page
1077
     */
1077
     */
1078
    public function test_process_page() {
1078
    public function test_process_page(): void {
Línea 1079... Línea 1079...
1079
        global $DB;
1079
        global $DB;
1080
 
1080
 
Línea 1095... Línea 1095...
1095
    }
1095
    }
Línea 1096... Línea 1096...
1096
 
1096
 
1097
    /**
1097
    /**
1098
     * Test finish attempt not doing anything.
1098
     * Test finish attempt not doing anything.
1099
     */
1099
     */
Línea 1100... Línea 1100...
1100
    public function test_finish_attempt_not_doing_anything() {
1100
    public function test_finish_attempt_not_doing_anything(): void {
1101
 
1101
 
1102
        $this->setUser($this->student);
1102
        $this->setUser($this->student);
Línea 1126... Línea 1126...
1126
    }
1126
    }
Línea 1127... Línea 1127...
1127
 
1127
 
1128
    /**
1128
    /**
1129
     * Test finish attempt with correct answer.
1129
     * Test finish attempt with correct answer.
1130
     */
1130
     */
1131
    public function test_finish_attempt_with_correct_answer() {
1131
    public function test_finish_attempt_with_correct_answer(): void {
1132
        // Create a finished attempt.
1132
        // Create a finished attempt.
Línea 1133... Línea 1133...
1133
        $result = $this->create_attempt($this->student, true, true);
1133
        $result = $this->create_attempt($this->student, true, true);
1134
 
1134
 
Línea 1153... Línea 1153...
1153
    }
1153
    }
Línea 1154... Línea 1154...
1154
 
1154
 
1155
    /**
1155
    /**
1156
     * Test get_attempts_overview
1156
     * Test get_attempts_overview
1157
     */
1157
     */
1158
    public function test_get_attempts_overview() {
1158
    public function test_get_attempts_overview(): void {
Línea 1159... Línea 1159...
1159
        global $DB;
1159
        global $DB;
1160
 
1160
 
1161
        // Create a finished attempt with incorrect answer.
1161
        // Create a finished attempt with incorrect answer.
Línea 1232... Línea 1232...
1232
    }
1232
    }
Línea 1233... Línea 1233...
1233
 
1233
 
1234
    /**
1234
    /**
1235
     * Test get_attempts_overview when there aren't attempts.
1235
     * Test get_attempts_overview when there aren't attempts.
1236
     */
1236
     */
1237
    public function test_get_attempts_overview_no_attempts() {
1237
    public function test_get_attempts_overview_no_attempts(): void {
1238
        $this->setAdminUser();
1238
        $this->setAdminUser();
1239
        $result = mod_lesson_external::get_attempts_overview($this->lesson->id);
1239
        $result = mod_lesson_external::get_attempts_overview($this->lesson->id);
1240
        $result = external_api::clean_returnvalue(mod_lesson_external::get_attempts_overview_returns(), $result);
1240
        $result = external_api::clean_returnvalue(mod_lesson_external::get_attempts_overview_returns(), $result);
1241
        $this->assertCount(0, $result['warnings']);
1241
        $this->assertCount(0, $result['warnings']);
1242
        $this->assertArrayNotHasKey('data', $result);
1242
        $this->assertArrayNotHasKey('data', $result);
Línea 1243... Línea 1243...
1243
    }
1243
    }
1244
 
1244
 
1245
    /**
1245
    /**
1246
     * Test get_user_attempt
1246
     * Test get_user_attempt
1247
     */
1247
     */
Línea 1248... Línea 1248...
1248
    public function test_get_user_attempt() {
1248
    public function test_get_user_attempt(): void {
1249
        global $DB;
1249
        global $DB;
1250
 
1250
 
Línea 1300... Línea 1300...
1300
    }
1300
    }
Línea 1301... Línea 1301...
1301
 
1301
 
1302
    /**
1302
    /**
1303
     * Test get_pages_possible_jumps
1303
     * Test get_pages_possible_jumps
1304
     */
1304
     */
1305
    public function test_get_pages_possible_jumps() {
1305
    public function test_get_pages_possible_jumps(): void {
1306
        $this->setAdminUser();
1306
        $this->setAdminUser();
1307
        $result = mod_lesson_external::get_pages_possible_jumps($this->lesson->id);
1307
        $result = mod_lesson_external::get_pages_possible_jumps($this->lesson->id);
Línea 1308... Línea 1308...
1308
        $result = external_api::clean_returnvalue(mod_lesson_external::get_pages_possible_jumps_returns(), $result);
1308
        $result = external_api::clean_returnvalue(mod_lesson_external::get_pages_possible_jumps_returns(), $result);
Línea 1323... Línea 1323...
1323
    }
1323
    }
Línea 1324... Línea 1324...
1324
 
1324
 
1325
    /**
1325
    /**
1326
     * Test get_pages_possible_jumps when offline attemps are disabled for a normal user
1326
     * Test get_pages_possible_jumps when offline attemps are disabled for a normal user
1327
     */
1327
     */
1328
    public function test_get_pages_possible_jumps_with_offlineattemps_disabled() {
1328
    public function test_get_pages_possible_jumps_with_offlineattemps_disabled(): void {
1329
        $this->setUser($this->student->id);
1329
        $this->setUser($this->student->id);
1330
        $result = mod_lesson_external::get_pages_possible_jumps($this->lesson->id);
1330
        $result = mod_lesson_external::get_pages_possible_jumps($this->lesson->id);
1331
        $result = external_api::clean_returnvalue(mod_lesson_external::get_pages_possible_jumps_returns(), $result);
1331
        $result = external_api::clean_returnvalue(mod_lesson_external::get_pages_possible_jumps_returns(), $result);
1332
        $this->assertCount(0, $result['jumps']);
1332
        $this->assertCount(0, $result['jumps']);
Línea 1333... Línea 1333...
1333
    }
1333
    }
1334
 
1334
 
1335
    /**
1335
    /**
1336
     * Test get_pages_possible_jumps when offline attemps are enabled for a normal user
1336
     * Test get_pages_possible_jumps when offline attemps are enabled for a normal user
1337
     */
1337
     */
Línea 1338... Línea 1338...
1338
    public function test_get_pages_possible_jumps_with_offlineattemps_enabled() {
1338
    public function test_get_pages_possible_jumps_with_offlineattemps_enabled(): void {
1339
        global $DB;
1339
        global $DB;
1340
 
1340
 
Línea 1346... Línea 1346...
1346
    }
1346
    }
Línea 1347... Línea 1347...
1347
 
1347
 
1348
    /*
1348
    /*
1349
     * Test get_lesson user student.
1349
     * Test get_lesson user student.
1350
     */
1350
     */
1351
    public function test_get_lesson_user_student() {
1351
    public function test_get_lesson_user_student(): void {
1352
        // Test user with full capabilities.
1352
        // Test user with full capabilities.
Línea 1353... Línea 1353...
1353
        $this->setUser($this->student);
1353
        $this->setUser($this->student);
1354
 
1354
 
Línea 1360... Línea 1360...
1360
    }
1360
    }
Línea 1361... Línea 1361...
1361
 
1361
 
1362
    /**
1362
    /**
1363
     * Test get_lesson user student with missing password.
1363
     * Test get_lesson user student with missing password.
1364
     */
1364
     */
1365
    public function test_get_lesson_user_student_with_missing_password() {
1365
    public function test_get_lesson_user_student_with_missing_password(): void {
Línea 1366... Línea 1366...
1366
        global $DB;
1366
        global $DB;
1367
 
1367
 
1368
        // Test user with full capabilities.
1368
        // Test user with full capabilities.
Línea 1378... Línea 1378...
1378
    }
1378
    }
Línea 1379... Línea 1379...
1379
 
1379
 
1380
    /**
1380
    /**
1381
     * Test get_lesson user student with correct password.
1381
     * Test get_lesson user student with correct password.
1382
     */
1382
     */
1383
    public function test_get_lesson_user_student_with_correct_password() {
1383
    public function test_get_lesson_user_student_with_correct_password(): void {
1384
        global $DB;
1384
        global $DB;
1385
        // Test user with full capabilities.
1385
        // Test user with full capabilities.
1386
        $this->setUser($this->student);
1386
        $this->setUser($this->student);
1387
        $password = 'abc';
1387
        $password = 'abc';
Línea 1396... Línea 1396...
1396
    }
1396
    }
Línea 1397... Línea 1397...
1397
 
1397
 
1398
    /**
1398
    /**
1399
     * Test get_lesson teacher.
1399
     * Test get_lesson teacher.
1400
     */
1400
     */
1401
    public function test_get_lesson_teacher() {
1401
    public function test_get_lesson_teacher(): void {
1402
        global $DB;
1402
        global $DB;
1403
        // Test user with full capabilities.
1403
        // Test user with full capabilities.
1404
        $this->setUser($this->teacher);
1404
        $this->setUser($this->teacher);
1405
        $password = 'abc';
1405
        $password = 'abc';