forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwpDropdownUsers.php
More file actions
204 lines (169 loc) · 4.68 KB
/
wpDropdownUsers.php
File metadata and controls
204 lines (169 loc) · 4.68 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
/**
* Test functions in wp-includes/user.php
*
* @group user
*/
class Tests_User_wpDropdownUsers extends WP_UnitTestCase {
/**
* @ticket 31251
*/
public function test_default_value_of_show_should_be_display_name() {
// Create a user with a different display_name.
$u = self::factory()->user->create(
array(
'user_login' => 'foo',
'display_name' => 'Foo Person',
)
);
$found = wp_dropdown_users(
array(
'echo' => false,
)
);
$expected = "<option value='$u'>Foo Person</option>";
$this->assertStringContainsString( $expected, $found );
}
/**
* @ticket 31251
*/
public function test_show_should_display_display_name_show_is_specified_as_empty() {
// Create a user with a different display_name.
$u = self::factory()->user->create(
array(
'user_login' => 'foo',
'display_name' => 'Foo Person',
)
);
// Get the result of a non-default, but acceptable input for 'show' parameter to wp_dropdown_users().
$found = wp_dropdown_users(
array(
'echo' => false,
'show' => '',
)
);
$expected = "<option value='$u'>Foo Person</option>";
$this->assertStringContainsString( $expected, $found );
}
/**
* @ticket 31251
*/
public function test_show_should_display_user_property_when_the_value_of_show_is_a_valid_user_property() {
// Create a user with a different display_name.
$u = self::factory()->user->create(
array(
'user_login' => 'foo',
'display_name' => 'Foo Person',
)
);
// Get the result of a non-default, but acceptable input for 'show' parameter to wp_dropdown_users().
$found = wp_dropdown_users(
array(
'echo' => false,
'show' => 'user_login',
)
);
$expected = "<option value='$u'>foo</option>";
$this->assertStringContainsString( $expected, $found );
}
/**
* @ticket 31251
*/
public function test_show_display_name_with_login() {
// Create a user with a different display_name.
$u = self::factory()->user->create(
array(
'user_login' => 'foo',
'display_name' => 'Foo Person',
)
);
// Get the result of a non-default, but acceptable input for 'show' parameter to wp_dropdown_users().
$found = wp_dropdown_users(
array(
'echo' => false,
'show' => 'display_name_with_login',
)
);
$expected = "<option value='$u'>Foo Person (foo)</option>";
$this->assertStringContainsString( $expected, $found );
}
/**
* @ticket 31251
*/
public function test_include_selected() {
$users = self::factory()->user->create_many( 2 );
$found = wp_dropdown_users(
array(
'echo' => false,
'include' => $users[0],
'selected' => $users[1],
'include_selected' => true,
'show' => 'user_login',
)
);
$user1 = get_userdata( $users[1] );
$this->assertStringContainsString( $user1->user_login, $found );
}
/**
* @ticket 51370
*/
public function test_include_selected_with_non_existing_user_id() {
$found = wp_dropdown_users(
array(
'echo' => false,
'selected' => PHP_INT_MAX,
'include_selected' => true,
'show' => 'user_login',
)
);
$this->assertStringNotContainsString( (string) PHP_INT_MAX, $found );
}
/**
* @ticket 38135
*/
public function test_role() {
$u1 = self::factory()->user->create_and_get( array( 'role' => 'subscriber' ) );
$u2 = self::factory()->user->create_and_get( array( 'role' => 'author' ) );
$found = wp_dropdown_users(
array(
'echo' => false,
'role' => 'author',
'show' => 'user_login',
)
);
$this->assertStringNotContainsString( $u1->user_login, $found );
$this->assertStringContainsString( $u2->user_login, $found );
}
/**
* @ticket 38135
*/
public function test_role__in() {
$u1 = self::factory()->user->create_and_get( array( 'role' => 'subscriber' ) );
$u2 = self::factory()->user->create_and_get( array( 'role' => 'author' ) );
$found = wp_dropdown_users(
array(
'echo' => false,
'role__in' => array( 'author', 'editor' ),
'show' => 'user_login',
)
);
$this->assertStringNotContainsString( $u1->user_login, $found );
$this->assertStringContainsString( $u2->user_login, $found );
}
/**
* @ticket 38135
*/
public function test_role__not_in() {
$u1 = self::factory()->user->create_and_get( array( 'role' => 'subscriber' ) );
$u2 = self::factory()->user->create_and_get( array( 'role' => 'author' ) );
$found = wp_dropdown_users(
array(
'echo' => false,
'role__not_in' => array( 'subscriber', 'editor' ),
'show' => 'user_login',
)
);
$this->assertStringNotContainsString( $u1->user_login, $found );
$this->assertStringContainsString( $u2->user_login, $found );
}
}