Make WordPress Core

Ticket #27587: miqro-27587.2.patch

File miqro-27587.2.patch, 17.3 KB (added by miqrogroove, 11 years ago)

Corrected several more bad tests and refreshed.

  • src/wp-includes/formatting.php

     
    19091909         */
    19101910        $src_url = apply_filters( 'smilies_src', includes_url( "images/smilies/$img" ), $img, site_url() );
    19111911
    1912         return sprintf( ' <img src="%s" alt="%s" class="wp-smiley" /> ', esc_url( $src_url ), esc_attr( $smiley ) );
     1912        return sprintf( '<img src="%s" alt="%s" class="wp-smiley" />', esc_url( $src_url ), esc_attr( $smiley ) );
    19131913}
    19141914
    19151915/**
     
    38643864        }
    38653865
    38663866        return $spaces;
    3867 }
    3868  No newline at end of file
     3867}
  • src/wp-includes/functions.php

     
    27132713         */
    27142714        krsort($wpsmiliestrans);
    27152715
    2716         $wp_smiliessearch = '/((?:\s|^)';
     2716        $spaces = wp_spaces_regexp();
    27172717
     2718        // Begin first "subpattern"
     2719        $wp_smiliessearch = '/(?<=' . $spaces . '|^)';
     2720
    27182721        $subchar = '';
    27192722        foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
    27202723                $firstchar = substr($smiley, 0, 1);
     
    27232726                // new subpattern?
    27242727                if ($firstchar != $subchar) {
    27252728                        if ($subchar != '') {
    2726                                 $wp_smiliessearch .= ')(?=\s|$))|((?:\s|^)'; ;
     2729                                $wp_smiliessearch .= ')(?=' . $spaces . '|$)';  // End previous "subpattern"
     2730                                $wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern"
    27272731                        }
    27282732                        $subchar = $firstchar;
    27292733                        $wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:';
     
    27332737                $wp_smiliessearch .= preg_quote($rest, '/');
    27342738        }
    27352739
    2736         $wp_smiliessearch .= ')(?=\s|$))/m';
     2740        $wp_smiliessearch .= ')(?=' . $spaces . '|$)/m';
    27372741
    27382742}
    27392743
     
    44194423        }
    44204424
    44214425        return (bool) $var;
    4422 }
    4423  No newline at end of file
     4426}
  • tests/phpunit/tests/formatting/Smilies.php

     
    1616                return array (
    1717                        array (
    1818                                '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 :?:',
    19                                 'Lorem ipsum dolor sit amet mauris <img src="' . $includes_path . 'icon_wink.gif" alt=";-)" class="wp-smiley" />  Praesent gravida sodales. <img src="' . $includes_path . 'icon_lol.gif" alt=":lol:" class="wp-smiley" />  Vivamus nec diam in faucibus eu, bibendum varius nec, imperdiet purus est, at augue at lacus malesuada elit dapibus a, <img src="' . $includes_path . 'icon_surprised.gif" alt=":eek:" class="wp-smiley" />  mauris. Cras mauris viverra elit. Nam laoreet viverra. Pellentesque tortor. Nam libero ante, porta urna ut turpis. Nullam wisi magna, <img src="' . $includes_path . 'icon_mrgreen.gif" alt=":mrgreen:" class="wp-smiley" />  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 <img src="' . $includes_path . 'icon_question.gif" alt=":?:" class="wp-smiley" /> '
     19                                'Lorem ipsum dolor sit amet mauris <img src="' . $includes_path . 'icon_wink.gif" alt=";-)" class="wp-smiley" /> Praesent gravida sodales. <img src="' . $includes_path . 'icon_lol.gif" alt=":lol:" class="wp-smiley" /> Vivamus nec diam in faucibus eu, bibendum varius nec, imperdiet purus est, at augue at lacus malesuada elit dapibus a, <img src="' . $includes_path . 'icon_surprised.gif" alt=":eek:" class="wp-smiley" /> mauris. Cras mauris viverra elit. Nam laoreet viverra. Pellentesque tortor. Nam libero ante, porta urna ut turpis. Nullam wisi magna, <img src="' . $includes_path . 'icon_mrgreen.gif" alt=":mrgreen:" class="wp-smiley" /> 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 <img src="' . $includes_path . 'icon_question.gif" alt=":?:" class="wp-smiley" />'
    2020                        ),
    2121                        array (
    2222                                '<strong>Welcome to the jungle!</strong> We got fun n games! :) We got everything you want 8-) <em>Honey we know the names :)</em>',
    23                                 '<strong>Welcome to the jungle!</strong> We got fun n games! <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" />  We got everything you want <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" />  <em>Honey we know the names <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> </em>'
     23                                '<strong>Welcome to the jungle!</strong> We got fun n games! <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> We got everything you want <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <em>Honey we know the names <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /></em>'
    2424                        ),
    2525                        array (
    2626                                "<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",
    27                                 "<strong;)>a little bit of this\na little bit:other: of that <img src=\"{$includes_path}icon_biggrin.gif\" alt=\":D\" class=\"wp-smiley\" />  <img src=\"{$includes_path}icon_biggrin.gif\" alt=\":D\" class=\"wp-smiley\" /> a little bit of good\nyeah with a little bit of bad8O"
     27                                "<strong;)>a little bit of this\na little bit:other: of that <img src=\"{$includes_path}icon_biggrin.gif\" alt=\":D\" class=\"wp-smiley\" />\n<img src=\"{$includes_path}icon_biggrin.gif\" alt=\":D\" class=\"wp-smiley\" /> a little bit of good\nyeah with a little bit of bad8O"
    2828                        ),
    2929                        array (
    3030                                '<strong style="here comes the sun :-D">and I say it\'s allright:D:D',
     
    4848         * when use_smilies = 1 and not when use_smilies = 0
    4949         */
    5050        function test_convert_standard_smilies( $in_txt, $converted_txt ) {
    51                 global $wpsmiliestrans;
    52 
    5351                // standard smilies, use_smilies: ON
    5452                update_option( 'use_smilies', 1 );
    5553
     
    6159                update_option( 'use_smilies', 0 );
    6260
    6361                $this->assertEquals( $in_txt, convert_smilies($in_txt) );
    64 
    65                 unset( $wpsmiliestrans );
    6662        }
    6763
    6864        /**
     
    7672                return array (
    7773                        array (
    7874                                '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:',
    79                                 '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" /> '
     75                                '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" />'
    8076                        ),
    8177                        array (
    8278                                '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:',
    83                                 'Star Wars Jedi Knight <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" />  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" /> '
     79                                'Star Wars Jedi Knight <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" /> 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" />'
    8480                        ),
    8581                        array (
    8682                                ':arrow: monkey: Lorem ipsum dolor sit amet enim. Etiam ullam :PP <br />corper. Suspendisse a pellentesque dui, non felis.<a> :arrow: :arrow</a>',
    87                                 ' <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" />  monkey: Lorem ipsum dolor sit amet enim. Etiam ullam <img src="' . $includes_path . 'icon_tongue.gif" alt=":PP" class="wp-smiley" />  <br />corper. Suspendisse a pellentesque dui, non felis.<a> <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" /> :arrow</a>'
     83                                '<img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" /> monkey: Lorem ipsum dolor sit amet enim. Etiam ullam <img src="' . $includes_path . 'icon_tongue.gif" alt=":PP" class="wp-smiley" /> <br />corper. Suspendisse a pellentesque dui, non felis.<a> <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" /> :arrow</a>'
    8884                        ),
    8985                );
    9086        }
     
    9692         */
    9793        function test_convert_custom_smilies ( $in_txt, $converted_txt ) {
    9894                global $wpsmiliestrans;
    99                 $trans_orig = $wpsmiliestrans; // save original translations array
    10095
    10196                // custom smilies, use_smilies: ON
    10297                update_option( 'use_smilies', 1 );
     98
     99                if ( !isset( $wpsmiliestrans ) ) {
     100                        smilies_init();
     101                }
     102
     103                $trans_orig = $wpsmiliestrans; // save original translations array
     104
    103105                $wpsmiliestrans = array(
    104106                  ':PP' => 'icon_tongue.gif',
    105107                  ':arrow:' => 'icon_arrow.gif',
     
    142144         * @dataProvider get_smilies_ignore_tags
    143145         */
    144146        public function test_ignore_smilies_in_tags( $element ) {
    145                 global $wpsmiliestrans;
    146                 $trans_orig = $wpsmiliestrans;  // save original translations array
    147 
    148147                $includes_path = includes_url("images/smilies/");
    149148
    150149                $in_str = 'Do we ingore smilies ;-) in ' . $element . ' tags <' . $element . '>My Content Here :?: </' . $element . '>';
    151                 $exp_str = 'Do we ingore smilies <img src="' . $includes_path . 'icon_wink.gif" alt=";-)" class="wp-smiley" />  in ' . $element . ' tags <' . $element . '>My Content Here :?: </' . $element . '>';
     150                $exp_str = 'Do we ingore smilies <img src="' . $includes_path . 'icon_wink.gif" alt=";-)" class="wp-smiley" /> in ' . $element . ' tags <' . $element . '>My Content Here :?: </' . $element . '>';
    152151
    153152                // standard smilies, use_smilies: ON
    154153                update_option( 'use_smilies', 1 );
     
    158157
    159158                // standard smilies, use_smilies: OFF
    160159                update_option( 'use_smilies', 0 );
    161 
    162                 $wpsmiliestrans = $trans_orig; // reset original translations array
    163160        }
    164161
    165162        /**
     
    172169                return array (
    173170                        array (
    174171                                '8-O :-(',
    175                                 ' <img src="' . $includes_path . 'icon_eek.gif" alt="8-O" class="wp-smiley" />  <img src="' . $includes_path . 'icon_sad.gif" alt=":-(" class="wp-smiley" /> '
     172                                '<img src="' . $includes_path . 'icon_eek.gif" alt="8-O" class="wp-smiley" /> <img src="' . $includes_path . 'icon_sad.gif" alt=":-(" class="wp-smiley" />'
    176173                        ),
    177174                        array (
    178175                                '8-) 8-O',
    179                                 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" />  <img src="' . $includes_path . 'icon_eek.gif" alt="8-O" class="wp-smiley" /> '
     176                                '<img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_eek.gif" alt="8-O" class="wp-smiley" />'
    180177                        ),
    181178                        array (
    182179                                '8-) 8O',
    183                                 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" />  <img src="' . $includes_path . 'icon_eek.gif" alt="8O" class="wp-smiley" /> '
     180                                '<img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_eek.gif" alt="8O" class="wp-smiley" />'
    184181                        ),
    185182                        array (
    186183                                '8-) :-(',
    187                                 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" />  <img src="' . $includes_path . 'icon_sad.gif" alt=":-(" class="wp-smiley" /> '
     184                                '<img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_sad.gif" alt=":-(" class="wp-smiley" />'
    188185                        ),
    189186                        array (
    190187                                '8-) :twisted:',
    191                                 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" />  <img src="' . $includes_path . 'icon_twisted.gif" alt=":twisted:" class="wp-smiley" /> '
     188                                '<img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_twisted.gif" alt=":twisted:" class="wp-smiley" />'
    192189                        ),
    193190                        array (
    194191                                '8O :twisted: :( :? :(',
    195                                 ' <img src="' . $includes_path . 'icon_eek.gif" alt="8O" class="wp-smiley" />  <img src="' . $includes_path . 'icon_twisted.gif" alt=":twisted:" class="wp-smiley" />  <img src="' . $includes_path . 'icon_sad.gif" alt=":(" class="wp-smiley" />  <img src="' . $includes_path . 'icon_confused.gif" alt=":?" class="wp-smiley" />  <img src="' . $includes_path . 'icon_sad.gif" alt=":(" class="wp-smiley" /> '
     192                                '<img src="' . $includes_path . 'icon_eek.gif" alt="8O" class="wp-smiley" /> <img src="' . $includes_path . 'icon_twisted.gif" alt=":twisted:" class="wp-smiley" /> <img src="' . $includes_path . 'icon_sad.gif" alt=":(" class="wp-smiley" /> <img src="' . $includes_path . 'icon_confused.gif" alt=":?" class="wp-smiley" /> <img src="' . $includes_path . 'icon_sad.gif" alt=":(" class="wp-smiley" />'
    196193                        ),
    197194                );
    198195        }
     
    205202         * @dataProvider get_smilies_combinations
    206203         */
    207204        public function test_smilies_combinations( $in_txt, $converted_txt ) {
    208                 global $wpsmiliestrans;
    209 
    210205                // custom smilies, use_smilies: ON
    211206                update_option( 'use_smilies', 1 );
    212207                smilies_init();
     
    233228                        ),
    234229                        array (
    235230                                '8O :) additional text here :)',
    236                                 '8O <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" />  additional text here <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> '
     231                                '8O <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> additional text here <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" />'
    237232                        ),
    238233                        array (
    239234                                ':) :) :) :)',
    240                                 ' <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" />  <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" />  <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" />  <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> '
     235                                '<img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_smile.gif" alt=":)" class="wp-smiley" />'
    241236                        ),
    242237                );
    243238        }
     
    251246         */
    252247        public function test_single_smilies_in_wpsmiliestrans( $in_txt, $converted_txt ) {
    253248                global $wpsmiliestrans;
    254                 $orig_trans = $wpsmiliestrans; // save original tranlations array
    255249
    256250                // standard smilies, use_smilies: ON
    257251                update_option( 'use_smilies', 1 );
    258252
     253                if ( !isset( $wpsmiliestrans ) ) {
     254                        smilies_init();
     255                }
     256
     257                $orig_trans = $wpsmiliestrans; // save original tranlations array
     258
    259259                $wpsmiliestrans = array (
    260260                  ':)' => 'icon_smile.gif'
    261261                );
     
    271271
    272272                $wpsmiliestrans = $orig_trans; // reset original translations array
    273273        }
    274 }
    275  No newline at end of file
     274
     275        /**
     276         * Check that $wp_smiliessearch pattern will match smilies
     277         * between spaces, but never capture those spaces.
     278         *
     279         * Further check that spaces aren't randomly deleted
     280         * or added when replacing the text with an image.
     281         *
     282         * @ticket 22692
     283         */
     284        function test_spaces_around_smilies() {
     285                $nbsp = "\xC2\xA0";
     286
     287                // standard smilies, use_smilies: ON
     288                update_option( 'use_smilies', 1 );
     289                smilies_init();
     290
     291                $input  = array();
     292                $output = array();
     293
     294                $input[]  = 'My test :) smile';
     295                $output[] = array('test <img ', 'alt=":)"', ' /> smile');
     296
     297                $input[]  = 'My test ;) smile';
     298                $output[] = array('test <img ', 'alt=";)"', ' /> smile');
     299
     300                $input[]  = 'My test &nbsp;:)&nbsp;smile';
     301                $output[] = array('test &nbsp;<img ', 'alt=":)"', ' />&nbsp;smile');
     302
     303                $input[]  = 'My test &nbsp;;)&nbsp;smile';
     304                $output[] = array('test &nbsp;<img ', 'alt=";)"', ' />&nbsp;smile');
     305
     306                $input[]  = "My test {$nbsp}:){$nbsp}smile";
     307                $output[] = array("test {$nbsp}<img ", 'alt=":)"', " />{$nbsp}smile");
     308
     309                $input[]  = "My test {$nbsp};){$nbsp}smile";
     310                $output[] = array("test {$nbsp}<img ", 'alt=";)"', " />{$nbsp}smile");
     311
     312                foreach($input as $key => $in) {
     313                        $result = convert_smilies( $in );
     314                        foreach($output[$key] as $out) {
     315
     316                                // Each output element must appear in the results.
     317                                $this->assertContains( $out, $result );
     318
     319                        }
     320                }
     321
     322                // standard smilies, use_smilies: OFF
     323                update_option( 'use_smilies', 0 );
     324        }
     325}