Changeset 52010 for trunk/tests/phpunit/tests/functions.php
- Timestamp:
- 11/04/2021 03:22:47 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/functions.php
r51653 r52010 5 5 */ 6 6 class Tests_Functions extends WP_UnitTestCase { 7 function test_wp_parse_args_object() {7 public function test_wp_parse_args_object() { 8 8 $x = new MockClass; 9 9 $x->_baba = 5; … … 22 22 } 23 23 24 function test_wp_parse_args_array() {24 public function test_wp_parse_args_array() { 25 25 // Arrays. 26 26 $a = array(); … … 41 41 } 42 42 43 function test_wp_parse_args_defaults() {43 public function test_wp_parse_args_defaults() { 44 44 $x = new MockClass; 45 45 $x->_baba = 5; … … 67 67 } 68 68 69 function test_wp_parse_args_other() {69 public function test_wp_parse_args_other() { 70 70 $b = true; 71 71 wp_parse_str( $b, $s ); … … 79 79 * @ticket 30753 80 80 */ 81 function test_wp_parse_args_boolean_strings() {81 public function test_wp_parse_args_boolean_strings() { 82 82 $args = wp_parse_args( 'foo=false&bar=true' ); 83 83 $this->assertIsString( $args['foo'] ); … … 88 88 * @ticket 35972 89 89 */ 90 function test_bool_from_yn() {90 public function test_bool_from_yn() { 91 91 $this->assertTrue( bool_from_yn( 'Y' ) ); 92 92 $this->assertTrue( bool_from_yn( 'y' ) ); … … 94 94 } 95 95 96 function test_path_is_absolute() {96 public function test_path_is_absolute() { 97 97 $absolute_paths = array( 98 98 '/', … … 112 112 } 113 113 114 function test_path_is_not_absolute() {114 public function test_path_is_not_absolute() { 115 115 $relative_paths = array( 116 116 '', … … 136 136 * @dataProvider data_wp_normalize_path 137 137 */ 138 function test_wp_normalize_path( $path, $expected ) {138 public function test_wp_normalize_path( $path, $expected ) { 139 139 $this->assertSame( $expected, wp_normalize_path( $path ) ); 140 140 } 141 141 142 function data_wp_normalize_path() {142 public function data_wp_normalize_path() { 143 143 return array( 144 144 // Windows paths. … … 164 164 } 165 165 166 function test_wp_unique_filename() {166 public function test_wp_unique_filename() { 167 167 168 168 $testdir = DIR_TESTDATA . '/images/'; … … 208 208 * @ticket 42437 209 209 */ 210 function test_unique_filename_with_dimension_like_filename() {210 public function test_unique_filename_with_dimension_like_filename() { 211 211 $testdir = DIR_TESTDATA . '/images/'; 212 212 … … 225 225 226 226 // Callback to patch "basedir" when used in `wp_unique_filename()`. 227 function upload_dir_patch_basedir( $upload_dir ) {227 public function upload_dir_patch_basedir( $upload_dir ) { 228 228 $upload_dir['basedir'] = DIR_TESTDATA . '/images/'; 229 229 return $upload_dir; … … 233 233 * @ticket 53668 234 234 */ 235 function test_wp_unique_filename_with_additional_image_extension() {235 public function test_wp_unique_filename_with_additional_image_extension() { 236 236 $testdir = DIR_TESTDATA . '/images/'; 237 237 … … 315 315 * @dataProvider data_is_not_serialized 316 316 */ 317 function test_maybe_serialize( $value ) {317 public function test_maybe_serialize( $value ) { 318 318 if ( is_array( $value ) || is_object( $value ) ) { 319 319 $expected = serialize( $value ); … … 328 328 * @dataProvider data_is_serialized 329 329 */ 330 function test_maybe_serialize_with_double_serialization( $value ) {330 public function test_maybe_serialize_with_double_serialization( $value ) { 331 331 $expected = serialize( $value ); 332 332 … … 338 338 * @dataProvider data_is_not_serialized 339 339 */ 340 function test_maybe_unserialize( $value, $is_serialized ) {340 public function test_maybe_unserialize( $value, $is_serialized ) { 341 341 if ( $is_serialized ) { 342 342 $expected = unserialize( trim( $value ) ); … … 356 356 * @dataProvider data_is_not_serialized 357 357 */ 358 function test_is_serialized( $value, $expected ) {358 public function test_is_serialized( $value, $expected ) { 359 359 $this->assertSame( $expected, is_serialized( $value ) ); 360 360 } … … 363 363 * @dataProvider data_serialize_deserialize_objects 364 364 */ 365 function test_deserialize_request_utility_filtered_iterator_objects( $value ) {365 public function test_deserialize_request_utility_filtered_iterator_objects( $value ) { 366 366 $serialized = maybe_serialize( $value ); 367 367 if ( get_class( $value ) === 'Requests_Utility_FilteredIterator' ) { … … 376 376 } 377 377 378 function data_serialize_deserialize_objects() {378 public function data_serialize_deserialize_objects() { 379 379 return array( 380 380 array( new Requests_Utility_FilteredIterator( array( 1 ), 'md5' ) ), … … 384 384 } 385 385 386 function data_is_serialized() {386 public function data_is_serialized() { 387 387 return array( 388 388 array( serialize( null ), true ), … … 410 410 } 411 411 412 function data_is_not_serialized() {412 public function data_is_not_serialized() { 413 413 return array( 414 414 array( null, false ), … … 440 440 * @dataProvider data_is_serialized_should_return_true_for_large_floats 441 441 */ 442 function test_is_serialized_should_return_true_for_large_floats( $value ) {442 public function test_is_serialized_should_return_true_for_large_floats( $value ) { 443 443 $this->assertTrue( is_serialized( $value ) ); 444 444 } 445 445 446 function data_is_serialized_should_return_true_for_large_floats() {446 public function data_is_serialized_should_return_true_for_large_floats() { 447 447 return array( 448 448 array( serialize( 1.7976931348623157E+308 ) ), … … 454 454 * @ticket 17375 455 455 */ 456 function test_no_new_serializable_types() {456 public function test_no_new_serializable_types() { 457 457 $this->assertFalse( is_serialized( 'C:16:"Serialized_Class":6:{a:0:{}}' ) ); 458 458 } … … 461 461 * @group add_query_arg 462 462 */ 463 function test_add_query_arg() {463 public function test_add_query_arg() { 464 464 $old_req_uri = $_SERVER['REQUEST_URI']; 465 465 … … 649 649 * @ticket 31306 650 650 */ 651 function test_add_query_arg_numeric_keys() {651 public function test_add_query_arg_numeric_keys() { 652 652 $url = add_query_arg( array( 'foo' => 'bar' ), '1=1' ); 653 653 $this->assertSame( '1=1&foo=bar', $url ); … … 669 669 * @ticket 21594 670 670 */ 671 function test_get_allowed_mime_types() {671 public function test_get_allowed_mime_types() { 672 672 $mimes = get_allowed_mime_types(); 673 673 … … 689 689 * @ticket 21594 690 690 */ 691 function test_wp_get_mime_types() {691 public function test_wp_get_mime_types() { 692 692 $mimes = wp_get_mime_types(); 693 693 … … 721 721 * @ticket 23688 722 722 */ 723 function test_canonical_charset() {723 public function test_canonical_charset() { 724 724 $orig_blog_charset = get_option( 'blog_charset' ); 725 725 … … 759 759 * @dataProvider data_wp_parse_list 760 760 */ 761 function test_wp_parse_list( $expected, $actual ) {761 public function test_wp_parse_list( $expected, $actual ) { 762 762 $this->assertSame( $expected, array_values( wp_parse_list( $actual ) ) ); 763 763 } 764 764 765 function data_wp_parse_list() {765 public function data_wp_parse_list() { 766 766 return array( 767 767 array( array( '1', '2', '3', '4' ), '1,2,3,4' ), … … 782 782 * @dataProvider data_wp_parse_id_list 783 783 */ 784 function test_wp_parse_id_list( $expected, $actual ) {784 public function test_wp_parse_id_list( $expected, $actual ) { 785 785 $this->assertSame( $expected, array_values( wp_parse_id_list( $actual ) ) ); 786 786 } 787 787 788 function data_wp_parse_id_list() {788 public function data_wp_parse_id_list() { 789 789 return array( 790 790 array( array( 1, 2, 3, 4 ), '1,2,3,4' ), … … 801 801 * @dataProvider data_wp_parse_slug_list 802 802 */ 803 function test_wp_parse_slug_list( $expected, $actual ) {803 public function test_wp_parse_slug_list( $expected, $actual ) { 804 804 $this->assertSame( $expected, array_values( wp_parse_slug_list( $actual ) ) ); 805 805 } 806 806 807 function data_wp_parse_slug_list() {807 public function data_wp_parse_slug_list() { 808 808 return array( 809 809 array( array( 'apple', 'banana', 'carrot', 'dog' ), 'apple,banana,carrot,dog' ), … … 817 817 * @dataProvider data_device_can_upload 818 818 */ 819 function test_device_can_upload( $user_agent, $expected ) {819 public function test_device_can_upload( $user_agent, $expected ) { 820 820 $_SERVER['HTTP_USER_AGENT'] = $user_agent; 821 821 $actual = _device_can_upload(); … … 824 824 } 825 825 826 function data_device_can_upload() {826 public function data_device_can_upload() { 827 827 return array( 828 828 // iPhone iOS 5.0.1, Safari 5.1. … … 877 877 * @ticket 9064 878 878 */ 879 function test_wp_extract_urls() {879 public function test_wp_extract_urls() { 880 880 $original_urls = array( 881 881 'http://woo.com/1,2,3,4,5,6/-1-2-3-4-/woo.html', … … 1044 1044 * @ticket 28786 1045 1045 */ 1046 function test_wp_json_encode() {1046 public function test_wp_json_encode() { 1047 1047 $this->assertSame( wp_json_encode( 'a' ), '"a"' ); 1048 1048 } … … 1051 1051 * @ticket 28786 1052 1052 */ 1053 function test_wp_json_encode_utf8() {1053 public function test_wp_json_encode_utf8() { 1054 1054 $this->assertSame( wp_json_encode( '这' ), '"\u8fd9"' ); 1055 1055 } … … 1059 1059 * @requires function mb_detect_order 1060 1060 */ 1061 function test_wp_json_encode_non_utf8() {1061 public function test_wp_json_encode_non_utf8() { 1062 1062 $charsets = mb_detect_order(); 1063 1063 $old_charsets = $charsets; … … 1081 1081 * @requires function mb_detect_order 1082 1082 */ 1083 function test_wp_json_encode_non_utf8_in_array() {1083 public function test_wp_json_encode_non_utf8_in_array() { 1084 1084 $charsets = mb_detect_order(); 1085 1085 $old_charsets = $charsets; … … 1102 1102 * @ticket 28786 1103 1103 */ 1104 function test_wp_json_encode_array() {1104 public function test_wp_json_encode_array() { 1105 1105 $this->assertSame( wp_json_encode( array( 'a' ) ), '["a"]' ); 1106 1106 } … … 1109 1109 * @ticket 28786 1110 1110 */ 1111 function test_wp_json_encode_object() {1111 public function test_wp_json_encode_object() { 1112 1112 $object = new stdClass; 1113 1113 $object->a = 'b'; … … 1118 1118 * @ticket 28786 1119 1119 */ 1120 function test_wp_json_encode_depth() {1120 public function test_wp_json_encode_depth() { 1121 1121 $data = array( array( array( 1, 2, 3 ) ) ); 1122 1122 $json = wp_json_encode( $data, 0, 1 ); … … 1131 1131 * @ticket 53238 1132 1132 */ 1133 function test_wp_json_file_decode() {1133 public function test_wp_json_file_decode() { 1134 1134 $result = wp_json_file_decode( 1135 1135 DIR_TESTDATA . '/blocks/notice/block.json' … … 1143 1143 * @ticket 53238 1144 1144 */ 1145 function test_wp_json_file_decode_associative_array() {1145 public function test_wp_json_file_decode_associative_array() { 1146 1146 $result = wp_json_file_decode( 1147 1147 DIR_TESTDATA . '/blocks/notice/block.json', … … 1157 1157 * @dataProvider datetime_provider 1158 1158 */ 1159 function test_mysql_to_rfc3339( $expected, $actual ) {1159 public function test_mysql_to_rfc3339( $expected, $actual ) { 1160 1160 $date_return = mysql_to_rfc3339( $actual ); 1161 1161 … … 1166 1166 } 1167 1167 1168 function datetime_provider() {1168 public function datetime_provider() { 1169 1169 return array( 1170 1170 array( '2016-03-15T18:54:46', '15-03-2016 18:54:46' ), … … 1219 1219 * @ticket 32075 1220 1220 */ 1221 function test_wp_raise_memory_limit() {1221 public function test_wp_raise_memory_limit() { 1222 1222 if ( -1 !== WP_MAX_MEMORY_LIMIT ) { 1223 1223 $this->markTestSkipped( 'WP_MAX_MEMORY_LIMIT should be set to -1.' ); … … 1239 1239 * @ticket 38164 1240 1240 */ 1241 function test_wp_generate_uuid4() {1241 public function test_wp_generate_uuid4() { 1242 1242 $uuids = array(); 1243 1243 for ( $i = 0; $i < 20; $i += 1 ) { … … 1257 1257 * @ticket 39778 1258 1258 */ 1259 function test_wp_is_valid_uuid() {1259 public function test_wp_is_valid_uuid() { 1260 1260 $uuids_v4 = array( 1261 1261 '27fe2421-780c-44c5-b39b-fff753092b55', … … 1307 1307 * @ticket 44883 1308 1308 */ 1309 function test_wp_unique_id() {1309 public function test_wp_unique_id() { 1310 1310 1311 1311 // Test without prefix. … … 1331 1331 /** 1332 1332 * @ticket 40017 1333 * @dataProvider _wp_get_image_mime1333 * @dataProvider wp_get_image_mime 1334 1334 */ 1335 1335 public function test_wp_get_image_mime( $file, $expected ) { … … 1366 1366 /** 1367 1367 * @ticket 39550 1368 * @dataProvider _wp_check_filetype_and_ext_data1368 * @dataProvider wp_check_filetype_and_ext_data 1369 1369 * @requires extension fileinfo 1370 1370 */ 1371 function test_wp_check_filetype_and_ext( $file, $filename, $expected ) {1371 public function test_wp_check_filetype_and_ext( $file, $filename, $expected ) { 1372 1372 $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) ); 1373 1373 } … … 1378 1378 * @requires extension fileinfo 1379 1379 */ 1380 function test_wp_check_filetype_and_ext_with_filtered_svg() {1380 public function test_wp_check_filetype_and_ext_with_filtered_svg() { 1381 1381 $file = DIR_TESTDATA . '/uploads/video-play.svg'; 1382 1382 $filename = 'video-play.svg'; … … 1388 1388 ); 1389 1389 1390 add_filter( 'upload_mimes', array( $this, ' _filter_mime_types_svg' ) );1390 add_filter( 'upload_mimes', array( $this, 'filter_mime_types_svg' ) ); 1391 1391 $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) ); 1392 1392 1393 1393 // Cleanup. 1394 remove_filter( 'upload_mimes', array( $this, ' _test_add_mime_types_svg' ) );1394 remove_filter( 'upload_mimes', array( $this, 'filter_mime_types_svg' ) ); 1395 1395 } 1396 1396 … … 1400 1400 * @requires extension fileinfo 1401 1401 */ 1402 function test_wp_check_filetype_and_ext_with_filtered_woff() {1402 public function test_wp_check_filetype_and_ext_with_filtered_woff() { 1403 1403 $file = DIR_TESTDATA . '/uploads/dashicons.woff'; 1404 1404 $filename = 'dashicons.woff'; … … 1410 1410 ); 1411 1411 1412 add_filter( 'upload_mimes', array( $this, ' _filter_mime_types_woff' ) );1412 add_filter( 'upload_mimes', array( $this, 'filter_mime_types_woff' ) ); 1413 1413 $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) ); 1414 1414 1415 1415 // Cleanup. 1416 remove_filter( 'upload_mimes', array( $this, ' _test_add_mime_types_woff' ) );1417 } 1418 1419 public function _filter_mime_types_svg( $mimes ) {1416 remove_filter( 'upload_mimes', array( $this, 'filter_mime_types_woff' ) ); 1417 } 1418 1419 public function filter_mime_types_svg( $mimes ) { 1420 1420 $mimes['svg'] = 'image/svg+xml'; 1421 1421 return $mimes; 1422 1422 } 1423 1423 1424 public function _filter_mime_types_woff( $mimes ) {1424 public function filter_mime_types_woff( $mimes ) { 1425 1425 $mimes['woff'] = 'application/font-woff'; 1426 1426 return $mimes; … … 1430 1430 * Data provider for test_wp_get_image_mime(). 1431 1431 */ 1432 public function _wp_get_image_mime() {1432 public function wp_get_image_mime() { 1433 1433 $data = array( 1434 1434 // Standard JPEG. … … 1585 1585 } 1586 1586 1587 public function _wp_check_filetype_and_ext_data() {1587 public function wp_check_filetype_and_ext_data() { 1588 1588 $data = array( 1589 1589 // Standard image.
Note: See TracChangeset
for help on using the changeset viewer.