Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 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/formatting/Smilies.php

    r42228 r42343  
    1313         */
    1414        public function get_smilies_input_output() {
    15                 $includes_path = includes_url("images/smilies/");
    16 
    17                 return array (
    18                         array (
     15                $includes_path = includes_url( 'images/smilies/' );
     16
     17                return array(
     18                        array(
    1919                                'Lorem ipsum dolor sit amet mauris ;-) Praesent gravida sodales. :lol: Vivamus nec diam in faucibus eu, bibendum varius nec, imperdiet purus est, at augue at lacus malesuada elit dapibus a, :eek: mauris. Cras mauris viverra elit. Nam laoreet viverra. Pellentesque tortor. Nam libero ante, porta urna ut turpis. Nullam wisi magna, :mrgreen: tincidunt nec, sagittis non, fringilla enim. Nam consectetuer nec, ullamcorper pede eu dui odio consequat vel, vehicula tortor quis pede turpis cursus quis, egestas ipsum ultricies ut, eleifend velit. Mauris vestibulum iaculis. Sed in nunc. Vivamus elit porttitor egestas. Mauris purus :?:',
    20                                 "Lorem ipsum dolor sit amet mauris \xf0\x9f\x98\x89 Praesent gravida sodales. \xf0\x9f\x98\x86 Vivamus nec diam in faucibus eu, bibendum varius nec, imperdiet purus est, at augue at lacus malesuada elit dapibus a, \xf0\x9f\x98\xae mauris. Cras mauris viverra elit. Nam laoreet viverra. Pellentesque tortor. Nam libero ante, porta urna ut turpis. Nullam wisi magna, <img src=\"${includes_path}mrgreen.png\" alt=\":mrgreen:\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" /> tincidunt nec, sagittis non, fringilla enim. Nam consectetuer nec, ullamcorper pede eu dui odio consequat vel, vehicula tortor quis pede turpis cursus quis, egestas ipsum ultricies ut, eleifend velit. Mauris vestibulum iaculis. Sed in nunc. Vivamus elit porttitor egestas. Mauris purus \xe2\x9d\x93"
    21                         ),
    22                         array (
     20                                "Lorem ipsum dolor sit amet mauris \xf0\x9f\x98\x89 Praesent gravida sodales. \xf0\x9f\x98\x86 Vivamus nec diam in faucibus eu, bibendum varius nec, imperdiet purus est, at augue at lacus malesuada elit dapibus a, \xf0\x9f\x98\xae mauris. Cras mauris viverra elit. Nam laoreet viverra. Pellentesque tortor. Nam libero ante, porta urna ut turpis. Nullam wisi magna, <img src=\"${includes_path}mrgreen.png\" alt=\":mrgreen:\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" /> tincidunt nec, sagittis non, fringilla enim. Nam consectetuer nec, ullamcorper pede eu dui odio consequat vel, vehicula tortor quis pede turpis cursus quis, egestas ipsum ultricies ut, eleifend velit. Mauris vestibulum iaculis. Sed in nunc. Vivamus elit porttitor egestas. Mauris purus \xe2\x9d\x93",
     21                        ),
     22                        array(
    2323                                '<strong>Welcome to the jungle!</strong> We got fun n games! :) We got everything you want 8-) <em>Honey we know the names :)</em>',
    24                                 "<strong>Welcome to the jungle!</strong> We got fun n games! \xf0\x9f\x99\x82 We got everything you want \xf0\x9f\x98\x8e <em>Honey we know the names \xf0\x9f\x99\x82</em>"
    25                         ),
    26                         array (
     24                                "<strong>Welcome to the jungle!</strong> We got fun n games! \xf0\x9f\x99\x82 We got everything you want \xf0\x9f\x98\x8e <em>Honey we know the names \xf0\x9f\x99\x82</em>",
     25                        ),
     26                        array(
    2727                                "<strong;)>a little bit of this\na little bit:other: of that :D\n:D a little bit of good\nyeah with a little bit of bad8O",
    28                                 "<strong;)>a little bit of this\na little bit:other: of that \xf0\x9f\x98\x80\n\xf0\x9f\x98\x80 a little bit of good\nyeah with a little bit of bad8O"
    29                         ),
    30                         array (
     28                                "<strong;)>a little bit of this\na little bit:other: of that \xf0\x9f\x98\x80\n\xf0\x9f\x98\x80 a little bit of good\nyeah with a little bit of bad8O",
     29                        ),
     30                        array(
    3131                                '<strong style="here comes the sun :-D">and I say it\'s allright:D:D',
    32                                 '<strong style="here comes the sun :-D">and I say it\'s allright:D:D'
    33                         ),
    34                         array (
     32                                '<strong style="here comes the sun :-D">and I say it\'s allright:D:D',
     33                        ),
     34                        array(
    3535                                '<!-- Woo-hoo, I\'m a comment, baby! :x > -->',
    36                                 '<!-- Woo-hoo, I\'m a comment, baby! :x > -->'
    37                         ),
    38                         array (
     36                                '<!-- Woo-hoo, I\'m a comment, baby! :x > -->',
     37                        ),
     38                        array(
    3939                                ':?:P:?::-x:mrgreen:::',
    40                                 ':?:P:?::-x:mrgreen:::'
     40                                ':?:P:?::-x:mrgreen:::',
    4141                        ),
    4242                );
     
    5555                smilies_init();
    5656
    57                 $this->assertEquals( $converted_txt, convert_smilies($in_txt) );
    58 
    59                 // standard smilies, use_smilies: OFF
    60                 update_option( 'use_smilies', 0 );
    61 
    62                 $this->assertEquals( $in_txt, convert_smilies($in_txt) );
     57                $this->assertEquals( $converted_txt, convert_smilies( $in_txt ) );
     58
     59                // standard smilies, use_smilies: OFF
     60                update_option( 'use_smilies', 0 );
     61
     62                $this->assertEquals( $in_txt, convert_smilies( $in_txt ) );
    6363        }
    6464
     
    6969         */
    7070        public function get_custom_smilies_input_output() {
    71                 $includes_path = includes_url("images/smilies/");
    72 
    73                 return array (
    74                         array (
     71                $includes_path = includes_url( 'images/smilies/' );
     72
     73                return array(
     74                        array(
    7575                                'Peter Brian Gabriel (born 13 February 1950) is a British singer, musician, and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. :monkey:',
    76                                 'Peter Brian Gabriel (born 13 February 1950) is a British singer, musician, and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. <img src="' . $includes_path . 'icon_shock_the_monkey.gif" alt=":monkey:" class="wp-smiley" style="height: 1em; max-height: 1em;" />'
    77                         ),
    78                         array (
     76                                'Peter Brian Gabriel (born 13 February 1950) is a British singer, musician, and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. <img src="' . $includes_path . 'icon_shock_the_monkey.gif" alt=":monkey:" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
     77                        ),
     78                        array(
    7979                                'Star Wars Jedi Knight :arrow: Jedi Academy is a first and third-person shooter action game set in the Star Wars universe. It was developed by Raven Software and published, distributed and marketed by LucasArts in North America and by Activision in the rest of the world. :nervou:',
    80                                 'Star Wars Jedi Knight <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Jedi Academy is a first and third-person shooter action game set in the Star Wars universe. It was developed by Raven Software and published, distributed and marketed by LucasArts in North America and by Activision in the rest of the world. <img src="' . $includes_path . 'icon_nervou.gif" alt=":nervou:" class="wp-smiley" style="height: 1em; max-height: 1em;" />'
    81                         ),
    82                         array (
     80                                'Star Wars Jedi Knight <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Jedi Academy is a first and third-person shooter action game set in the Star Wars universe. It was developed by Raven Software and published, distributed and marketed by LucasArts in North America and by Activision in the rest of the world. <img src="' . $includes_path . 'icon_nervou.gif" alt=":nervou:" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
     81                        ),
     82                        array(
    8383                                ':arrow: monkey: Lorem ipsum dolor sit amet enim. Etiam ullam :PP <br />corper. Suspendisse a pellentesque dui, non felis.<a> :arrow: :arrow</a>',
    84                                 '<img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" style="height: 1em; max-height: 1em;" /> monkey: Lorem ipsum dolor sit amet enim. Etiam ullam <img src="' . $includes_path . 'icon_tongue.gif" alt=":PP" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <br />corper. Suspendisse a pellentesque dui, non felis.<a> <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" style="height: 1em; max-height: 1em;" /> :arrow</a>'
     84                                '<img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" style="height: 1em; max-height: 1em;" /> monkey: Lorem ipsum dolor sit amet enim. Etiam ullam <img src="' . $includes_path . 'icon_tongue.gif" alt=":PP" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <br />corper. Suspendisse a pellentesque dui, non felis.<a> <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" style="height: 1em; max-height: 1em;" /> :arrow</a>',
    8585                        ),
    8686                );
     
    9292         * Validate Custom Smilies are converted to images when use_smilies = 1
    9393         */
    94         function test_convert_custom_smilies ( $in_txt, $converted_txt ) {
     94        function test_convert_custom_smilies( $in_txt, $converted_txt ) {
    9595                global $wpsmiliestrans;
    9696
     
    9898                update_option( 'use_smilies', 1 );
    9999
    100                 if ( !isset( $wpsmiliestrans ) ) {
     100                if ( ! isset( $wpsmiliestrans ) ) {
    101101                        smilies_init();
    102102                }
     
    105105
    106106                $wpsmiliestrans = array(
    107                         ':PP' => 'icon_tongue.gif',
    108                         ':arrow:' => 'icon_arrow.gif',
     107                        ':PP'      => 'icon_tongue.gif',
     108                        ':arrow:'  => 'icon_arrow.gif',
    109109                        ':monkey:' => 'icon_shock_the_monkey.gif',
    110                         ':nervou:' => 'icon_nervou.gif'
    111                 );
    112 
    113                 smilies_init();
    114 
    115                 $this->assertEquals( $converted_txt, convert_smilies($in_txt) );
    116 
    117                 // standard smilies, use_smilies: OFF
    118                 update_option( 'use_smilies', 0 );
    119 
    120                 $this->assertEquals( $in_txt, convert_smilies($in_txt) );
     110                        ':nervou:' => 'icon_nervou.gif',
     111                );
     112
     113                smilies_init();
     114
     115                $this->assertEquals( $converted_txt, convert_smilies( $in_txt ) );
     116
     117                // standard smilies, use_smilies: OFF
     118                update_option( 'use_smilies', 0 );
     119
     120                $this->assertEquals( $in_txt, convert_smilies( $in_txt ) );
    121121
    122122                $wpsmiliestrans = $trans_orig; // reset original translations array
     
    126126        /**
    127127         * DataProvider of HTML elements/tags that smilie matches should be ignored in
    128          *
    129128         */
    130129        public function get_smilies_ignore_tags() {
    131                 return array (
     130                return array(
    132131                        array( 'pre' ),
    133132                        array( 'code' ),
    134133                        array( 'script' ),
    135134                        array( 'style' ),
    136                         array( 'textarea'),
     135                        array( 'textarea' ),
    137136                );
    138137        }
     
    146145         */
    147146        public function test_ignore_smilies_in_tags( $element ) {
    148                 $includes_path = includes_url("images/smilies/");
    149 
    150                 $in_str = 'Do we ingore smilies ;-) in ' . $element . ' tags <' . $element . '>My Content Here :?: </' . $element . '>';
     147                $includes_path = includes_url( 'images/smilies/' );
     148
     149                $in_str  = 'Do we ingore smilies ;-) in ' . $element . ' tags <' . $element . '>My Content Here :?: </' . $element . '>';
    151150                $exp_str = "Do we ingore smilies \xf0\x9f\x98\x89 in $element tags <$element>My Content Here :?: </$element>";
    152151
     
    155154                smilies_init();
    156155
    157                 $this->assertEquals( $exp_str, convert_smilies($in_str) );
     156                $this->assertEquals( $exp_str, convert_smilies( $in_str ) );
    158157
    159158                // standard smilies, use_smilies: OFF
     
    163162        /**
    164163         * DataProvider of Smilie Combinations
    165          *
    166164         */
    167165        public function get_smilies_combinations() {
    168                 $includes_path = includes_url("images/smilies/");
    169 
    170                 return array (
    171                         array (
     166                $includes_path = includes_url( 'images/smilies/' );
     167
     168                return array(
     169                        array(
    172170                                '8-O :-(',
    173                                 "\xf0\x9f\x98\xaf \xf0\x9f\x99\x81"
    174                         ),
    175                         array (
     171                                "\xf0\x9f\x98\xaf \xf0\x9f\x99\x81",
     172                        ),
     173                        array(
    176174                                '8-) 8-O',
    177                                 "\xf0\x9f\x98\x8e \xf0\x9f\x98\xaf"
    178                         ),
    179                         array (
     175                                "\xf0\x9f\x98\x8e \xf0\x9f\x98\xaf",
     176                        ),
     177                        array(
    180178                                '8-) 8O',
    181                                 "\xf0\x9f\x98\x8e \xf0\x9f\x98\xaf"
    182                         ),
    183                         array (
     179                                "\xf0\x9f\x98\x8e \xf0\x9f\x98\xaf",
     180                        ),
     181                        array(
    184182                                '8-) :-(',
    185                                 "\xf0\x9f\x98\x8e \xf0\x9f\x99\x81"
    186                         ),
    187                         array (
     183                                "\xf0\x9f\x98\x8e \xf0\x9f\x99\x81",
     184                        ),
     185                        array(
    188186                                '8-) :twisted:',
    189                                 "\xf0\x9f\x98\x8e \xf0\x9f\x98\x88"
    190                         ),
    191                         array (
     187                                "\xf0\x9f\x98\x8e \xf0\x9f\x98\x88",
     188                        ),
     189                        array(
    192190                                '8O :twisted: :( :? :roll: :mrgreen:',
    193                                 "\xf0\x9f\x98\xaf \xf0\x9f\x98\x88 \xf0\x9f\x99\x81 \xf0\x9f\x98\x95 \xf0\x9f\x99\x84 <img src=\"{$includes_path}mrgreen.png\" alt=\":mrgreen:\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" />"
     191                                "\xf0\x9f\x98\xaf \xf0\x9f\x98\x88 \xf0\x9f\x99\x81 \xf0\x9f\x98\x95 \xf0\x9f\x99\x84 <img src=\"{$includes_path}mrgreen.png\" alt=\":mrgreen:\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" />",
    194192                        ),
    195193                );
     
    208206                smilies_init();
    209207
    210                 $this->assertEquals( $converted_txt, convert_smilies($in_txt) );
     208                $this->assertEquals( $converted_txt, convert_smilies( $in_txt ) );
    211209
    212210                // custom smilies, use_smilies: OFF
    213211                update_option( 'use_smilies', 0 );
    214212
    215                 $this->assertEquals( $in_txt, convert_smilies($in_txt) );
     213                $this->assertEquals( $in_txt, convert_smilies( $in_txt ) );
    216214        }
    217215
    218216        /**
    219217         * DataProvider of Single Smilies input and converted output
    220          *
    221218         */
    222219        public function get_single_smilies_input_output() {
    223                 $includes_path = includes_url("images/smilies/");
    224 
    225                 return array (
    226                         array (
     220                $includes_path = includes_url( 'images/smilies/' );
     221
     222                return array(
     223                        array(
    227224                                '8-O :-(',
    228                                 '8-O :-('
    229                         ),
    230                         array (
     225                                '8-O :-(',
     226                        ),
     227                        array(
    231228                                '8O :) additional text here :)',
    232                                 '8O <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> additional text here <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" />'
    233                         ),
    234                         array (
     229                                '8O <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> additional text here <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
     230                        ),
     231                        array(
    235232                                ':) :) :) :)',
    236                                 '<img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" />'
     233                                '<img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
    237234                        ),
    238235                );
     
    252249                update_option( 'use_smilies', 1 );
    253250
    254                 if ( !isset( $wpsmiliestrans ) ) {
     251                if ( ! isset( $wpsmiliestrans ) ) {
    255252                        smilies_init();
    256253                }
     
    258255                $orig_trans = $wpsmiliestrans; // save original tranlations array
    259256
    260                 $wpsmiliestrans = array (
    261                         ':)' => 'simple-smile.png'
    262                 );
    263 
    264                 smilies_init();
    265 
    266                 $this->assertEquals( $converted_txt, convert_smilies($in_txt) );
    267 
    268                 // standard smilies, use_smilies: OFF
    269                 update_option( 'use_smilies', 0 );
    270 
    271                 $this->assertEquals( $in_txt, convert_smilies($in_txt) );
     257                $wpsmiliestrans = array(
     258                        ':)' => 'simple-smile.png',
     259                );
     260
     261                smilies_init();
     262
     263                $this->assertEquals( $converted_txt, convert_smilies( $in_txt ) );
     264
     265                // standard smilies, use_smilies: OFF
     266                update_option( 'use_smilies', 0 );
     267
     268                $this->assertEquals( $in_txt, convert_smilies( $in_txt ) );
    272269
    273270                $wpsmiliestrans = $orig_trans; // reset original translations array
     
    280277                        array(
    281278                                'test :) smile',
    282                                 "test \xf0\x9f\x99\x82 smile"
     279                                "test \xf0\x9f\x99\x82 smile",
    283280                        ),
    284281                        array(
    285282                                'test &nbsp;:)&nbsp;smile',
    286                                 "test &nbsp;\xf0\x9f\x99\x82&nbsp;smile"
     283                                "test &nbsp;\xf0\x9f\x99\x82&nbsp;smile",
    287284                        ),
    288285                        array(
    289286                                "test {$nbsp}:){$nbsp}smile",
    290                                 "test {$nbsp}\xf0\x9f\x99\x82{$nbsp}smile"
    291                         )
     287                                "test {$nbsp}\xf0\x9f\x99\x82{$nbsp}smile",
     288                        ),
    292289                );
    293290        }
     
    340337                remove_filter( 'smilies', array( $this, '_filter_add_smilies' ) );
    341338
    342                 $txt = 'You played with my <3';
     339                $txt          = 'You played with my <3';
    343340                $expected_txt = 'You played with my \xe2\x9d\xa4';
    344341
Note: See TracChangeset for help on using the changeset viewer.