Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 31... Línea 31...
31
 */
31
 */
32
class userlib_test extends \advanced_testcase {
32
class userlib_test extends \advanced_testcase {
33
    /**
33
    /**
34
     * Test user_get_user_details_courses
34
     * Test user_get_user_details_courses
35
     */
35
     */
36
    public function test_user_get_user_details_courses() {
36
    public function test_user_get_user_details_courses(): void {
37
        global $DB;
37
        global $DB;
Línea 38... Línea 38...
38
 
38
 
Línea 39... Línea 39...
39
        $this->resetAfterTest();
39
        $this->resetAfterTest();
Línea 73... Línea 73...
73
    }
73
    }
Línea 74... Línea 74...
74
 
74
 
75
    /**
75
    /**
76
     * Verify return when course groupmode set to 'no groups'.
76
     * Verify return when course groupmode set to 'no groups'.
77
     */
77
     */
78
    public function test_user_get_user_details_courses_groupmode_nogroups() {
78
    public function test_user_get_user_details_courses_groupmode_nogroups(): void {
Línea 79... Línea 79...
79
        $this->resetAfterTest();
79
        $this->resetAfterTest();
80
 
80
 
81
        // Enrol 2 users into a course with groupmode set to 'no groups'.
81
        // Enrol 2 users into a course with groupmode set to 'no groups'.
Línea 93... Línea 93...
93
    }
93
    }
Línea 94... Línea 94...
94
 
94
 
95
    /**
95
    /**
96
     * Verify return when course groupmode set to 'separate groups'.
96
     * Verify return when course groupmode set to 'separate groups'.
97
     */
97
     */
98
    public function test_user_get_user_details_courses_groupmode_separate() {
98
    public function test_user_get_user_details_courses_groupmode_separate(): void {
Línea 99... Línea 99...
99
        $this->resetAfterTest();
99
        $this->resetAfterTest();
100
 
100
 
101
        // Enrol 2 users into a course with groupmode set to 'separate groups'.
101
        // Enrol 2 users into a course with groupmode set to 'separate groups'.
Línea 111... Línea 111...
111
    }
111
    }
Línea 112... Línea 112...
112
 
112
 
113
    /**
113
    /**
114
     * Verify return when course groupmode set to 'visible groups'.
114
     * Verify return when course groupmode set to 'visible groups'.
115
     */
115
     */
116
    public function test_user_get_user_details_courses_groupmode_visible() {
116
    public function test_user_get_user_details_courses_groupmode_visible(): void {
Línea 117... Línea 117...
117
        $this->resetAfterTest();
117
        $this->resetAfterTest();
118
 
118
 
119
        // Enrol 2 users into a course with groupmode set to 'visible groups'.
119
        // Enrol 2 users into a course with groupmode set to 'visible groups'.
Línea 133... Línea 133...
133
    /**
133
    /**
134
     * Tests that the user fields returned by the method can be limited.
134
     * Tests that the user fields returned by the method can be limited.
135
     *
135
     *
136
     * @covers ::user_get_user_details_courses
136
     * @covers ::user_get_user_details_courses
137
     */
137
     */
138
    public function test_user_get_user_details_courses_limit_return() {
138
    public function test_user_get_user_details_courses_limit_return(): void {
139
        $this->resetAfterTest();
139
        $this->resetAfterTest();
Línea 140... Línea 140...
140
 
140
 
141
        // Setup some data.
141
        // Setup some data.
142
        $user1 = $this->getDataGenerator()->create_user();
142
        $user1 = $this->getDataGenerator()->create_user();
Línea 174... Línea 174...
174
    }
174
    }
Línea 175... Línea 175...
175
 
175
 
176
    /**
176
    /**
177
     * Test user_update_user.
177
     * Test user_update_user.
178
     */
178
     */
179
    public function test_user_update_user() {
179
    public function test_user_update_user(): void {
Línea 180... Línea 180...
180
        global $DB;
180
        global $DB;
Línea 181... Línea 181...
181
 
181
 
Línea 248... Línea 248...
248
    }
248
    }
Línea 249... Línea 249...
249
 
249
 
250
    /**
250
    /**
251
     * Test create_users.
251
     * Test create_users.
252
     */
252
     */
253
    public function test_create_users() {
253
    public function test_create_users(): void {
Línea 254... Línea 254...
254
        global $DB;
254
        global $DB;
Línea 255... Línea 255...
255
 
255
 
Línea 363... Línea 363...
363
     *
363
     *
364
     * @dataProvider data_create_user_invalid_username
364
     * @dataProvider data_create_user_invalid_username
365
     * @param string $username Invalid username
365
     * @param string $username Invalid username
366
     * @param string $expectmessage Expected exception message
366
     * @param string $expectmessage Expected exception message
367
     */
367
     */
368
    public function test_create_user_invalid_username($username, $expectmessage) {
368
    public function test_create_user_invalid_username($username, $expectmessage): void {
369
        global $CFG;
369
        global $CFG;
Línea 370... Línea 370...
370
 
370
 
371
        $this->resetAfterTest();
371
        $this->resetAfterTest();
Línea 408... Línea 408...
408
    }
408
    }
Línea 409... Línea 409...
409
 
409
 
410
    /**
410
    /**
411
     * Test function user_count_login_failures().
411
     * Test function user_count_login_failures().
412
     */
412
     */
413
    public function test_user_count_login_failures() {
413
    public function test_user_count_login_failures(): void {
414
        $this->resetAfterTest();
414
        $this->resetAfterTest();
415
        $user = $this->getDataGenerator()->create_user();
415
        $user = $this->getDataGenerator()->create_user();
416
        $this->assertEquals(0, get_user_preferences('login_failed_count_since_success', 0, $user));
416
        $this->assertEquals(0, get_user_preferences('login_failed_count_since_success', 0, $user));
417
        for ($i = 0; $i < 10; $i++) {
417
        for ($i = 0; $i < 10; $i++) {
Línea 432... Línea 432...
432
    }
432
    }
Línea 433... Línea 433...
433
 
433
 
434
    /**
434
    /**
435
     * Test function user_add_password_history().
435
     * Test function user_add_password_history().
436
     */
436
     */
437
    public function test_user_add_password_history() {
437
    public function test_user_add_password_history(): void {
Línea 438... Línea 438...
438
        global $DB;
438
        global $DB;
Línea 439... Línea 439...
439
 
439
 
Línea 506... Línea 506...
506
    }
506
    }
Línea 507... Línea 507...
507
 
507
 
508
    /**
508
    /**
509
     * Test function user_add_password_history().
509
     * Test function user_add_password_history().
510
     */
510
     */
511
    public function test_user_is_previously_used_password() {
511
    public function test_user_is_previously_used_password(): void {
Línea 512... Línea 512...
512
        global $DB;
512
        global $DB;
Línea 513... Línea 513...
513
 
513
 
Línea 574... Línea 574...
574
    }
574
    }
Línea 575... Línea 575...
575
 
575
 
576
    /**
576
    /**
577
     * Test that password history is deleted together with user.
577
     * Test that password history is deleted together with user.
578
     */
578
     */
579
    public function test_delete_of_hashes_on_user_delete() {
579
    public function test_delete_of_hashes_on_user_delete(): void {
Línea 580... Línea 580...
580
        global $DB;
580
        global $DB;
Línea 581... Línea 581...
581
 
581
 
Línea 602... Línea 602...
602
    }
602
    }
Línea 603... Línea 603...
603
 
603
 
604
    /**
604
    /**
605
     * Test user_list_view function
605
     * Test user_list_view function
606
     */
606
     */
Línea 607... Línea 607...
607
    public function test_user_list_view() {
607
    public function test_user_list_view(): void {
Línea 608... Línea 608...
608
 
608
 
609
        $this->resetAfterTest();
609
        $this->resetAfterTest();
Línea 631... Línea 631...
631
    }
631
    }
Línea 632... Línea 632...
632
 
632
 
633
    /**
633
    /**
634
     * Test setting the user menu avatar size.
634
     * Test setting the user menu avatar size.
635
     */
635
     */
636
    public function test_user_menu_custom_avatar_size() {
636
    public function test_user_menu_custom_avatar_size(): void {
637
        global $PAGE;
637
        global $PAGE;
Línea 638... Línea 638...
638
        $this->resetAfterTest(true);
638
        $this->resetAfterTest(true);
Línea 651... Línea 651...
651
    }
651
    }
Línea 652... Línea 652...
652
 
652
 
653
    /**
653
    /**
654
     * Test user_can_view_profile
654
     * Test user_can_view_profile
655
     */
655
     */
656
    public function test_user_can_view_profile() {
656
    public function test_user_can_view_profile(): void {
Línea 657... Línea 657...
657
        global $DB, $CFG;
657
        global $DB, $CFG;
Línea 658... Línea 658...
658
 
658
 
Línea 826... Línea 826...
826
    }
826
    }
Línea 827... Línea 827...
827
 
827
 
828
    /**
828
    /**
829
     * Test user_get_user_details
829
     * Test user_get_user_details
830
     */
830
     */
831
    public function test_user_get_user_details() {
831
    public function test_user_get_user_details(): void {
Línea 832... Línea 832...
832
        global $DB;
832
        global $DB;
Línea 833... Línea 833...
833
 
833
 
Línea 877... Línea 877...
877
     * Regression test for MDL-57840.
877
     * Regression test for MDL-57840.
878
     *
878
     *
879
     * Ensure the fields "auth, confirmed, idnumber, lang, theme, timezone and mailformat" are present when
879
     * Ensure the fields "auth, confirmed, idnumber, lang, theme, timezone and mailformat" are present when
880
     * calling user_get_user_details() function.
880
     * calling user_get_user_details() function.
881
     */
881
     */
882
    public function test_user_get_user_details_missing_fields() {
882
    public function test_user_get_user_details_missing_fields(): void {
883
        global $CFG;
883
        global $CFG;
Línea 884... Línea 884...
884
 
884
 
885
        $this->resetAfterTest(true);
885
        $this->resetAfterTest(true);
886
        $this->setAdminUser(); // We need capabilities to view the data.
886
        $this->setAdminUser(); // We need capabilities to view the data.
Línea 909... Línea 909...
909
 
909
 
910
    /**
910
    /**
911
     * Test user_get_user_details_permissions.
911
     * Test user_get_user_details_permissions.
912
     * @covers ::user_get_user_details
912
     * @covers ::user_get_user_details
913
     */
913
     */
914
    public function test_user_get_user_details_permissions() {
914
    public function test_user_get_user_details_permissions(): void {
Línea 915... Línea 915...
915
        global $CFG;
915
        global $CFG;
Línea 916... Línea 916...
916
 
916
 
Línea 941... Línea 941...
941
 
941
 
Línea 942... Línea 942...
942
        $this->setUser($student2);
942
        $this->setUser($student2);
943
 
943
 
944
        // Get student details with required fields.
944
        // Get student details with required fields.
945
        $result = user_get_user_details($student1, $course, array('id', 'fullname', 'timezone', 'city', 'address', 'idnumber'));
945
        $result = user_get_user_details($student1, $course, array('id', 'fullname', 'timezone', 'city', 'address', 'idnumber'));
946
        $this->assertCount(4, $result); // Ensure address (never returned), idnumber (identity field) are not returned here.
946
        $this->assertCount(5, $result); // Ensure idnumber (identity field) is not returned here.
947
        $this->assertEquals($student1->id, $result['id']);
947
        $this->assertEquals($student1->id, $result['id']);
948
        $this->assertEquals($student1fullname, $result['fullname']);
948
        $this->assertEquals($student1fullname, $result['fullname']);
-
 
949
        $this->assertEquals($student1->timezone, $result['timezone']);
Línea 949... Línea 950...
949
        $this->assertEquals($student1->timezone, $result['timezone']);
950
        $this->assertEquals($student1->city, $result['city']);
950
        $this->assertEquals($student1->city, $result['city']);
951
        $this->assertEquals($student1->address, $result['address']);
951
 
952
 
952
        // Set new identity fields and hidden fields and try to retrieve them without permission.
953
        // Set new identity fields and hidden fields and try to retrieve them without permission.
953
        $CFG->showuseridentity = $CFG->showuseridentity . ',idnumber';
954
        $CFG->showuseridentity = $CFG->showuseridentity . ',idnumber';
954
        $CFG->hiddenuserfields = 'city';
955
        $CFG->hiddenuserfields = 'city';
955
        $result = user_get_user_details($student1, $course, array('id', 'fullname', 'timezone', 'city', 'address', 'idnumber'));
956
        $result = user_get_user_details($student1, $course, array('id', 'fullname', 'timezone', 'city', 'address', 'idnumber'));
956
        $this->assertCount(3, $result); // Ensure address, city and idnumber are not returned here.
957
        $this->assertCount(4, $result); // Ensure city and idnumber are not returned here.
-
 
958
        $this->assertEquals($student1->id, $result['id']);
Línea 957... Línea 959...
957
        $this->assertEquals($student1->id, $result['id']);
959
        $this->assertEquals($student1fullname, $result['fullname']);
958
        $this->assertEquals($student1fullname, $result['fullname']);
960
        $this->assertEquals($student1->timezone, $result['timezone']);
959
        $this->assertEquals($student1->timezone, $result['timezone']);
961
        $this->assertEquals($student1->address, $result['address']);
960
 
962
 
961
        // Now, teacher should have permission to see the idnumber and city fields.
963
        // Now, teacher should have permission to see the idnumber and city fields.
962
        $this->setUser($teacher);
964
        $this->setUser($teacher);
963
        $result = user_get_user_details($student1, $course, array('id', 'fullname', 'timezone', 'city', 'address', 'idnumber'));
965
        $result = user_get_user_details($student1, $course, array('id', 'fullname', 'timezone', 'city', 'address', 'idnumber'));
964
        $this->assertCount(5, $result); // Ensure address is not returned here.
966
        $this->assertCount(6, $result);
965
        $this->assertEquals($student1->id, $result['id']);
967
        $this->assertEquals($student1->id, $result['id']);
-
 
968
        $this->assertEquals($student1fullname, $result['fullname']);
Línea 966... Línea 969...
966
        $this->assertEquals($student1fullname, $result['fullname']);
969
        $this->assertEquals($student1->timezone, $result['timezone']);
967
        $this->assertEquals($student1->timezone, $result['timezone']);
970
        $this->assertEquals($student1->idnumber, $result['idnumber']);
968
        $this->assertEquals($student1->idnumber, $result['idnumber']);
971
        $this->assertEquals($student1->city, $result['city']);
969
        $this->assertEquals($student1->city, $result['city']);
972
        $this->assertEquals($student1->address, $result['address']);
Línea 982... Línea 985...
982
 
985
 
983
    /**
986
    /**
984
     * Test user_get_user_details_groups.
987
     * Test user_get_user_details_groups.
985
     * @covers ::user_get_user_details
988
     * @covers ::user_get_user_details
986
     */
989
     */
987
    public function test_user_get_user_details_groups() {
990
    public function test_user_get_user_details_groups(): void {
Línea 988... Línea 991...
988
        $this->resetAfterTest();
991
        $this->resetAfterTest();
989
 
992
 
990
        // Create user and modify user profile.
993
        // Create user and modify user profile.