Changeset 53478
- Timestamp:
- 06/07/2022 02:44:00 PM (3 years ago)
- Location:
- trunk/tests/phpunit/tests
- Files:
-
- 1 added
- 1 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/pluggable.php
r53477 r53478 339 339 return $signatures; 340 340 } 341 342 /**343 * @ticket 28020344 */345 public function test_get_user_by_should_return_same_instance_as_wp_get_current_user() {346 // Create a test user.347 $new_user = self::factory()->user->create( array( 'role' => 'subscriber' ) );348 349 // Set the test user as the current user.350 $current_user = wp_set_current_user( $new_user );351 352 // Get the test user using get_user_by().353 $from_get_user_by = get_user_by( 'id', $new_user );354 355 $this->assertSame( $current_user, $from_get_user_by );356 }357 358 /**359 * Tests that wp_rand() returns zero when `$min` and `$max` are zero.360 *361 * @ticket 55194362 * @dataProvider data_wp_rand_should_return_zero_when_min_and_max_are_zero363 * @covers ::wp_rand364 *365 * @param mixed $min Lower limit for the generated number.366 * @param mixed $max Upper limit for the generated number.367 */368 public function test_wp_rand_should_return_zero_when_min_and_max_are_zero( $min, $max ) {369 $this->assertSame( 0, wp_rand( $min, $max ) );370 }371 372 /**373 * Data provider.374 *375 * @return array376 */377 public function data_wp_rand_should_return_zero_when_min_and_max_are_zero() {378 return array(379 'min and max as 0' => array(380 'min' => 0,381 'max' => 0,382 ),383 'min and max as 0.0' => array(384 'min' => 0.0,385 'max' => 0.0,386 ),387 'min as null, max as 0' => array(388 'min' => null,389 'max' => 0,390 ),391 );392 }393 394 /**395 * Tests that wp_rand() returns a positive integer for both positive and negative input.396 *397 * @ticket 55194398 * @dataProvider data_wp_rand_should_return_a_positive_integer399 * @covers ::wp_rand400 *401 * @param int $min Lower limit for the generated number.402 * @param int $max Upper limit for the generated number.403 */404 public function test_wp_rand_should_return_a_positive_integer( $min, $max ) {405 $this->assertGreaterThan(406 0,407 wp_rand( $min, $max ),408 'The value was not greater than 0'409 );410 411 $this->assertLessThan(412 100,413 wp_rand( $min, $max ),414 'The value was not less than 100'415 );416 }417 418 /**419 * Data provider.420 *421 * @return array422 */423 public function data_wp_rand_should_return_a_positive_integer() {424 return array(425 '1 and 99' => array(426 'min' => 1,427 'max' => 99,428 ),429 '-1 and 99' => array(430 'min' => -1,431 'max' => 99,432 ),433 '1 and -99' => array(434 'min' => 1,435 'max' => -99,436 ),437 '-1 and -99' => array(438 'min' => -1,439 'max' => -99,440 ),441 '1.0 and 99.0' => array(442 'min' => 1.0,443 'max' => 99.0,444 ),445 '-1.0 and -99.0' => array(446 'min' => -1.0,447 'max' => -99.0,448 ),449 );450 }451 341 } -
trunk/tests/phpunit/tests/pluggable/getUserBy.php
r53477 r53478 3 3 /** 4 4 * @group pluggable 5 * @covers ::get_user_by 5 6 */ 6 class Tests_Pluggable extends WP_UnitTestCase { 7 8 /** 9 * Tests that the signatures of all functions in pluggable.php match their expected signature. 10 * 11 * @ticket 33654 12 * @ticket 33867 13 * 14 * @dataProvider get_defined_pluggable_functions 15 */ 16 public function test_pluggable_function_signatures_match( $function ) { 17 18 $signatures = $this->get_pluggable_function_signatures(); 19 20 $this->assertTrue( function_exists( $function ) ); 21 $this->assertArrayHasKey( $function, $signatures ); 22 23 $function_ref = new ReflectionFunction( $function ); 24 $param_refs = $function_ref->getParameters(); 25 26 $this->assertSame( count( $signatures[ $function ] ), count( $param_refs ) ); 27 28 $i = 0; 29 30 foreach ( $signatures[ $function ] as $name => $value ) { 31 32 $param_ref = $param_refs[ $i ]; 33 $msg = 'Parameter: ' . $param_ref->getName(); 34 35 if ( is_numeric( $name ) ) { 36 $name = $value; 37 $this->assertFalse( $param_ref->isOptional(), $msg ); 38 } else { 39 $this->assertTrue( $param_ref->isOptional(), $msg ); 40 $this->assertSame( $value, $param_ref->getDefaultValue(), $msg ); 41 } 42 43 $this->assertSame( $name, $param_ref->getName(), $msg ); 44 45 $i++; 46 47 } 48 49 } 50 51 /** 52 * Test the tests. Makes sure all the expected pluggable functions exist and that they live in pluggable.php. 53 * 54 * @ticket 33654 55 * @ticket 33867 56 */ 57 public function test_all_pluggable_functions_exist() { 58 59 $defined = wp_list_pluck( $this->get_defined_pluggable_functions(), 0 ); 60 $expected = $this->get_pluggable_function_signatures(); 61 62 foreach ( $expected as $function => $sig ) { 63 $msg = 'Function: ' . $function . '()'; 64 $this->assertTrue( function_exists( $function ), $msg ); 65 $this->assertContains( $function, $defined, $msg ); 66 } 67 68 } 69 70 /** 71 * Data provider for our pluggable function signature tests. 72 * 73 * @return array Data provider array of pluggable function names. 74 */ 75 public function get_defined_pluggable_functions() { 76 77 require_once ABSPATH . '/wp-admin/includes/upgrade.php'; 78 79 $test_functions = array( 80 'install_network', 81 'wp_install', 82 'wp_install_defaults', 83 'wp_new_blog_notification', 84 'wp_upgrade', 85 'install_global_terms', 86 ); 87 $test_files = array( 88 'wp-includes/pluggable.php', 89 ); 90 91 // Pluggable function signatures are not tested when an external object cache is in use. See #31491. 92 if ( ! wp_using_ext_object_cache() ) { 93 $test_files[] = 'wp-includes/cache.php'; 94 } 95 96 $data = array(); 97 98 foreach ( $test_functions as $function ) { 99 $data[] = array( 100 $function, 101 ); 102 } 103 104 foreach ( $test_files as $file ) { 105 preg_match_all( '#^\t?function (\w+)#m', file_get_contents( ABSPATH . '/' . $file ), $functions ); 106 107 foreach ( $functions[1] as $function ) { 108 $data[] = array( 109 $function, 110 ); 111 } 112 } 113 114 return $data; 115 116 } 117 118 /** 119 * Expected pluggable function signatures. 120 * 121 * @return array Array of signatures keyed by their function name. 122 */ 123 public function get_pluggable_function_signatures() { 124 125 $signatures = array( 126 127 // wp-includes/pluggable.php: 128 'wp_set_current_user' => array( 129 'id', 130 'name' => '', 131 ), 132 'wp_get_current_user' => array(), 133 'get_userdata' => array( 'user_id' ), 134 'get_user_by' => array( 'field', 'value' ), 135 'cache_users' => array( 'user_ids' ), 136 'wp_mail' => array( 137 'to', 138 'subject', 139 'message', 140 'headers' => '', 141 'attachments' => array(), 142 ), 143 'wp_authenticate' => array( 'username', 'password' ), 144 'wp_logout' => array(), 145 'wp_validate_auth_cookie' => array( 146 'cookie' => '', 147 'scheme' => '', 148 ), 149 'wp_generate_auth_cookie' => array( 150 'user_id', 151 'expiration', 152 'scheme' => 'auth', 153 'token' => '', 154 ), 155 'wp_parse_auth_cookie' => array( 156 'cookie' => '', 157 'scheme' => '', 158 ), 159 'wp_set_auth_cookie' => array( 160 'user_id', 161 'remember' => false, 162 'secure' => '', 163 'token' => '', 164 ), 165 'wp_clear_auth_cookie' => array(), 166 'is_user_logged_in' => array(), 167 'auth_redirect' => array(), 168 'check_admin_referer' => array( 169 'action' => -1, 170 'query_arg' => '_wpnonce', 171 ), 172 'check_ajax_referer' => array( 173 'action' => -1, 174 'query_arg' => false, 175 'die' => true, 176 ), 177 'wp_redirect' => array( 178 'location', 179 'status' => 302, 180 'x_redirect_by' => 'WordPress', 181 ), 182 'wp_sanitize_redirect' => array( 'location' ), 183 '_wp_sanitize_utf8_in_redirect' => array( 'matches' ), 184 'wp_safe_redirect' => array( 185 'location', 186 'status' => 302, 187 'x_redirect_by' => 'WordPress', 188 ), 189 'wp_validate_redirect' => array( 190 'location', 191 'default' => '', 192 ), 193 'wp_notify_postauthor' => array( 194 'comment_id', 195 'deprecated' => null, 196 ), 197 'wp_notify_moderator' => array( 'comment_id' ), 198 'wp_password_change_notification' => array( 'user' ), 199 'wp_new_user_notification' => array( 200 'user_id', 201 'deprecated' => null, 202 'notify' => '', 203 ), 204 'wp_nonce_tick' => array(), 205 'wp_verify_nonce' => array( 206 'nonce', 207 'action' => -1, 208 ), 209 'wp_create_nonce' => array( 'action' => -1 ), 210 'wp_salt' => array( 'scheme' => 'auth' ), 211 'wp_hash' => array( 212 'data', 213 'scheme' => 'auth', 214 ), 215 'wp_hash_password' => array( 'password' ), 216 'wp_check_password' => array( 217 'password', 218 'hash', 219 'user_id' => '', 220 ), 221 'wp_generate_password' => array( 222 'length' => 12, 223 'special_chars' => true, 224 'extra_special_chars' => false, 225 ), 226 'wp_rand' => array( 227 'min' => null, 228 'max' => null, 229 ), 230 'wp_set_password' => array( 'password', 'user_id' ), 231 'get_avatar' => array( 232 'id_or_email', 233 'size' => 96, 234 'default' => '', 235 'alt' => '', 236 'args' => null, 237 ), 238 'wp_text_diff' => array( 239 'left_string', 240 'right_string', 241 'args' => null, 242 ), 243 244 // wp-admin/includes/schema.php: 245 'install_network' => array(), 246 247 // wp-admin/includes/upgrade.php: 248 'wp_install' => array( 249 'blog_title', 250 'user_name', 251 'user_email', 252 'is_public', 253 'deprecated' => '', 254 'user_password' => '', 255 'language' => '', 256 ), 257 'wp_install_defaults' => array( 'user_id' ), 258 'wp_new_blog_notification' => array( 'blog_title', 'blog_url', 'user_id', 'password' ), 259 'wp_upgrade' => array(), 260 'install_global_terms' => array(), 261 ); 262 263 // Pluggable function signatures are not tested when an external object cache is in use. See #31491. 264 if ( ! wp_using_ext_object_cache() ) { 265 $signatures = array_merge( 266 $signatures, 267 array( 268 269 // wp-includes/cache.php: 270 'wp_cache_init' => array(), 271 'wp_cache_add' => array( 272 'key', 273 'data', 274 'group' => '', 275 'expire' => 0, 276 ), 277 'wp_cache_add_multiple' => array( 278 'data', 279 'group' => '', 280 'expire' => 0, 281 ), 282 'wp_cache_replace' => array( 283 'key', 284 'data', 285 'group' => '', 286 'expire' => 0, 287 ), 288 'wp_cache_set' => array( 289 'key', 290 'data', 291 'group' => '', 292 'expire' => 0, 293 ), 294 'wp_cache_set_multiple' => array( 295 'data', 296 'group' => '', 297 'expire' => 0, 298 ), 299 'wp_cache_get' => array( 300 'key', 301 'group' => '', 302 'force' => false, 303 'found' => null, 304 ), 305 'wp_cache_get_multiple' => array( 306 'keys', 307 'group' => '', 308 'force' => false, 309 ), 310 'wp_cache_delete' => array( 311 'key', 312 'group' => '', 313 ), 314 'wp_cache_delete_multiple' => array( 315 'keys', 316 'group' => '', 317 ), 318 'wp_cache_incr' => array( 319 'key', 320 'offset' => 1, 321 'group' => '', 322 ), 323 'wp_cache_decr' => array( 324 'key', 325 'offset' => 1, 326 'group' => '', 327 ), 328 'wp_cache_flush' => array(), 329 'wp_cache_flush_runtime' => array(), 330 'wp_cache_close' => array(), 331 'wp_cache_add_global_groups' => array( 'groups' ), 332 'wp_cache_add_non_persistent_groups' => array( 'groups' ), 333 'wp_cache_switch_to_blog' => array( 'blog_id' ), 334 'wp_cache_reset' => array(), 335 ) 336 ); 337 } 338 339 return $signatures; 340 } 7 class Tests_Pluggable_GetUserBy extends WP_UnitTestCase { 341 8 342 9 /** … … 355 22 $this->assertSame( $current_user, $from_get_user_by ); 356 23 } 357 358 /**359 * Tests that wp_rand() returns zero when `$min` and `$max` are zero.360 *361 * @ticket 55194362 * @dataProvider data_wp_rand_should_return_zero_when_min_and_max_are_zero363 * @covers ::wp_rand364 *365 * @param mixed $min Lower limit for the generated number.366 * @param mixed $max Upper limit for the generated number.367 */368 public function test_wp_rand_should_return_zero_when_min_and_max_are_zero( $min, $max ) {369 $this->assertSame( 0, wp_rand( $min, $max ) );370 }371 372 /**373 * Data provider.374 *375 * @return array376 */377 public function data_wp_rand_should_return_zero_when_min_and_max_are_zero() {378 return array(379 'min and max as 0' => array(380 'min' => 0,381 'max' => 0,382 ),383 'min and max as 0.0' => array(384 'min' => 0.0,385 'max' => 0.0,386 ),387 'min as null, max as 0' => array(388 'min' => null,389 'max' => 0,390 ),391 );392 }393 394 /**395 * Tests that wp_rand() returns a positive integer for both positive and negative input.396 *397 * @ticket 55194398 * @dataProvider data_wp_rand_should_return_a_positive_integer399 * @covers ::wp_rand400 *401 * @param int $min Lower limit for the generated number.402 * @param int $max Upper limit for the generated number.403 */404 public function test_wp_rand_should_return_a_positive_integer( $min, $max ) {405 $this->assertGreaterThan(406 0,407 wp_rand( $min, $max ),408 'The value was not greater than 0'409 );410 411 $this->assertLessThan(412 100,413 wp_rand( $min, $max ),414 'The value was not less than 100'415 );416 }417 418 /**419 * Data provider.420 *421 * @return array422 */423 public function data_wp_rand_should_return_a_positive_integer() {424 return array(425 '1 and 99' => array(426 'min' => 1,427 'max' => 99,428 ),429 '-1 and 99' => array(430 'min' => -1,431 'max' => 99,432 ),433 '1 and -99' => array(434 'min' => 1,435 'max' => -99,436 ),437 '-1 and -99' => array(438 'min' => -1,439 'max' => -99,440 ),441 '1.0 and 99.0' => array(442 'min' => 1.0,443 'max' => 99.0,444 ),445 '-1.0 and -99.0' => array(446 'min' => -1.0,447 'max' => -99.0,448 ),449 );450 }451 24 } -
trunk/tests/phpunit/tests/pluggable/wpRand.php
r53477 r53478 3 3 /** 4 4 * @group pluggable 5 * @covers ::wp_rand 5 6 */ 6 class Tests_Pluggable extends WP_UnitTestCase { 7 8 /** 9 * Tests that the signatures of all functions in pluggable.php match their expected signature. 10 * 11 * @ticket 33654 12 * @ticket 33867 13 * 14 * @dataProvider get_defined_pluggable_functions 15 */ 16 public function test_pluggable_function_signatures_match( $function ) { 17 18 $signatures = $this->get_pluggable_function_signatures(); 19 20 $this->assertTrue( function_exists( $function ) ); 21 $this->assertArrayHasKey( $function, $signatures ); 22 23 $function_ref = new ReflectionFunction( $function ); 24 $param_refs = $function_ref->getParameters(); 25 26 $this->assertSame( count( $signatures[ $function ] ), count( $param_refs ) ); 27 28 $i = 0; 29 30 foreach ( $signatures[ $function ] as $name => $value ) { 31 32 $param_ref = $param_refs[ $i ]; 33 $msg = 'Parameter: ' . $param_ref->getName(); 34 35 if ( is_numeric( $name ) ) { 36 $name = $value; 37 $this->assertFalse( $param_ref->isOptional(), $msg ); 38 } else { 39 $this->assertTrue( $param_ref->isOptional(), $msg ); 40 $this->assertSame( $value, $param_ref->getDefaultValue(), $msg ); 41 } 42 43 $this->assertSame( $name, $param_ref->getName(), $msg ); 44 45 $i++; 46 47 } 48 49 } 50 51 /** 52 * Test the tests. Makes sure all the expected pluggable functions exist and that they live in pluggable.php. 53 * 54 * @ticket 33654 55 * @ticket 33867 56 */ 57 public function test_all_pluggable_functions_exist() { 58 59 $defined = wp_list_pluck( $this->get_defined_pluggable_functions(), 0 ); 60 $expected = $this->get_pluggable_function_signatures(); 61 62 foreach ( $expected as $function => $sig ) { 63 $msg = 'Function: ' . $function . '()'; 64 $this->assertTrue( function_exists( $function ), $msg ); 65 $this->assertContains( $function, $defined, $msg ); 66 } 67 68 } 69 70 /** 71 * Data provider for our pluggable function signature tests. 72 * 73 * @return array Data provider array of pluggable function names. 74 */ 75 public function get_defined_pluggable_functions() { 76 77 require_once ABSPATH . '/wp-admin/includes/upgrade.php'; 78 79 $test_functions = array( 80 'install_network', 81 'wp_install', 82 'wp_install_defaults', 83 'wp_new_blog_notification', 84 'wp_upgrade', 85 'install_global_terms', 86 ); 87 $test_files = array( 88 'wp-includes/pluggable.php', 89 ); 90 91 // Pluggable function signatures are not tested when an external object cache is in use. See #31491. 92 if ( ! wp_using_ext_object_cache() ) { 93 $test_files[] = 'wp-includes/cache.php'; 94 } 95 96 $data = array(); 97 98 foreach ( $test_functions as $function ) { 99 $data[] = array( 100 $function, 101 ); 102 } 103 104 foreach ( $test_files as $file ) { 105 preg_match_all( '#^\t?function (\w+)#m', file_get_contents( ABSPATH . '/' . $file ), $functions ); 106 107 foreach ( $functions[1] as $function ) { 108 $data[] = array( 109 $function, 110 ); 111 } 112 } 113 114 return $data; 115 116 } 117 118 /** 119 * Expected pluggable function signatures. 120 * 121 * @return array Array of signatures keyed by their function name. 122 */ 123 public function get_pluggable_function_signatures() { 124 125 $signatures = array( 126 127 // wp-includes/pluggable.php: 128 'wp_set_current_user' => array( 129 'id', 130 'name' => '', 131 ), 132 'wp_get_current_user' => array(), 133 'get_userdata' => array( 'user_id' ), 134 'get_user_by' => array( 'field', 'value' ), 135 'cache_users' => array( 'user_ids' ), 136 'wp_mail' => array( 137 'to', 138 'subject', 139 'message', 140 'headers' => '', 141 'attachments' => array(), 142 ), 143 'wp_authenticate' => array( 'username', 'password' ), 144 'wp_logout' => array(), 145 'wp_validate_auth_cookie' => array( 146 'cookie' => '', 147 'scheme' => '', 148 ), 149 'wp_generate_auth_cookie' => array( 150 'user_id', 151 'expiration', 152 'scheme' => 'auth', 153 'token' => '', 154 ), 155 'wp_parse_auth_cookie' => array( 156 'cookie' => '', 157 'scheme' => '', 158 ), 159 'wp_set_auth_cookie' => array( 160 'user_id', 161 'remember' => false, 162 'secure' => '', 163 'token' => '', 164 ), 165 'wp_clear_auth_cookie' => array(), 166 'is_user_logged_in' => array(), 167 'auth_redirect' => array(), 168 'check_admin_referer' => array( 169 'action' => -1, 170 'query_arg' => '_wpnonce', 171 ), 172 'check_ajax_referer' => array( 173 'action' => -1, 174 'query_arg' => false, 175 'die' => true, 176 ), 177 'wp_redirect' => array( 178 'location', 179 'status' => 302, 180 'x_redirect_by' => 'WordPress', 181 ), 182 'wp_sanitize_redirect' => array( 'location' ), 183 '_wp_sanitize_utf8_in_redirect' => array( 'matches' ), 184 'wp_safe_redirect' => array( 185 'location', 186 'status' => 302, 187 'x_redirect_by' => 'WordPress', 188 ), 189 'wp_validate_redirect' => array( 190 'location', 191 'default' => '', 192 ), 193 'wp_notify_postauthor' => array( 194 'comment_id', 195 'deprecated' => null, 196 ), 197 'wp_notify_moderator' => array( 'comment_id' ), 198 'wp_password_change_notification' => array( 'user' ), 199 'wp_new_user_notification' => array( 200 'user_id', 201 'deprecated' => null, 202 'notify' => '', 203 ), 204 'wp_nonce_tick' => array(), 205 'wp_verify_nonce' => array( 206 'nonce', 207 'action' => -1, 208 ), 209 'wp_create_nonce' => array( 'action' => -1 ), 210 'wp_salt' => array( 'scheme' => 'auth' ), 211 'wp_hash' => array( 212 'data', 213 'scheme' => 'auth', 214 ), 215 'wp_hash_password' => array( 'password' ), 216 'wp_check_password' => array( 217 'password', 218 'hash', 219 'user_id' => '', 220 ), 221 'wp_generate_password' => array( 222 'length' => 12, 223 'special_chars' => true, 224 'extra_special_chars' => false, 225 ), 226 'wp_rand' => array( 227 'min' => null, 228 'max' => null, 229 ), 230 'wp_set_password' => array( 'password', 'user_id' ), 231 'get_avatar' => array( 232 'id_or_email', 233 'size' => 96, 234 'default' => '', 235 'alt' => '', 236 'args' => null, 237 ), 238 'wp_text_diff' => array( 239 'left_string', 240 'right_string', 241 'args' => null, 242 ), 243 244 // wp-admin/includes/schema.php: 245 'install_network' => array(), 246 247 // wp-admin/includes/upgrade.php: 248 'wp_install' => array( 249 'blog_title', 250 'user_name', 251 'user_email', 252 'is_public', 253 'deprecated' => '', 254 'user_password' => '', 255 'language' => '', 256 ), 257 'wp_install_defaults' => array( 'user_id' ), 258 'wp_new_blog_notification' => array( 'blog_title', 'blog_url', 'user_id', 'password' ), 259 'wp_upgrade' => array(), 260 'install_global_terms' => array(), 261 ); 262 263 // Pluggable function signatures are not tested when an external object cache is in use. See #31491. 264 if ( ! wp_using_ext_object_cache() ) { 265 $signatures = array_merge( 266 $signatures, 267 array( 268 269 // wp-includes/cache.php: 270 'wp_cache_init' => array(), 271 'wp_cache_add' => array( 272 'key', 273 'data', 274 'group' => '', 275 'expire' => 0, 276 ), 277 'wp_cache_add_multiple' => array( 278 'data', 279 'group' => '', 280 'expire' => 0, 281 ), 282 'wp_cache_replace' => array( 283 'key', 284 'data', 285 'group' => '', 286 'expire' => 0, 287 ), 288 'wp_cache_set' => array( 289 'key', 290 'data', 291 'group' => '', 292 'expire' => 0, 293 ), 294 'wp_cache_set_multiple' => array( 295 'data', 296 'group' => '', 297 'expire' => 0, 298 ), 299 'wp_cache_get' => array( 300 'key', 301 'group' => '', 302 'force' => false, 303 'found' => null, 304 ), 305 'wp_cache_get_multiple' => array( 306 'keys', 307 'group' => '', 308 'force' => false, 309 ), 310 'wp_cache_delete' => array( 311 'key', 312 'group' => '', 313 ), 314 'wp_cache_delete_multiple' => array( 315 'keys', 316 'group' => '', 317 ), 318 'wp_cache_incr' => array( 319 'key', 320 'offset' => 1, 321 'group' => '', 322 ), 323 'wp_cache_decr' => array( 324 'key', 325 'offset' => 1, 326 'group' => '', 327 ), 328 'wp_cache_flush' => array(), 329 'wp_cache_flush_runtime' => array(), 330 'wp_cache_close' => array(), 331 'wp_cache_add_global_groups' => array( 'groups' ), 332 'wp_cache_add_non_persistent_groups' => array( 'groups' ), 333 'wp_cache_switch_to_blog' => array( 'blog_id' ), 334 'wp_cache_reset' => array(), 335 ) 336 ); 337 } 338 339 return $signatures; 340 } 341 342 /** 343 * @ticket 28020 344 */ 345 public function test_get_user_by_should_return_same_instance_as_wp_get_current_user() { 346 // Create a test user. 347 $new_user = self::factory()->user->create( array( 'role' => 'subscriber' ) ); 348 349 // Set the test user as the current user. 350 $current_user = wp_set_current_user( $new_user ); 351 352 // Get the test user using get_user_by(). 353 $from_get_user_by = get_user_by( 'id', $new_user ); 354 355 $this->assertSame( $current_user, $from_get_user_by ); 356 } 357 358 /** 359 * Tests that wp_rand() returns zero when `$min` and `$max` are zero. 360 * 361 * @ticket 55194 362 * @dataProvider data_wp_rand_should_return_zero_when_min_and_max_are_zero 363 * @covers ::wp_rand 364 * 365 * @param mixed $min Lower limit for the generated number. 366 * @param mixed $max Upper limit for the generated number. 367 */ 368 public function test_wp_rand_should_return_zero_when_min_and_max_are_zero( $min, $max ) { 369 $this->assertSame( 0, wp_rand( $min, $max ) ); 370 } 371 372 /** 373 * Data provider. 374 * 375 * @return array 376 */ 377 public function data_wp_rand_should_return_zero_when_min_and_max_are_zero() { 378 return array( 379 'min and max as 0' => array( 380 'min' => 0, 381 'max' => 0, 382 ), 383 'min and max as 0.0' => array( 384 'min' => 0.0, 385 'max' => 0.0, 386 ), 387 'min as null, max as 0' => array( 388 'min' => null, 389 'max' => 0, 390 ), 391 ); 392 } 7 class Tests_Pluggable_wpRand extends WP_UnitTestCase { 393 8 394 9 /** … … 397 12 * @ticket 55194 398 13 * @dataProvider data_wp_rand_should_return_a_positive_integer 399 * @covers ::wp_rand400 14 * 401 15 * @param int $min Lower limit for the generated number. … … 449 63 ); 450 64 } 65 66 /** 67 * Tests that wp_rand() returns zero when `$min` and `$max` are zero. 68 * 69 * @ticket 55194 70 * @dataProvider data_wp_rand_should_return_zero_when_min_and_max_are_zero 71 * 72 * @param mixed $min Lower limit for the generated number. 73 * @param mixed $max Upper limit for the generated number. 74 */ 75 public function test_wp_rand_should_return_zero_when_min_and_max_are_zero( $min, $max ) { 76 $this->assertSame( 0, wp_rand( $min, $max ) ); 77 } 78 79 /** 80 * Data provider. 81 * 82 * @return array 83 */ 84 public function data_wp_rand_should_return_zero_when_min_and_max_are_zero() { 85 return array( 86 'min and max as 0' => array( 87 'min' => 0, 88 'max' => 0, 89 ), 90 'min and max as 0.0' => array( 91 'min' => 0.0, 92 'max' => 0.0, 93 ), 94 'min as null, max as 0' => array( 95 'min' => null, 96 'max' => 0, 97 ), 98 ); 99 } 451 100 }
Note: See TracChangeset
for help on using the changeset viewer.