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
    protected function setUp(): void {
32
    protected function setUp(): void {
33
        $this->resetAfterTest(true);
33
        $this->resetAfterTest(true);
34
    }
34
    }
Línea 35... Línea 35...
35
 
35
 
36
    public function test_get_user() {
36
    public function test_get_user(): void {
Línea 37... Línea 37...
37
        global $CFG;
37
        global $CFG;
38
 
38
 
Línea 81... Línea 81...
81
    }
81
    }
Línea 82... Línea 82...
82
 
82
 
83
    /**
83
    /**
84
     * Test get_user_by_username method.
84
     * Test get_user_by_username method.
85
     */
85
     */
86
    public function test_get_user_by_username() {
86
    public function test_get_user_by_username(): void {
87
        $record = array();
87
        $record = array();
88
        $record['username'] = 'johndoe';
88
        $record['username'] = 'johndoe';
89
        $record['email'] = 'johndoe@example.com';
89
        $record['email'] = 'johndoe@example.com';
Línea 110... Línea 110...
110
 
110
 
111
        // Assert that a user not in the db return false.
111
        // Assert that a user not in the db return false.
112
        $this->assertFalse(\core_user::get_user_by_username('janedoe'));
112
        $this->assertFalse(\core_user::get_user_by_username('janedoe'));
Línea 113... Línea 113...
113
    }
113
    }
114
 
114
 
Línea 115... Línea 115...
115
    public function test_search() {
115
    public function test_search(): void {
Línea 116... Línea 116...
116
        global $DB;
116
        global $DB;
Línea 315... Línea 315...
315
    }
315
    }
Línea 316... Línea 316...
316
 
316
 
317
    /**
317
    /**
318
     * Tests the search() function with limits on the number to return.
318
     * Tests the search() function with limits on the number to return.
319
     */
319
     */
320
    public function test_search_with_count() {
320
    public function test_search_with_count(): void {
321
        self::init_search_tests();
321
        self::init_search_tests();
322
        $generator = $this->getDataGenerator();
322
        $generator = $this->getDataGenerator();
Línea 323... Línea 323...
323
        $course = $generator->create_course();
323
        $course = $generator->create_course();
Línea 344... Línea 344...
344
    /**
344
    /**
345
     * When course is in separate groups mode and user is a student, they can't see people who
345
     * When course is in separate groups mode and user is a student, they can't see people who
346
     * are not in the same group. This is checked by the user profile permission thing and not
346
     * are not in the same group. This is checked by the user profile permission thing and not
347
     * currently by the original query.
347
     * currently by the original query.
348
     */
348
     */
349
    public function test_search_group_permissions() {
349
    public function test_search_group_permissions(): void {
350
        global $DB;
350
        global $DB;
Línea 351... Línea 351...
351
 
351
 
Línea 352... Línea 352...
352
        self::init_search_tests();
352
        self::init_search_tests();
Línea 387... Línea 387...
387
    /**
387
    /**
388
     * When course is in separate groups mode and user is a student, they can't see people who
388
     * When course is in separate groups mode and user is a student, they can't see people who
389
     * are not in the same group. This is checked by the user profile permission thing and not
389
     * are not in the same group. This is checked by the user profile permission thing and not
390
     * currently by the original query.
390
     * currently by the original query.
391
     */
391
     */
392
    public function test_search_deleted_users() {
392
    public function test_search_deleted_users(): void {
393
        self::init_search_tests();
393
        self::init_search_tests();
Línea 394... Línea 394...
394
 
394
 
395
        // Create one user to do the searching.
395
        // Create one user to do the searching.
396
        $generator = $this->getDataGenerator();
396
        $generator = $this->getDataGenerator();
Línea 441... Línea 441...
441
    }
441
    }
Línea 442... Línea 442...
442
 
442
 
443
    /**
443
    /**
444
     * Test require_active_user
444
     * Test require_active_user
445
     */
445
     */
446
    public function test_require_active_user() {
446
    public function test_require_active_user(): void {
Línea 447... Línea 447...
447
        global $DB;
447
        global $DB;
448
 
448
 
Línea 509... Línea 509...
509
    }
509
    }
Línea 510... Línea 510...
510
 
510
 
511
    /**
511
    /**
512
     * Test get_property_definition() method.
512
     * Test get_property_definition() method.
513
     */
513
     */
514
    public function test_get_property_definition() {
514
    public function test_get_property_definition(): void {
515
        // Try to get a existing property.
515
        // Try to get a existing property.
516
        $properties = \core_user::get_property_definition('id');
516
        $properties = \core_user::get_property_definition('id');
517
        $this->assertEquals($properties['type'], PARAM_INT);
517
        $this->assertEquals($properties['type'], PARAM_INT);
518
        $properties = \core_user::get_property_definition('username');
518
        $properties = \core_user::get_property_definition('username');
Línea 534... Línea 534...
534
    }
534
    }
Línea 535... Línea 535...
535
 
535
 
536
    /**
536
    /**
537
     * Test validate() method.
537
     * Test validate() method.
538
     */
538
     */
Línea 539... Línea 539...
539
    public function test_validate() {
539
    public function test_validate(): void {
540
 
540
 
541
        // Create user with just with username and firstname.
541
        // Create user with just with username and firstname.
Línea 564... Línea 564...
564
    }
564
    }
Línea 565... Línea 565...
565
 
565
 
566
    /**
566
    /**
567
     * Test clean_data() method.
567
     * Test clean_data() method.
568
     */
568
     */
569
    public function test_clean_data() {
569
    public function test_clean_data(): void {
Línea 570... Línea 570...
570
        $this->resetAfterTest(false);
570
        $this->resetAfterTest(false);
571
 
571
 
572
        $user = new \stdClass();
572
        $user = new \stdClass();
Línea 591... Línea 591...
591
    }
591
    }
Línea 592... Línea 592...
592
 
592
 
593
    /**
593
    /**
594
     * Test clean_field() method.
594
     * Test clean_field() method.
595
     */
595
     */
Línea 596... Línea 596...
596
    public function test_clean_field() {
596
    public function test_clean_field(): void {
597
 
597
 
598
        // Create a 'malicious' user object/
598
        // Create a 'malicious' user object/
599
        $user = new \stdClass();
599
        $user = new \stdClass();
Línea 617... Línea 617...
617
    }
617
    }
Línea 618... Línea 618...
618
 
618
 
619
    /**
619
    /**
620
     * Test get_property_type() method.
620
     * Test get_property_type() method.
621
     */
621
     */
Línea 622... Línea 622...
622
    public function test_get_property_type() {
622
    public function test_get_property_type(): void {
623
 
623
 
624
        // Fetch valid properties and verify if the type is correct.
624
        // Fetch valid properties and verify if the type is correct.
625
        $type = \core_user::get_property_type('username');
625
        $type = \core_user::get_property_type('username');
Línea 640... Línea 640...
640
    }
640
    }
Línea 641... Línea 641...
641
 
641
 
642
    /**
642
    /**
643
     * Test get_property_null() method.
643
     * Test get_property_null() method.
644
     */
644
     */
645
    public function test_get_property_null() {
645
    public function test_get_property_null(): void {
646
        // Fetch valid properties and verify if it is NULL_ALLOWED or NULL_NOT_ALLOWED.
646
        // Fetch valid properties and verify if it is NULL_ALLOWED or NULL_NOT_ALLOWED.
647
        $property = \core_user::get_property_null('username');
647
        $property = \core_user::get_property_null('username');
648
        $this->assertEquals(NULL_NOT_ALLOWED, $property);
648
        $this->assertEquals(NULL_NOT_ALLOWED, $property);
649
        $property = \core_user::get_property_null('password');
649
        $property = \core_user::get_property_null('password');
Línea 664... Línea 664...
664
    }
664
    }
Línea 665... Línea 665...
665
 
665
 
666
    /**
666
    /**
667
     * Test get_property_choices() method.
667
     * Test get_property_choices() method.
668
     */
668
     */
Línea 669... Línea 669...
669
    public function test_get_property_choices() {
669
    public function test_get_property_choices(): void {
670
 
670
 
671
        // Test against country property choices.
671
        // Test against country property choices.
672
        $choices = \core_user::get_property_choices('country');
672
        $choices = \core_user::get_property_choices('country');
Línea 699... Línea 699...
699
    }
699
    }
Línea 700... Línea 700...
700
 
700
 
701
    /**
701
    /**
702
     * Test get_property_default().
702
     * Test get_property_default().
703
     */
703
     */
704
    public function test_get_property_default() {
704
    public function test_get_property_default(): void {
705
        global $CFG;
705
        global $CFG;
Línea 706... Línea 706...
706
        $this->resetAfterTest();
706
        $this->resetAfterTest();
707
 
707
 
Línea 733... Línea 733...
733
    }
733
    }
Línea 734... Línea 734...
734
 
734
 
735
    /**
735
    /**
736
     * Ensure that the noreply user is not cached.
736
     * Ensure that the noreply user is not cached.
737
     */
737
     */
738
    public function test_get_noreply_user() {
738
    public function test_get_noreply_user(): void {
Línea 739... Línea 739...
739
        global $CFG;
739
        global $CFG;
740
 
740
 
741
        // Create a new fake language 'xx' with the 'noreplyname'.
741
        // Create a new fake language 'xx' with the 'noreplyname'.
Línea 756... Línea 756...
756
    }
756
    }
Línea 757... Línea 757...
757
 
757
 
758
    /**
758
    /**
759
     * Test is_real_user method.
759
     * Test is_real_user method.
760
     */
760
     */
761
    public function test_is_real_user() {
761
    public function test_is_real_user(): void {
Línea 762... Línea 762...
762
        global $CFG, $USER;
762
        global $CFG, $USER;
763
 
763
 
764
        // Real users are real users.
764
        // Real users are real users.
Línea 796... Línea 796...
796
    }
796
    }
Línea 797... Línea 797...
797
 
797
 
798
    /**
798
    /**
799
     * Tests for the {@see \core_user::awaiting_action()} method.
799
     * Tests for the {@see \core_user::awaiting_action()} method.
800
     */
800
     */
801
    public function test_awaiting_action() {
801
    public function test_awaiting_action(): void {
Línea 802... Línea 802...
802
        global $CFG, $DB, $USER;
802
        global $CFG, $DB, $USER;
803
 
803
 
804
        $guest = \core_user::get_user($CFG->siteguest);
804
        $guest = \core_user::get_user($CFG->siteguest);
Línea 848... Línea 848...
848
    /**
848
    /**
849
     * Test for function to get user details.
849
     * Test for function to get user details.
850
     *
850
     *
851
     * @covers \core_user::get_fullname
851
     * @covers \core_user::get_fullname
852
     */
852
     */
853
    public function test_display_name() {
853
    public function test_display_name(): void {
854
        $this->resetAfterTest();
854
        $this->resetAfterTest();
Línea 855... Línea 855...
855
 
855
 
856
        $user = $this->getDataGenerator()->create_user(['firstname' => 'John', 'lastname' => 'Doe']);
856
        $user = $this->getDataGenerator()->create_user(['firstname' => 'John', 'lastname' => 'Doe']);
Línea 878... Línea 878...
878
    /**
878
    /**
879
     * Test for function to get user details.
879
     * Test for function to get user details.
880
     *
880
     *
881
     * @covers \core_user::get_profile_url
881
     * @covers \core_user::get_profile_url
882
     */
882
     */
883
    public function test_display_profile_url() {
883
    public function test_display_profile_url(): void {
884
        $this->resetAfterTest();
884
        $this->resetAfterTest();
Línea 885... Línea 885...
885
 
885
 
Línea 886... Línea 886...
886
        $user = $this->getDataGenerator()->create_user(['firstname' => 'John', 'lastname' => 'Doe']);
886
        $user = $this->getDataGenerator()->create_user(['firstname' => 'John', 'lastname' => 'Doe']);
Línea 890... Línea 890...
890
            \core_user::get_profile_url($user)->out());
890
            \core_user::get_profile_url($user)->out());
Línea 891... Línea 891...
891
 
891
 
892
        // Display profile url at course context.
892
        // Display profile url at course context.
893
        $course = $this->getDataGenerator()->create_course();
893
        $course = $this->getDataGenerator()->create_course();
894
        $coursecontext = \context_course::instance($course->id);
894
        $coursecontext = \context_course::instance($course->id);
895
        $this->assertEquals("https://www.example.com/moodle/user/view.php?id={$user->id}&courseid={$course->id}",
895
        $this->assertEquals("https://www.example.com/moodle/user/view.php?id={$user->id}&course={$course->id}",
Línea 896... Línea 896...
896
            \core_user::get_profile_url($user, $coursecontext));
896
            \core_user::get_profile_url($user, $coursecontext));
897
 
897
 
898
        // Throw error if userid is invalid.
898
        // Throw error if userid is invalid.
Línea 905... Línea 905...
905
    /**
905
    /**
906
     * Test for function to get user details.
906
     * Test for function to get user details.
907
     *
907
     *
908
     * @covers \core_user::get_profile_picture
908
     * @covers \core_user::get_profile_picture
909
     */
909
     */
910
    public function test_display_profile_picture() {
910
    public function test_display_profile_picture(): void {
911
        global $OUTPUT, $CFG;
911
        global $OUTPUT, $CFG;
912
        $this->resetAfterTest();
912
        $this->resetAfterTest();
Línea 913... Línea 913...
913
 
913
 
914
        $user1 = $this->getDataGenerator()->create_user(['firstname' => 'John', 'lastname' => 'Doe']);
914
        $user1 = $this->getDataGenerator()->create_user(['firstname' => 'John', 'lastname' => 'Doe']);