Changeset 48937 for trunk/tests/phpunit/tests/functions.php
- Timestamp:
- 09/02/2020 12:35:36 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/functions.php
r48604 r48937 10 10 $x->yZ = 'baba'; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 11 11 $x->a = array( 5, 111, 'x' ); 12 $this->assert Equals(12 $this->assertSame( 13 13 array( 14 14 '_baba' => 5, … … 19 19 ); 20 20 $y = new MockClass; 21 $this->assert Equals( array(), wp_parse_args( $y ) );21 $this->assertSame( array(), wp_parse_args( $y ) ); 22 22 } 23 23 … … 25 25 // Arrays. 26 26 $a = array(); 27 $this->assert Equals( array(), wp_parse_args( $a ) );27 $this->assertSame( array(), wp_parse_args( $a ) ); 28 28 $b = array( 29 29 '_baba' => 5, … … 31 31 'a' => array( 5, 111, 'x' ), 32 32 ); 33 $this->assert Equals(33 $this->assertSame( 34 34 array( 35 35 '_baba' => 5, … … 47 47 $x->a = array( 5, 111, 'x' ); 48 48 $d = array( 'pu' => 'bu' ); 49 $this->assert Equals(49 $this->assertSame( 50 50 array( 51 51 'pu' => 'bu', … … 57 57 ); 58 58 $e = array( '_baba' => 6 ); 59 $this->assert Equals(59 $this->assertSame( 60 60 array( 61 61 '_baba' => 5, … … 70 70 $b = true; 71 71 wp_parse_str( $b, $s ); 72 $this->assert Equals( $s, wp_parse_args( $b ) );72 $this->assertSame( $s, wp_parse_args( $b ) ); 73 73 $q = 'x=5&_baba=dudu&'; 74 74 wp_parse_str( $q, $ss ); 75 $this->assert Equals( $ss, wp_parse_args( $q ) );75 $this->assertSame( $ss, wp_parse_args( $q ) ); 76 76 } 77 77 … … 137 137 */ 138 138 function test_wp_normalize_path( $path, $expected ) { 139 $this->assert Equals( $expected, wp_normalize_path( $path ) );139 $this->assertSame( $expected, wp_normalize_path( $path ) ); 140 140 } 141 141 … … 169 169 170 170 // Sanity check. 171 $this->assert Equals( 'abcdefg.png', wp_unique_filename( $testdir, 'abcdefg.png' ), 'Sanitiy check failed' );171 $this->assertSame( 'abcdefg.png', wp_unique_filename( $testdir, 'abcdefg.png' ), 'Sanitiy check failed' ); 172 172 173 173 // Check number is appended for file already exists. 174 174 $this->assertFileExists( $testdir . 'test-image.png', 'Test image does not exist' ); 175 $this->assert Equals( 'test-image-1.png', wp_unique_filename( $testdir, 'test-image.png' ), 'Number not appended correctly' );175 $this->assertSame( 'test-image-1.png', wp_unique_filename( $testdir, 'test-image.png' ), 'Number not appended correctly' ); 176 176 $this->assertFileNotExists( $testdir . 'test-image-1.png' ); 177 177 178 178 // Check special chars. 179 $this->assert Equals( 'testtest-image.png', wp_unique_filename( $testdir, 'testtést-imagé.png' ), 'Filename with special chars failed' );179 $this->assertSame( 'testtest-image.png', wp_unique_filename( $testdir, 'testtést-imagé.png' ), 'Filename with special chars failed' ); 180 180 181 181 // Check special chars with potential conflicting name. 182 $this->assert Equals( 'test-image-1.png', wp_unique_filename( $testdir, 'tést-imagé.png' ), 'Filename with special chars failed' );182 $this->assertSame( 'test-image-1.png', wp_unique_filename( $testdir, 'tést-imagé.png' ), 'Filename with special chars failed' ); 183 183 184 184 // Check with single quotes in name (somehow). 185 $this->assert Equals( 'abcdefgh.png', wp_unique_filename( $testdir, "abcdefg'h.png" ), 'File with quote failed' );185 $this->assertSame( 'abcdefgh.png', wp_unique_filename( $testdir, "abcdefg'h.png" ), 'File with quote failed' ); 186 186 187 187 // Check with double quotes in name (somehow). 188 $this->assert Equals( 'abcdefgh.png', wp_unique_filename( $testdir, 'abcdefg"h.png' ), 'File with quote failed' );188 $this->assertSame( 'abcdefgh.png', wp_unique_filename( $testdir, 'abcdefg"h.png' ), 'File with quote failed' ); 189 189 190 190 // Test crazy name (useful for regression tests). 191 $this->assert Equals( '12af34567890@..^_qwerty-fghjkl-zx.png', wp_unique_filename( $testdir, '12%af34567890#~!@#$..%^&*()|_+qwerty fgh`jkl zx<>?:"{}[]="\'/?.png' ), 'Failed crazy file name' );191 $this->assertSame( '12af34567890@..^_qwerty-fghjkl-zx.png', wp_unique_filename( $testdir, '12%af34567890#~!@#$..%^&*()|_+qwerty fgh`jkl zx<>?:"{}[]="\'/?.png' ), 'Failed crazy file name' ); 192 192 193 193 // Test slashes in names. 194 $this->assert Equals( 'abcdefg.png', wp_unique_filename( $testdir, 'abcde\fg.png' ), 'Slash not removed' );195 $this->assert Equals( 'abcdefg.png', wp_unique_filename( $testdir, 'abcde\\fg.png' ), 'Double slashed not removed' );196 $this->assert Equals( 'abcdefg.png', wp_unique_filename( $testdir, 'abcde\\\fg.png' ), 'Tripple slashed not removed' );194 $this->assertSame( 'abcdefg.png', wp_unique_filename( $testdir, 'abcde\fg.png' ), 'Slash not removed' ); 195 $this->assertSame( 'abcdefg.png', wp_unique_filename( $testdir, 'abcde\\fg.png' ), 'Double slashed not removed' ); 196 $this->assertSame( 'abcdefg.png', wp_unique_filename( $testdir, 'abcde\\\fg.png' ), 'Tripple slashed not removed' ); 197 197 } 198 198 … … 206 206 207 207 // Test collision with "dimension-like" original filename. 208 $this->assert Equals( 'one-blue-pixel-100x100-1.png', wp_unique_filename( $testdir, 'one-blue-pixel-100x100.png' ) );208 $this->assertSame( 'one-blue-pixel-100x100-1.png', wp_unique_filename( $testdir, 'one-blue-pixel-100x100.png' ) ); 209 209 // Test collision with existing sub-size filename. 210 210 // Existing files: one-blue-pixel-100x100.png, one-blue-pixel-1-100x100.png. 211 $this->assert Equals( 'one-blue-pixel-2.png', wp_unique_filename( $testdir, 'one-blue-pixel.png' ) );211 $this->assertSame( 'one-blue-pixel-2.png', wp_unique_filename( $testdir, 'one-blue-pixel.png' ) ); 212 212 // Same as above with upper case extension. 213 $this->assert Equals( 'one-blue-pixel-2.png', wp_unique_filename( $testdir, 'one-blue-pixel.PNG' ) );213 $this->assertSame( 'one-blue-pixel-2.png', wp_unique_filename( $testdir, 'one-blue-pixel.PNG' ) ); 214 214 215 215 remove_filter( 'upload_dir', array( $this, 'upload_dir_patch_basedir' ) ); … … 369 369 $_SERVER['REQUEST_URI'] = 'nothing'; 370 370 371 $this->assert Equals( "$url?foo=1", add_query_arg( 'foo', '1', $url ) );372 $this->assert Equals( "$url?foo=1", add_query_arg( array( 'foo' => '1' ), $url ) );373 $this->assert Equals(371 $this->assertSame( "$url?foo=1", add_query_arg( 'foo', '1', $url ) ); 372 $this->assertSame( "$url?foo=1", add_query_arg( array( 'foo' => '1' ), $url ) ); 373 $this->assertSame( 374 374 "$url?foo=2", 375 375 add_query_arg( … … 381 381 ) 382 382 ); 383 $this->assert Equals(383 $this->assertSame( 384 384 "$url?foo=1&bar=2", 385 385 add_query_arg( … … 394 394 $_SERVER['REQUEST_URI'] = $url; 395 395 396 $this->assert Equals( "$url?foo=1", add_query_arg( 'foo', '1' ) );397 $this->assert Equals( "$url?foo=1", add_query_arg( array( 'foo' => '1' ) ) );398 $this->assert Equals(396 $this->assertSame( "$url?foo=1", add_query_arg( 'foo', '1' ) ); 397 $this->assertSame( "$url?foo=1", add_query_arg( array( 'foo' => '1' ) ) ); 398 $this->assertSame( 399 399 "$url?foo=2", 400 400 add_query_arg( … … 405 405 ) 406 406 ); 407 $this->assert Equals(407 $this->assertSame( 408 408 "$url?foo=1&bar=2", 409 409 add_query_arg( … … 420 420 $url = str_replace( '#frag', '', $frag_url ); 421 421 422 $this->assert Equals( "$url?foo=1#frag", add_query_arg( 'foo', '1', $frag_url ) );423 $this->assert Equals( "$url?foo=1#frag", add_query_arg( array( 'foo' => '1' ), $frag_url ) );424 $this->assert Equals(422 $this->assertSame( "$url?foo=1#frag", add_query_arg( 'foo', '1', $frag_url ) ); 423 $this->assertSame( "$url?foo=1#frag", add_query_arg( array( 'foo' => '1' ), $frag_url ) ); 424 $this->assertSame( 425 425 "$url?foo=2#frag", 426 426 add_query_arg( … … 432 432 ) 433 433 ); 434 $this->assert Equals(434 $this->assertSame( 435 435 "$url?foo=1&bar=2#frag", 436 436 add_query_arg( … … 445 445 $_SERVER['REQUEST_URI'] = $frag_url; 446 446 447 $this->assert Equals( "$url?foo=1#frag", add_query_arg( 'foo', '1' ) );448 $this->assert Equals( "$url?foo=1#frag", add_query_arg( array( 'foo' => '1' ) ) );449 $this->assert Equals(447 $this->assertSame( "$url?foo=1#frag", add_query_arg( 'foo', '1' ) ); 448 $this->assertSame( "$url?foo=1#frag", add_query_arg( array( 'foo' => '1' ) ) ); 449 $this->assertSame( 450 450 "$url?foo=2#frag", 451 451 add_query_arg( … … 456 456 ) 457 457 ); 458 $this->assert Equals(458 $this->assertSame( 459 459 "$url?foo=1&bar=2#frag", 460 460 add_query_arg( … … 482 482 $_SERVER['REQUEST_URI'] = 'nothing'; 483 483 484 $this->assert Equals( "$url&foo=1", add_query_arg( 'foo', '1', $url ) );485 $this->assert Equals( "$url&foo=1", add_query_arg( array( 'foo' => '1' ), $url ) );486 $this->assert Equals(484 $this->assertSame( "$url&foo=1", add_query_arg( 'foo', '1', $url ) ); 485 $this->assertSame( "$url&foo=1", add_query_arg( array( 'foo' => '1' ), $url ) ); 486 $this->assertSame( 487 487 "$url&foo=2", 488 488 add_query_arg( … … 494 494 ) 495 495 ); 496 $this->assert Equals(496 $this->assertSame( 497 497 "$url&foo=1&bar=2", 498 498 add_query_arg( … … 507 507 $_SERVER['REQUEST_URI'] = $url; 508 508 509 $this->assert Equals( "$url&foo=1", add_query_arg( 'foo', '1' ) );510 $this->assert Equals( "$url&foo=1", add_query_arg( array( 'foo' => '1' ) ) );511 $this->assert Equals(509 $this->assertSame( "$url&foo=1", add_query_arg( 'foo', '1' ) ); 510 $this->assertSame( "$url&foo=1", add_query_arg( array( 'foo' => '1' ) ) ); 511 $this->assertSame( 512 512 "$url&foo=2", 513 513 add_query_arg( … … 518 518 ) 519 519 ); 520 $this->assert Equals(520 $this->assertSame( 521 521 "$url&foo=1&bar=2", 522 522 add_query_arg( … … 537 537 function test_add_query_arg_numeric_keys() { 538 538 $url = add_query_arg( array( 'foo' => 'bar' ), '1=1' ); 539 $this->assert Equals( '1=1&foo=bar', $url );539 $this->assertSame( '1=1&foo=bar', $url ); 540 540 541 541 $url = add_query_arg( … … 546 546 '1=1' 547 547 ); 548 $this->assert Equals( '1=2&foo=bar', $url );548 $this->assertSame( '1=2&foo=bar', $url ); 549 549 550 550 $url = add_query_arg( array( '1' => '2' ), 'foo=bar' ); 551 $this->assert Equals( 'foo=bar&1=2', $url );551 $this->assertSame( 'foo=bar&1=2', $url ); 552 552 } 553 553 … … 601 601 $this->assertInternalType( 'array', $mimes2 ); 602 602 $this->assertNotEmpty( $mimes2 ); 603 $this->assert Equals( $mimes2, $mimes );603 $this->assertSame( $mimes2, $mimes ); 604 604 } 605 605 … … 611 611 612 612 update_option( 'blog_charset', 'utf8' ); 613 $this->assert Equals( 'UTF-8', get_option( 'blog_charset' ) );613 $this->assertSame( 'UTF-8', get_option( 'blog_charset' ) ); 614 614 615 615 update_option( 'blog_charset', 'utf-8' ); 616 $this->assert Equals( 'UTF-8', get_option( 'blog_charset' ) );616 $this->assertSame( 'UTF-8', get_option( 'blog_charset' ) ); 617 617 618 618 update_option( 'blog_charset', 'UTF8' ); 619 $this->assert Equals( 'UTF-8', get_option( 'blog_charset' ) );619 $this->assertSame( 'UTF-8', get_option( 'blog_charset' ) ); 620 620 621 621 update_option( 'blog_charset', 'UTF-8' ); 622 $this->assert Equals( 'UTF-8', get_option( 'blog_charset' ) );622 $this->assertSame( 'UTF-8', get_option( 'blog_charset' ) ); 623 623 624 624 update_option( 'blog_charset', 'ISO-8859-1' ); 625 $this->assert Equals( 'ISO-8859-1', get_option( 'blog_charset' ) );625 $this->assertSame( 'ISO-8859-1', get_option( 'blog_charset' ) ); 626 626 627 627 update_option( 'blog_charset', 'ISO8859-1' ); 628 $this->assert Equals( 'ISO-8859-1', get_option( 'blog_charset' ) );628 $this->assertSame( 'ISO-8859-1', get_option( 'blog_charset' ) ); 629 629 630 630 update_option( 'blog_charset', 'iso8859-1' ); 631 $this->assert Equals( 'ISO-8859-1', get_option( 'blog_charset' ) );631 $this->assertSame( 'ISO-8859-1', get_option( 'blog_charset' ) ); 632 632 633 633 update_option( 'blog_charset', 'iso-8859-1' ); 634 $this->assert Equals( 'ISO-8859-1', get_option( 'blog_charset' ) );634 $this->assertSame( 'ISO-8859-1', get_option( 'blog_charset' ) ); 635 635 636 636 // Arbitrary strings are passed through. 637 637 update_option( 'blog_charset', 'foobarbaz' ); 638 $this->assert Equals( 'foobarbaz', get_option( 'blog_charset' ) );638 $this->assertSame( 'foobarbaz', get_option( 'blog_charset' ) ); 639 639 640 640 update_option( 'blog_charset', $orig_blog_charset ); … … 707 707 $actual = _device_can_upload(); 708 708 unset( $_SERVER['HTTP_USER_AGENT'] ); 709 $this->assert Equals( $expected, $actual );709 $this->assertSame( $expected, $actual ); 710 710 } 711 711 … … 889 889 $this->assertInternalType( 'array', $urls ); 890 890 $this->assertCount( count( $original_urls ), $urls ); 891 $this->assert Equals( $original_urls, $urls );891 $this->assertSame( $original_urls, $urls ); 892 892 893 893 $exploded = array_values( array_filter( array_map( 'trim', explode( "\n", $blob ) ) ) ); … … 895 895 $decoded = array_map( 'html_entity_decode', $exploded ); 896 896 897 $this->assert Equals( $decoded, $urls );898 $this->assert Equals( $original_urls, $decoded );897 $this->assertSame( $decoded, $urls ); 898 $this->assertSame( $original_urls, $decoded ); 899 899 900 900 $blob = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor … … 910 910 $this->assertInternalType( 'array', $urls ); 911 911 $this->assertCount( 8, $urls ); 912 $this->assert Equals( array_slice( $original_urls, 0, 8 ), $urls );912 $this->assertSame( array_slice( $original_urls, 0, 8 ), $urls ); 913 913 914 914 $blob = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor … … 924 924 $this->assertInternalType( 'array', $urls ); 925 925 $this->assertCount( 8, $urls ); 926 $this->assert Equals( array_slice( $original_urls, 0, 8 ), $urls );926 $this->assertSame( array_slice( $original_urls, 0, 8 ), $urls ); 927 927 } 928 928 … … 931 931 */ 932 932 function test_wp_json_encode() { 933 $this->assert Equals( wp_json_encode( 'a' ), '"a"' );933 $this->assertSame( wp_json_encode( 'a' ), '"a"' ); 934 934 } 935 935 … … 938 938 */ 939 939 function test_wp_json_encode_utf8() { 940 $this->assert Equals( wp_json_encode( '这' ), '"\u8fd9"' );940 $this->assertSame( wp_json_encode( '这' ), '"\u8fd9"' ); 941 941 } 942 942 … … 959 959 $utf8 = mb_convert_encoding( $eucjp, 'UTF-8', 'EUC-JP' ); 960 960 961 $this->assert Equals( 'aあb', $utf8 );962 963 $this->assert Equals( '"a\u3042b"', wp_json_encode( $eucjp ) );961 $this->assertSame( 'aあb', $utf8 ); 962 963 $this->assertSame( '"a\u3042b"', wp_json_encode( $eucjp ) ); 964 964 965 965 mb_detect_order( $old_charsets ); … … 984 984 $utf8 = mb_convert_encoding( $eucjp, 'UTF-8', 'EUC-JP' ); 985 985 986 $this->assert Equals( 'aあb', $utf8 );987 988 $this->assert Equals( '["c","a\u3042b"]', wp_json_encode( array( 'c', $eucjp ) ) );986 $this->assertSame( 'aあb', $utf8 ); 987 988 $this->assertSame( '["c","a\u3042b"]', wp_json_encode( array( 'c', $eucjp ) ) ); 989 989 990 990 mb_detect_order( $old_charsets ); … … 995 995 */ 996 996 function test_wp_json_encode_array() { 997 $this->assert Equals( wp_json_encode( array( 'a' ) ), '["a"]' );997 $this->assertSame( wp_json_encode( array( 'a' ) ), '["a"]' ); 998 998 } 999 999 … … 1004 1004 $object = new stdClass; 1005 1005 $object->a = 'b'; 1006 $this->assert Equals( wp_json_encode( $object ), '{"a":"b"}' );1006 $this->assertSame( wp_json_encode( $object ), '{"a":"b"}' ); 1007 1007 } 1008 1008 … … 1029 1029 $this->assertTrue( is_string( $date_return ), 'The date return must be a string' ); 1030 1030 $this->assertNotEmpty( $date_return, 'The date return could not be an empty string' ); 1031 $this->assert Equals( $expected, $date_return, 'The date does not match' );1031 $this->assertSame( $expected, $date_return, 'The date does not match' ); 1032 1032 $this->assertEquals( new DateTime( $expected ), new DateTime( $date_return ), 'The date is not the same after the call method' ); 1033 1033 } … … 1070 1070 foreach ( $extensions as $type => $extension_list ) { 1071 1071 foreach ( $extension_list as $extension ) { 1072 $this->assert Equals( $type, wp_ext2type( $extension ) );1073 $this->assert Equals( $type, wp_ext2type( strtoupper( $extension ) ) );1072 $this->assertSame( $type, wp_ext2type( $extension ) ); 1073 $this->assertSame( $type, wp_ext2type( strtoupper( $extension ) ) ); 1074 1074 } 1075 1075 } … … 1096 1096 1097 1097 $this->assertSame( $ini_limit_before, $ini_limit_after ); 1098 $this->assert Same( false,$raised_limit );1098 $this->assertFalse( $raised_limit ); 1099 1099 $this->assertEquals( WP_MAX_MEMORY_LIMIT, $ini_limit_after ); 1100 1100 } … … 1115 1115 1116 1116 $unique_uuids = array_unique( $uuids ); 1117 $this->assert Equals( $uuids, $unique_uuids );1117 $this->assertSame( $uuids, $unique_uuids ); 1118 1118 } 1119 1119 … … 1184 1184 $ids[] = $id; 1185 1185 } 1186 $this->assert Equals( $ids, array_unique( $ids ) );1186 $this->assertSame( $ids, array_unique( $ids ) ); 1187 1187 1188 1188 // Test with prefix. … … 1193 1193 $ids[] = $id; 1194 1194 } 1195 $this->assert Equals( $ids, array_unique( $ids ) );1195 $this->assertSame( $ids, array_unique( $ids ) ); 1196 1196 } 1197 1197 … … 1205 1205 } 1206 1206 1207 $this->assert Equals( $expected, wp_get_image_mime( $file ) );1207 $this->assertSame( $expected, wp_get_image_mime( $file ) ); 1208 1208 } 1209 1209 … … 1217 1217 } 1218 1218 1219 $this->assert Equals( $expected, wp_check_filetype_and_ext( $file, $filename ) );1219 $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) ); 1220 1220 } 1221 1221 … … 1239 1239 1240 1240 add_filter( 'upload_mimes', array( $this, '_filter_mime_types_svg' ) ); 1241 $this->assert Equals( $expected, wp_check_filetype_and_ext( $file, $filename ) );1241 $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) ); 1242 1242 1243 1243 // Cleanup. … … 1264 1264 1265 1265 add_filter( 'upload_mimes', array( $this, '_filter_mime_types_woff' ) ); 1266 $this->assert Equals( $expected, wp_check_filetype_and_ext( $file, $filename ) );1266 $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) ); 1267 1267 1268 1268 // Cleanup.
Note: See TracChangeset
for help on using the changeset viewer.