Make WordPress Core

Ticket #27587: miqro-27587.patch

File miqro-27587.patch, 17.2 KB (added by miqrogroove, 11 years ago)

Remove all extra spaces from expected outputs. Fix unit bugs.

  • 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/**
  • src/wp-includes/functions.php

     
    25662566         */
    25672567        krsort($wpsmiliestrans);
    25682568
    2569         $wp_smiliessearch = '/((?:\s|^)';
     2569        $spaces = wp_spaces_regexp();
     2570 
     2571        // Begin first "subpattern"
     2572        $wp_smiliessearch = '/(?<=' . $spaces . '|^)';
    25702573
    25712574        $subchar = '';
    25722575        foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
     
    25762579                // new subpattern?
    25772580                if ($firstchar != $subchar) {
    25782581                        if ($subchar != '') {
    2579                                 $wp_smiliessearch .= ')(?=\s|$))|((?:\s|^)'; ;
     2582                                $wp_smiliessearch .= ')(?=' . $spaces . '|$)';  // End previous "subpattern"
     2583                                $wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern"
    25802584                        }
    25812585                        $subchar = $firstchar;
    25822586                        $wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:';
     
    25862590                $wp_smiliessearch .= preg_quote($rest, '/');
    25872591        }
    25882592
    2589         $wp_smiliessearch .= ')(?=\s|$))/m';
     2593        $wp_smiliessearch .= ')(?=' . $spaces . '|$)/m';
    25902594
    25912595}
    25922596
  • 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\" /> <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        }
     
    9793         */
    9894        function test_convert_custom_smilies ( $in_txt, $converted_txt ) {
    9995                global $wpsmiliestrans;
    100                 $trans_orig = $wpsmiliestrans; // save original translations array
    10196
    10297                // custom smilies, use_smilies: ON
    10398                update_option( 'use_smilies', 1 );
     99
     100                if ( !isset( $wpsmiliestrans ) ) {
     101                        smilies_init();
     102                }
     103
     104                $trans_orig = $wpsmiliestrans; // save original translations array
     105
    104106                $wpsmiliestrans = array(
    105107                  ':PP' => 'icon_tongue.gif',
    106108                  ':arrow:' => 'icon_arrow.gif',
     
    141143         *
    142144         * @ticket 16448
    143145         * @dataProvider get_smilies_ignore_tags
    144          * @uses $wpsmiliestrans
    145146         */
    146147        public function test_ignore_smilies_in_tags( $element ) {
    147                 global $wpsmiliestrans;
    148                 $trans_orig = $wpsmiliestrans;  // save original translations array
    149 
    150148                $includes_path = includes_url("images/smilies/");
    151149
    152150                $in_str = 'Do we ingore smilies ;-) in ' . $element . ' tags <' . $element . '>My Content Here :?: </' . $element . '>';
    153                 $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 . '>';
     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 . '>';
    154152
    155153                // standard smilies, use_smilies: ON
    156154                update_option( 'use_smilies', 1 );
     
    160158
    161159                // standard smilies, use_smilies: OFF
    162160                update_option( 'use_smilies', 0 );
    163 
    164                 $wpsmiliestrans = $trans_orig; // reset original translations array
    165161        }
    166162
    167163        /**
     
    174170                return array (
    175171                        array (
    176172                                '8-O :-(',
    177                                 ' <img src="' . $includes_path . 'icon_eek.gif" alt="8-O" class="wp-smiley" />  <img src="' . $includes_path . 'icon_sad.gif" alt=":-(" class="wp-smiley" /> '
     173                                ' <img src="' . $includes_path . 'icon_eek.gif" alt="8-O" class="wp-smiley" /> <img src="' . $includes_path . 'icon_sad.gif" alt=":-(" class="wp-smiley" /> '
    178174                        ),
    179175                        array (
    180176                                '8-) 8-O',
    181                                 ' <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" /> '
     177                                ' <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" /> '
    182178                        ),
    183179                        array (
    184180                                '8-) 8O',
    185                                 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" />  <img src="' . $includes_path . 'icon_eek.gif" alt="8O" class="wp-smiley" /> '
     181                                ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_eek.gif" alt="8O" class="wp-smiley" /> '
    186182                        ),
    187183                        array (
    188184                                '8-) :-(',
    189                                 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" />  <img src="' . $includes_path . 'icon_sad.gif" alt=":-(" class="wp-smiley" /> '
     185                                ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_sad.gif" alt=":-(" class="wp-smiley" /> '
    190186                        ),
    191187                        array (
    192188                                '8-) :twisted:',
    193                                 ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" />  <img src="' . $includes_path . 'icon_twisted.gif" alt=":twisted:" class="wp-smiley" /> '
     189                                ' <img src="' . $includes_path . 'icon_cool.gif" alt="8-)" class="wp-smiley" /> <img src="' . $includes_path . 'icon_twisted.gif" alt=":twisted:" class="wp-smiley" /> '
    194190                        ),
    195191                        array (
    196192                                '8O :twisted: :( :? :(',
    197                                 ' <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" /> '
     193                                ' <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" /> '
    198194                        ),
    199195                );
    200196        }
     
    205201         *
    206202         * @ticket 20124
    207203         * @dataProvider get_smilies_combinations
    208          * @uses $wpsmiliestrans
    209204         */
    210205        public function test_smilies_combinations( $in_txt, $converted_txt ) {
    211                 global $wpsmiliestrans;
    212 
    213206                // custom smilies, use_smilies: ON
    214207                update_option( 'use_smilies', 1 );
    215208                smilies_init();
     
    236229                        ),
    237230                        array (
    238231                                '8O :) additional text here :)',
    239                                 '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" /> '
     232                                '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" />'
    240233                        ),
    241234                        array (
    242235                                ':) :) :) :)',
    243                                 ' <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" /> '
     236                                '<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" />'
    244237                        ),
    245238                );
    246239        }
     
    255248         */
    256249        public function test_single_smilies_in_wpsmiliestrans( $in_txt, $converted_txt ) {
    257250                global $wpsmiliestrans;
    258                 $orig_trans = $wpsmiliestrans; // save original tranlations array
    259251
    260252                // standard smilies, use_smilies: ON
    261253                update_option( 'use_smilies', 1 );
    262254
     255                if ( !isset( $wpsmiliestrans ) ) {
     256                        smilies_init();
     257                }
     258
     259                $orig_trans = $wpsmiliestrans; // save original tranlations array
     260
    263261                $wpsmiliestrans = array (
    264262                  ':)' => 'icon_smile.gif'
    265263                );
     
    275273
    276274                $wpsmiliestrans = $orig_trans; // reset original translations array
    277275        }
    278 }
    279  No newline at end of file
     276
     277        /**
     278         * Check that $wp_smiliessearch pattern will match smilies
     279         * between spaces, but never capture those spaces.
     280         *
     281         * Further check that spaces aren't randomly deleted
     282         * or added when replacing the text with an image.
     283         *
     284         * @ticket 22692
     285         */
     286        function test_spaces_around_smilies() {
     287                $nbsp = "\xC2\xA0";
     288
     289                // standard smilies, use_smilies: ON
     290                update_option( 'use_smilies', 1 );
     291                smilies_init();
     292
     293                $input  = array();
     294                $output = array();
     295
     296                $input[]  = 'My test :) smile';
     297                $output[] = array('test <img ', 'alt=":)"', ' /> smile');
     298
     299                $input[]  = 'My test ;) smile';
     300                $output[] = array('test <img ', 'alt=";)"', ' /> smile');
     301
     302                $input[]  = 'My test &nbsp;:)&nbsp;smile';
     303                $output[] = array('test &nbsp;<img ', 'alt=":)"', ' />&nbsp;smile');
     304
     305                $input[]  = 'My test &nbsp;;)&nbsp;smile';
     306                $output[] = array('test &nbsp;<img ', 'alt=";)"', ' />&nbsp;smile');
     307
     308                $input[]  = "My test {$nbsp}:){$nbsp}smile";
     309                $output[] = array("test {$nbsp}<img ", 'alt=":)"', " />{$nbsp}smile");
     310
     311                $input[]  = "My test {$nbsp};){$nbsp}smile";
     312                $output[] = array("test {$nbsp}<img ", 'alt=";)"', " />{$nbsp}smile");
     313
     314                foreach($input as $key => $in) {
     315                        $result = convert_smilies( $in );
     316                        foreach($output[$key] as $out) {
     317
     318                                // Each output element must appear in the results.
     319                                $this->assertContains( $out, $result );
     320
     321                        }
     322                }
     323
     324                // standard smilies, use_smilies: OFF
     325                update_option( 'use_smilies', 0 );
     326        }
     327}