Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 years ago)
Author:
pento
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/compat.php

    r42228 r42343  
    99        return array(
    1010            //                     string, character_length, byte_length
    11             array(                 'баба',                4,          8 ),
    12             array(                  'баб',                3,          6 ),
    13             array(          'I am your б',               11,          12 ),
    14             array(           '1111111111',               10,          10 ),
    15             array(           '²²²²²²²²²²',               10,          20 ),
    16             array( '3333333333',               10,          30 ),
    17             array(           '𝟜𝟜𝟜𝟜𝟜𝟜𝟜𝟜𝟜𝟜',               10,          40 ),
    18             array(      '1²3𝟜1²3𝟜1²3𝟜',               12,          30 ),
     11            array( 'баба', 4, 8 ),
     12            array( 'баб', 3, 6 ),
     13            array( 'I am your б', 11, 12 ),
     14            array( '1111111111', 10, 10 ),
     15            array( '²²²²²²²²²²', 10, 20 ),
     16            array( '3333333333', 10, 30 ),
     17            array( '𝟜𝟜𝟜𝟜𝟜𝟜𝟜𝟜𝟜𝟜', 10, 40 ),
     18            array( '1²3𝟜1²3𝟜1²3𝟜', 12, 30 ),
    1919        );
    2020    }
     
    2323        return array(
    2424            //               string, start, length, character_substring,   byte_substring
    25             array(           'баба',     0,      3,               'баб',          "б\xD0" ),
    26             array(           'баба',     0,     -1,               'баб',        "баб\xD0" ),
    27             array(           'баба',     1,   null,               'аба',        "\xB1аба" ),
    28             array(           'баба',    -3,   null,               'аба',          "\xB1а" ),
    29             array(           'баба',    -3,      2,                'аб',      "\xB1\xD0" ),
    30             array(           'баба',    -1,      2,                 'а',          "\xB0" ),
    31             array( 'I am your баба',     0,     11,      'I am your б', "I am your \xD0" ),
     25            array( 'баба', 0, 3, 'баб', "б\xD0" ),
     26            array( 'баба', 0, -1, 'баб', "баб\xD0" ),
     27            array( 'баба', 1, null, 'аба', "\xB1аба" ),
     28            array( 'баба', -3, null, 'аба', "\xB1а" ),
     29            array( 'баба', -3, 2, 'аб', "\xB1\xD0" ),
     30            array( 'баба', -1, 2, 'а', "\xB0" ),
     31            array( 'I am your баба', 0, 11, 'I am your б', "I am your \xD0" ),
    3232        );
    3333    }
     
    7979    }
    8080
    81     function test_mb_substr_phpcore(){
     81    function test_mb_substr_phpcore() {
    8282        /* https://github.com/php/php-src/blob/php-5.6.8/ext/mbstring/tests/mb_substr_basic.phpt */
    8383        $string_ascii = 'ABCDEF';
    84         $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
     84        $string_mb    = base64_decode( '5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=' );
    8585
    86         $this->assertEquals( 'DEF', _mb_substr($string_ascii, 3) );
    87         $this->assertEquals( 'DEF', _mb_substr($string_ascii, 3, 5, 'ISO-8859-1') );
     86        $this->assertEquals( 'DEF', _mb_substr( $string_ascii, 3 ) );
     87        $this->assertEquals( 'DEF', _mb_substr( $string_ascii, 3, 5, 'ISO-8859-1' ) );
    8888
    89         // specific latin-1 as that is the default the core php test opporates under   
    90         $this->assertEquals( 'peacrOiqng==' , base64_encode( _mb_substr($string_mb, 2, 7, 'latin-1' ) ) );
    91         $this->assertEquals( '6Kqe44OG44Kt44K544OI44Gn44GZ', base64_encode( _mb_substr($string_mb, 2, 7, 'utf-8') ) );
     89        // specific latin-1 as that is the default the core php test opporates under
     90        $this->assertEquals( 'peacrOiqng==', base64_encode( _mb_substr( $string_mb, 2, 7, 'latin-1' ) ) );
     91        $this->assertEquals( '6Kqe44OG44Kt44K544OI44Gn44GZ', base64_encode( _mb_substr( $string_mb, 2, 7, 'utf-8' ) ) );
    9292
    9393        /* https://github.com/php/php-src/blob/php-5.6.8/ext/mbstring/tests/mb_substr_variation1.phpt */
    94         $start = 0;
    95         $length = 5;
     94        $start     = 0;
     95        $length    = 5;
    9696        $unset_var = 10;
    97         unset ($unset_var);
     97        unset( $unset_var );
    9898        $heredoc = <<<EOT
    9999hello world
    100100EOT;
    101         $inputs = array(
     101        $inputs  = array(
    102102            0,
    103103            1,
     
    111111            .5,
    112112            // null data
    113             NULL,
     113            null,
    114114            null,
    115115            // boolean data
    116116            true,
    117117            false,
    118             TRUE,
    119             FALSE,
     118            true,
     119            false,
    120120            // empty data
    121             "",
     121            '',
    122122            '',
    123123            // string data
    124             "string",
     124            'string',
    125125            'string',
    126126            $heredoc,
     
    132132            @$unset_var,
    133133        );
    134         $outputs = array(
    135             "0",
    136             "1",
    137             "12345",
    138             "-2345",
    139             "10.5",
    140             "-10.5",
    141             "12345",
    142             "1.234",
    143             "0.5",
    144             "",
    145             "",
    146             "1",
    147             "",
    148             "1",
    149             "",
    150             "",
    151             "",
    152             "strin",
    153             "strin",
    154             "hello",
    155             "Class",
    156             "",
    157             "",
     134        $outputs  = array(
     135            '0',
     136            '1',
     137            '12345',
     138            '-2345',
     139            '10.5',
     140            '-10.5',
     141            '12345',
     142            '1.234',
     143            '0.5',
     144            '',
     145            '',
     146            '1',
     147            '',
     148            '1',
     149            '',
     150            '',
     151            '',
     152            'strin',
     153            'strin',
     154            'hello',
     155            'Class',
     156            '',
     157            '',
    158158        );
    159159        $iterator = 0;
    160         foreach($inputs as $input) {
    161             $this->assertEquals( $outputs[$iterator] ,  _mb_substr($input, $start, $length) );
     160        foreach ( $inputs as $input ) {
     161            $this->assertEquals( $outputs[ $iterator ], _mb_substr( $input, $start, $length ) );
    162162            $iterator++;
    163163        }
     
    166166
    167167    function test_hash_hmac_simple() {
    168         $this->assertEquals('140d1cb79fa12e2a31f32d35ad0a2723', _hash_hmac('md5', 'simple', 'key'));
    169         $this->assertEquals('993003b95758e0ac2eba451a4c5877eb1bb7b92a', _hash_hmac('sha1', 'simple', 'key'));
     168        $this->assertEquals( '140d1cb79fa12e2a31f32d35ad0a2723', _hash_hmac( 'md5', 'simple', 'key' ) );
     169        $this->assertEquals( '993003b95758e0ac2eba451a4c5877eb1bb7b92a', _hash_hmac( 'sha1', 'simple', 'key' ) );
    170170    }
    171171
    172172    function test_hash_hmac_padding() {
    173         $this->assertEquals('3c1399103807cf12ec38228614416a8c', _hash_hmac('md5', 'simple', '65 character key 65 character key 65 character key 65 character k'));
    174         $this->assertEquals('4428826d20003e309d6c2a6515891370daf184ea', _hash_hmac('sha1', 'simple', '65 character key 65 character key 65 character key 65 character k'));
     173        $this->assertEquals( '3c1399103807cf12ec38228614416a8c', _hash_hmac( 'md5', 'simple', '65 character key 65 character key 65 character key 65 character k' ) );
     174        $this->assertEquals( '4428826d20003e309d6c2a6515891370daf184ea', _hash_hmac( 'sha1', 'simple', '65 character key 65 character key 65 character key 65 character k' ) );
    175175    }
    176176
    177177    function test_hash_hmac_output() {
    178         $this->assertEquals(array( 1 => '140d1cb79fa12e2a31f32d35ad0a2723'), unpack('H32', _hash_hmac('md5', 'simple', 'key', true)));
    179         $this->assertEquals(array( 1 => '993003b95758e0ac2eba451a4c5877eb1bb7b92a'), unpack('H40', _hash_hmac('sha1', 'simple', 'key', true)));
     178        $this->assertEquals( array( 1 => '140d1cb79fa12e2a31f32d35ad0a2723' ), unpack( 'H32', _hash_hmac( 'md5', 'simple', 'key', true ) ) );
     179        $this->assertEquals( array( 1 => '993003b95758e0ac2eba451a4c5877eb1bb7b92a' ), unpack( 'H40', _hash_hmac( 'sha1', 'simple', 'key', true ) ) );
    180180    }
    181181
     
    189189}
    190190
    191 /* used in test_mb_substr_phpcore */ 
     191/* used in test_mb_substr_phpcore */
    192192class classA {
    193193    public function __toString() {
    194         return "Class A object";
     194        return 'Class A object';
    195195    }
    196196}
Note: See TracChangeset for help on using the changeset viewer.