Make WordPress Core


Ignore:
Timestamp:
06/10/2014 02:02:23 AM (10 years ago)
Author:
wonderboymusic
Message:

smilies_init(), treat   like whitespace when converting smilies.

Adds unit tests.

Props miqrogroove.
Fixes #27587.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/Smilies.php

    r28625 r28717  
    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 (
     
    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 );
     
    6260
    6361        $this->assertEquals( $in_txt, convert_smilies($in_txt) );
    64 
    65         unset( $wpsmiliestrans );
    6662    }
    6763
     
    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        );
     
    9793    function test_convert_custom_smilies ( $in_txt, $converted_txt ) {
    9894        global $wpsmiliestrans;
     95
     96        // custom smilies, use_smilies: ON
     97        update_option( 'use_smilies', 1 );
     98
     99        if ( !isset( $wpsmiliestrans ) ) {
     100            smilies_init();
     101        }
     102
    99103        $trans_orig = $wpsmiliestrans; // save original translations array
    100104
    101         // custom smilies, use_smilies: ON
    102         update_option( 'use_smilies', 1 );
    103105        $wpsmiliestrans = array(
    104106          ':PP' => 'icon_tongue.gif',
     
    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
     
    159158        // standard smilies, use_smilies: OFF
    160159        update_option( 'use_smilies', 0 );
    161 
    162         $wpsmiliestrans = $trans_orig; // reset original translations array
    163160    }
    164161
     
    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        );
     
    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 );
     
    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        );
     
    252247    public function test_single_smilies_in_wpsmiliestrans( $in_txt, $converted_txt ) {
    253248        global $wpsmiliestrans;
     249
     250        // standard smilies, use_smilies: ON
     251        update_option( 'use_smilies', 1 );
     252
     253        if ( !isset( $wpsmiliestrans ) ) {
     254            smilies_init();
     255        }
     256
    254257        $orig_trans = $wpsmiliestrans; // save original tranlations array
    255 
    256         // standard smilies, use_smilies: ON
    257         update_option( 'use_smilies', 1 );
    258258
    259259        $wpsmiliestrans = array (
     
    272272        $wpsmiliestrans = $orig_trans; // reset original translations array
    273273    }
     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    }
    274325}
Note: See TracChangeset for help on using the changeset viewer.