mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
Code is Poetry.
WordPress' code just... wasn't. This is now dealt with. Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS. Fixes #41057. git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -8,27 +8,27 @@ class Tests_Compat extends WP_UnitTestCase {
|
||||
function utf8_string_lengths() {
|
||||
return array(
|
||||
// string, character_length, byte_length
|
||||
array( 'баба', 4, 8 ),
|
||||
array( 'баб', 3, 6 ),
|
||||
array( 'I am your б', 11, 12 ),
|
||||
array( '1111111111', 10, 10 ),
|
||||
array( '²²²²²²²²²²', 10, 20 ),
|
||||
array( '3333333333', 10, 30 ),
|
||||
array( '𝟜𝟜𝟜𝟜𝟜𝟜𝟜𝟜𝟜𝟜', 10, 40 ),
|
||||
array( '1²3𝟜1²3𝟜1²3𝟜', 12, 30 ),
|
||||
array( 'баба', 4, 8 ),
|
||||
array( 'баб', 3, 6 ),
|
||||
array( 'I am your б', 11, 12 ),
|
||||
array( '1111111111', 10, 10 ),
|
||||
array( '²²²²²²²²²²', 10, 20 ),
|
||||
array( '3333333333', 10, 30 ),
|
||||
array( '𝟜𝟜𝟜𝟜𝟜𝟜𝟜𝟜𝟜𝟜', 10, 40 ),
|
||||
array( '1²3𝟜1²3𝟜1²3𝟜', 12, 30 ),
|
||||
);
|
||||
}
|
||||
|
||||
function utf8_substrings() {
|
||||
return array(
|
||||
// string, start, length, character_substring, byte_substring
|
||||
array( 'баба', 0, 3, 'баб', "б\xD0" ),
|
||||
array( 'баба', 0, -1, 'баб', "баб\xD0" ),
|
||||
array( 'баба', 1, null, 'аба', "\xB1аба" ),
|
||||
array( 'баба', -3, null, 'аба', "\xB1а" ),
|
||||
array( 'баба', -3, 2, 'аб', "\xB1\xD0" ),
|
||||
array( 'баба', -1, 2, 'а', "\xB0" ),
|
||||
array( 'I am your баба', 0, 11, 'I am your б', "I am your \xD0" ),
|
||||
array( 'баба', 0, 3, 'баб', "б\xD0" ),
|
||||
array( 'баба', 0, -1, 'баб', "баб\xD0" ),
|
||||
array( 'баба', 1, null, 'аба', "\xB1аба" ),
|
||||
array( 'баба', -3, null, 'аба', "\xB1а" ),
|
||||
array( 'баба', -3, 2, 'аб', "\xB1\xD0" ),
|
||||
array( 'баба', -1, 2, 'а', "\xB0" ),
|
||||
array( 'I am your баба', 0, 11, 'I am your б', "I am your \xD0" ),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -78,27 +78,27 @@ class Tests_Compat extends WP_UnitTestCase {
|
||||
$this->assertEquals( $expected_byte_substring, _mb_substr( $string, $start, $length, '8bit' ) );
|
||||
}
|
||||
|
||||
function test_mb_substr_phpcore(){
|
||||
function test_mb_substr_phpcore() {
|
||||
/* https://github.com/php/php-src/blob/php-5.6.8/ext/mbstring/tests/mb_substr_basic.phpt */
|
||||
$string_ascii = 'ABCDEF';
|
||||
$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
|
||||
$string_mb = base64_decode( '5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=' );
|
||||
|
||||
$this->assertEquals( 'DEF', _mb_substr($string_ascii, 3) );
|
||||
$this->assertEquals( 'DEF', _mb_substr($string_ascii, 3, 5, 'ISO-8859-1') );
|
||||
$this->assertEquals( 'DEF', _mb_substr( $string_ascii, 3 ) );
|
||||
$this->assertEquals( 'DEF', _mb_substr( $string_ascii, 3, 5, 'ISO-8859-1' ) );
|
||||
|
||||
// specific latin-1 as that is the default the core php test opporates under
|
||||
$this->assertEquals( 'peacrOiqng==' , base64_encode( _mb_substr($string_mb, 2, 7, 'latin-1' ) ) );
|
||||
$this->assertEquals( '6Kqe44OG44Kt44K544OI44Gn44GZ', base64_encode( _mb_substr($string_mb, 2, 7, 'utf-8') ) );
|
||||
// specific latin-1 as that is the default the core php test opporates under
|
||||
$this->assertEquals( 'peacrOiqng==', base64_encode( _mb_substr( $string_mb, 2, 7, 'latin-1' ) ) );
|
||||
$this->assertEquals( '6Kqe44OG44Kt44K544OI44Gn44GZ', base64_encode( _mb_substr( $string_mb, 2, 7, 'utf-8' ) ) );
|
||||
|
||||
/* https://github.com/php/php-src/blob/php-5.6.8/ext/mbstring/tests/mb_substr_variation1.phpt */
|
||||
$start = 0;
|
||||
$length = 5;
|
||||
$start = 0;
|
||||
$length = 5;
|
||||
$unset_var = 10;
|
||||
unset ($unset_var);
|
||||
unset( $unset_var );
|
||||
$heredoc = <<<EOT
|
||||
hello world
|
||||
EOT;
|
||||
$inputs = array(
|
||||
$inputs = array(
|
||||
0,
|
||||
1,
|
||||
12345,
|
||||
@@ -110,18 +110,18 @@ EOT;
|
||||
12.3456789000E-10,
|
||||
.5,
|
||||
// null data
|
||||
NULL,
|
||||
null,
|
||||
null,
|
||||
// boolean data
|
||||
true,
|
||||
false,
|
||||
TRUE,
|
||||
FALSE,
|
||||
true,
|
||||
false,
|
||||
// empty data
|
||||
"",
|
||||
'',
|
||||
'',
|
||||
// string data
|
||||
"string",
|
||||
'string',
|
||||
'string',
|
||||
$heredoc,
|
||||
// object data
|
||||
@@ -131,52 +131,52 @@ EOT;
|
||||
// unset data
|
||||
@$unset_var,
|
||||
);
|
||||
$outputs = array(
|
||||
"0",
|
||||
"1",
|
||||
"12345",
|
||||
"-2345",
|
||||
"10.5",
|
||||
"-10.5",
|
||||
"12345",
|
||||
"1.234",
|
||||
"0.5",
|
||||
"",
|
||||
"",
|
||||
"1",
|
||||
"",
|
||||
"1",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"strin",
|
||||
"strin",
|
||||
"hello",
|
||||
"Class",
|
||||
"",
|
||||
"",
|
||||
$outputs = array(
|
||||
'0',
|
||||
'1',
|
||||
'12345',
|
||||
'-2345',
|
||||
'10.5',
|
||||
'-10.5',
|
||||
'12345',
|
||||
'1.234',
|
||||
'0.5',
|
||||
'',
|
||||
'',
|
||||
'1',
|
||||
'',
|
||||
'1',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'strin',
|
||||
'strin',
|
||||
'hello',
|
||||
'Class',
|
||||
'',
|
||||
'',
|
||||
);
|
||||
$iterator = 0;
|
||||
foreach($inputs as $input) {
|
||||
$this->assertEquals( $outputs[$iterator] , _mb_substr($input, $start, $length) );
|
||||
foreach ( $inputs as $input ) {
|
||||
$this->assertEquals( $outputs[ $iterator ], _mb_substr( $input, $start, $length ) );
|
||||
$iterator++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function test_hash_hmac_simple() {
|
||||
$this->assertEquals('140d1cb79fa12e2a31f32d35ad0a2723', _hash_hmac('md5', 'simple', 'key'));
|
||||
$this->assertEquals('993003b95758e0ac2eba451a4c5877eb1bb7b92a', _hash_hmac('sha1', 'simple', 'key'));
|
||||
$this->assertEquals( '140d1cb79fa12e2a31f32d35ad0a2723', _hash_hmac( 'md5', 'simple', 'key' ) );
|
||||
$this->assertEquals( '993003b95758e0ac2eba451a4c5877eb1bb7b92a', _hash_hmac( 'sha1', 'simple', 'key' ) );
|
||||
}
|
||||
|
||||
function test_hash_hmac_padding() {
|
||||
$this->assertEquals('3c1399103807cf12ec38228614416a8c', _hash_hmac('md5', 'simple', '65 character key 65 character key 65 character key 65 character k'));
|
||||
$this->assertEquals('4428826d20003e309d6c2a6515891370daf184ea', _hash_hmac('sha1', 'simple', '65 character key 65 character key 65 character key 65 character k'));
|
||||
$this->assertEquals( '3c1399103807cf12ec38228614416a8c', _hash_hmac( 'md5', 'simple', '65 character key 65 character key 65 character key 65 character k' ) );
|
||||
$this->assertEquals( '4428826d20003e309d6c2a6515891370daf184ea', _hash_hmac( 'sha1', 'simple', '65 character key 65 character key 65 character key 65 character k' ) );
|
||||
}
|
||||
|
||||
function test_hash_hmac_output() {
|
||||
$this->assertEquals(array( 1 => '140d1cb79fa12e2a31f32d35ad0a2723'), unpack('H32', _hash_hmac('md5', 'simple', 'key', true)));
|
||||
$this->assertEquals(array( 1 => '993003b95758e0ac2eba451a4c5877eb1bb7b92a'), unpack('H40', _hash_hmac('sha1', 'simple', 'key', true)));
|
||||
$this->assertEquals( array( 1 => '140d1cb79fa12e2a31f32d35ad0a2723' ), unpack( 'H32', _hash_hmac( 'md5', 'simple', 'key', true ) ) );
|
||||
$this->assertEquals( array( 1 => '993003b95758e0ac2eba451a4c5877eb1bb7b92a' ), unpack( 'H40', _hash_hmac( 'sha1', 'simple', 'key', true ) ) );
|
||||
}
|
||||
|
||||
function test_json_encode_decode() {
|
||||
@@ -188,9 +188,9 @@ EOT;
|
||||
}
|
||||
}
|
||||
|
||||
/* used in test_mb_substr_phpcore */
|
||||
/* used in test_mb_substr_phpcore */
|
||||
class classA {
|
||||
public function __toString() {
|
||||
return "Class A object";
|
||||
return 'Class A object';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user