forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathretrievePassword.php
More file actions
77 lines (70 loc) · 1.73 KB
/
retrievePassword.php
File metadata and controls
77 lines (70 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Test cases for the `retrieve_password()` function.
*
* @package WordPress
* @since 6.0.0
*
* @group user
* @covers ::retrieve_password
*/
class Tests_User_RetrievePassword extends WP_UnitTestCase {
/**
* Test user.
*
* @since 6.0.0
*
* @var WP_User $user
*/
protected $user;
/**
* Create users for tests.
*
* @since 6.0.0
*/
public function set_up() {
parent::set_up();
// Create the user.
$this->user = self::factory()->user->create_and_get(
array(
'user_login' => 'jane',
'user_email' => 'r.jane@example.com',
)
);
}
/**
* The function should not error when the email was sent.
*
* @ticket 54690
*/
public function test_retrieve_password_reset_notification_email() {
$this->assertNotWPError( retrieve_password( $this->user->user_login ), 'Sending password reset notification email failed.' );
}
/**
* The function should error when the email was not sent.
*
* @ticket 54690
*/
public function test_retrieve_password_should_return_wp_error_on_failed_email() {
add_filter(
'retrieve_password_notification_email',
static function() {
return array( 'message' => '' );
}
);
$this->assertWPError( retrieve_password( $this->user->user_login ), 'Sending password reset notification email succeeded.' );
}
/**
* @ticket 53634
*/
public function test_retrieve_password_should_fetch_user_by_login_if_not_found_by_email() {
self::factory()->user->create(
array(
'user_login' => 'foo@example.com',
'user_email' => 'bar@example.com',
)
);
$this->assertTrue( retrieve_password( 'foo@example.com' ), 'Fetching user by login failed.' );
$this->assertTrue( retrieve_password( 'bar@example.com' ), 'Fetching user by email failed.' );
}
}