Make WordPress Core

Ticket #9568: auth_with_login_tests.php

File auth_with_login_tests.php, 2.1 KB (added by vhomenko, 10 years ago)

add wp_authenticate_username_password and wp_authenticate_email_password unit tests to wordpress-develop/tests/phpunit/tests/auth.php

Line 
17a8
2>       var $user_creds;
39c10,11
4<
5---
6>       var $user;
7>       
812,13c14,21
9<               $this->user_id = $this->factory->user->create();
10<
11---
12>               
13>               $this->user_creds = array(
14>                       'user_login' => 'dorothy',
15>                       'user_pass' => 'flowers',
16>                       'user_email' => 'speed@metal.forum' );
17>               $this->user_id = $this->factory->user->create( $this->user_creds );
18>               $this->user = new WP_User( $this->user_id );
19>                               
20163a172,211
21>
22>       function testLoginWithUsername() {
23>               $authed_user = wp_authenticate( $this->user_creds['user_login'], $this->user_creds['user_pass'] );
24>               $this->assertEquals( $this->user, $authed_user );
25>       }
26>       
27>       function testLoginWithEmail() {
28>               $email_authed_user = wp_authenticate( $this->user_creds['user_email'], $this->user_creds['user_pass'] );
29>               $this->assertEquals( $this->user, $email_authed_user );
30>       }
31>
32>       function testLoginWithEmptyUsernameAndPassword() {
33>               $he_came_too_soon = wp_authenticate( '', '' );
34>               $this->assertInstanceOf( 'WP_Error', $he_came_too_soon );
35>               $this->assertObjectHasAttribute( 'errors', $he_came_too_soon );
36>               $this->assertTrue( isset( $he_came_too_soon->errors['empty_username'] ) );
37>               $this->assertTrue( isset( $he_came_too_soon->errors['empty_password'] ) );
38>       }
39>       
40>       function testLoginWithWrongUsername() {
41>               $mr_x = wp_authenticate( 'wrong', $this->user_creds['user_pass'] );
42>               $this->assertInstanceOf( 'WP_Error', $mr_x );
43>               $this->assertObjectHasAttribute( 'errors', $mr_x );
44>               $this->assertTrue( isset( $mr_x->errors['invalid_username'] ) );
45>       }
46>
47>       function testLoginWithWrongEmail() {
48>               $mr_x = wp_authenticate( 'so@wrong.com', $this->user_creds['user_pass'] );
49>               $this->assertInstanceOf( 'WP_Error', $mr_x );
50>               $this->assertObjectHasAttribute( 'errors', $mr_x );
51>               $this->assertTrue( isset( $mr_x->errors['invalid_email'] ) );
52>       }
53>
54>       function testLoginWithWrongPassword() {
55>               $forgetful = wp_authenticate( $this->user_creds['user_login'], 'abc' );
56>               $this->assertInstanceOf( 'WP_Error', $forgetful );
57>               $this->assertObjectHasAttribute( 'errors', $forgetful );
58>               $this->assertTrue( isset( $forgetful->errors['incorrect_password'] ) );
59>       }
60>