1 | 7a8 |
---|
2 | > var $user_creds; |
---|
3 | 9c10,11 |
---|
4 | < |
---|
5 | --- |
---|
6 | > var $user; |
---|
7 | > |
---|
8 | 12,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 | > |
---|
20 | 163a172,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 | > |
---|