WordPress.org

Make WordPress Core

Changeset 26191


Ignore:
Timestamp:
11/15/2013 02:45:39 AM (6 years ago)
Author:
wonderboymusic
Message:

Don't place smilies inside of pre or code tags. Don't skip smilie after a smilie with an 8 in it. Fix regular expression used for smiley translations to work when there is only one registered emoticon.

Props solarissmoke, soulseekah, mdbitz, yonasy. ht to mdbitz for the Unit Tests and a comprehensive patch.
Fixes #16448, #20124, #25303.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r26122 r26191  
    17941794 * @return string Converted content with text smilies replaced with images.
    17951795 */
    1796 function convert_smilies($text) {
     1796function convert_smilies( $text ) {
    17971797    global $wp_smiliessearch;
    17981798    $output = '';
    1799     if ( get_option('use_smilies') && !empty($wp_smiliessearch) ) {
     1799    if ( get_option( 'use_smilies' ) && ! empty( $wp_smiliessearch ) ) {
    18001800        // HTML loop taken from texturize function, could possible be consolidated
    1801         $textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
    1802         $stop = count($textarr);// loop stuff
    1803         for ($i = 0; $i < $stop; $i++) {
     1801        $textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // capture the tags as well as in between
     1802        $stop = count( $textarr );// loop stuff
     1803
     1804        // Ignore proessing of specific tags
     1805        $tags_to_ignore = 'code|pre|style|script|textarea';
     1806        $ignore_block_element = '';
     1807
     1808        for ( $i = 0; $i < $stop; $i++ ) {
    18041809            $content = $textarr[$i];
    1805             if ((strlen($content) > 0) && ('<' != $content[0])) { // If it's not a tag
    1806                 $content = preg_replace_callback($wp_smiliessearch, 'translate_smiley', $content);
     1810
     1811            // If we're in an ignore block, wait until we find its closing tag
     1812            if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) )  {
     1813                $ignore_block_element = $matches[1];
    18071814            }
     1815
     1816            // If it's not a tag and not in ignore block
     1817            if ( '' ==  $ignore_block_element && strlen( $content ) > 0 && '<' != $content[0] ) {
     1818                $content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content );
     1819            }
     1820
     1821            // did we exit ignore block
     1822            if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content )  {
     1823                $ignore_block_element = '';
     1824            }
     1825
    18081826            $output .= $content;
    18091827        }
  • trunk/src/wp-includes/functions.php

    r26031 r26191  
    24782478}
    24792479
     2480
    24802481/**
    24812482 * Convert smiley code to the icon graphic file equivalent.
     
    25672568    krsort($wpsmiliestrans);
    25682569
    2569     $wp_smiliessearch = '/(?:\s|^)';
     2570    $wp_smiliessearch = '/((?:\s|^)';
    25702571
    25712572    $subchar = '';
     
    25772578        if ($firstchar != $subchar) {
    25782579            if ($subchar != '') {
    2579                 $wp_smiliessearch .= ')|(?:\s|^)';
     2580                $wp_smiliessearch .= ')(?=\s|$))|((?:\s|^)'; ;
    25802581            }
    25812582            $subchar = $firstchar;
     
    25872588    }
    25882589
    2589     $wp_smiliessearch .= ')(?:\s|$)/m';
     2590    $wp_smiliessearch .= ')(?=\s|$))/m';
     2591
    25902592}
    25912593
  • trunk/tests/phpunit/tests/formatting/Smilies.php

    r25002 r26191  
    66class Tests_Formatting_Smilies extends WP_UnitTestCase {
    77
    8     function test_convert_smilies() {
    9         global $wpsmiliestrans;
    10         $includes_path = includes_url("images/smilies/");
     8    /**
     9     * Basic Test Content DataProvider
     10     *
     11     * array ( input_txt, converted_output_txt)
     12     */
     13    public function get_smilies_input_output() {
     14        $includes_path = includes_url("images/smilies/");
     15
     16        return array (
     17            array (
     18                '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\' /> '
     20            ),
     21            array (
     22                '<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>'
     24            ),
     25            array (
     26                "<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"
     28            ),
     29            array (
     30                '<strong style="here comes the sun :-D">and I say it\'s allright:D:D',
     31                '<strong style="here comes the sun :-D">and I say it\'s allright:D:D'
     32            ),
     33            array (
     34                '<!-- Woo-hoo, I\'m a comment, baby! :x > -->',
     35                '<!-- Woo-hoo, I\'m a comment, baby! :x > -->'
     36            ),
     37            array (
     38                ':?:P:?::-x:mrgreen:::',
     39                ':?:P:?::-x:mrgreen:::'
     40            ),
     41        );
     42    }
     43
     44    /**
     45     * @dataProvider get_smilies_input_output
     46     *
     47     * Basic Validation Test to confirm that smilies are converted to image
     48     * when use_smilies = 1 and not when use_smilies = 0
     49     */
     50    function test_convert_standard_smilies( $in_txt, $converted_txt ) {
     51        global $wpsmiliestrans;
    1152
    1253        // standard smilies, use_smilies: ON
     
    1556        smilies_init();
    1657
    17         $inputs = array(
    18                         '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                         '<strong>Welcome to the jungle!</strong> We got fun n games! :) We got everything you want 8-) <em>Honey we know the names :)</em>',
    20                         "<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",
    21                         '<strong style="here comes the sun :-D">and I say it\'s allright:D:D',
    22                         '<!-- Woo-hoo, I\'m a comment, baby! :x > -->',
    23                         ':?:P:?::-x:mrgreen:::', /*
    24                         'the question is, <textarea>Should smilies be converted in textareas :?:</textarea>',
    25                         'the question is, <code>Should smilies be converted in code or pre tags :?:</code>',
    26                         'the question is, <code style="color:#fff">Should smilies be converted in code or pre tags :?:</code>',
    27                         'the question is, <code>Should smilies be converted in invalid code or pre tags :?:</pre>',
    28                         '<Am I greedy?>Yes I am :)> :) The world makes me :mad:' */
    29                         );
    30 
    31         $outputs = array(
    32                         '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\' /> ',
    33                         '<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>',
    34                         "<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",
    35                         '<strong style="here comes the sun :-D">and I say it\'s allright:D:D',
    36                         '<!-- Woo-hoo, I\'m a comment, baby! :x > -->',
    37                         ' <img src=\''.$includes_path.'icon_question.gif\' alt=\':?:\' class=\'wp-smiley\' /> P:?::-x:mrgreen:::', /*
    38                         'the question is, <textarea>Should smilies be converted in textareas :?:</textarea>',
    39                         'the question is, <code>Should smilies be converted in code or pre tags :?:</code>',
    40                         'the question is, <code style="color:#fff">Should smilies be converted in code or pre tags :?:</code>',
    41                         'the question is, <code>Should smilies be converted in invalid code or pre tags :?:</pre>',
    42                         '<Am I greedy?>Yes I am <img src=\''.$includes_path.'icon_smile.gif\' alt=\':)\' class=\'wp-smiley\' /> > <img src=\''.$includes_path.'icon_smile.gif\' alt=\':)\' class=\'wp-smiley\' />  The world makes me <img src=\'http://wp-test.php/wp-includes/images/smilies/icon_mad.gif\' alt=\':mad:\' class=\'wp-smiley\' />' */
    43                         );
    44 
    45         foreach ( $inputs as $k => $input ) {
    46             $this->assertEquals( $outputs[$k], convert_smilies($input) );
    47         }
    48 
    49         update_option( 'use_smilies', 0 );
    50 
    51         // standard smilies, use_smilies: OFF
    52 
    53         foreach ( $inputs as $input ) {
    54             $this->assertEquals( $input, convert_smilies($input) );
    55         }
    56 
    57         return;
     58        $this->assertEquals( $converted_txt, convert_smilies($in_txt) );
     59
     60        // standard smilies, use_smilies: OFF
     61        update_option( 'use_smilies', 0 );
     62
     63        $this->assertEquals( $in_txt, convert_smilies($in_txt) );
     64
     65        unset( $wpsmiliestrans );
     66    }
     67
     68    /**
     69     * Custom Smilies Test Content DataProvider
     70     *
     71     * array ( input_txt, converted_output_txt)
     72     */
     73    public function get_custom_smilies_input_output() {
     74        $includes_path = includes_url("images/smilies/");
     75
     76        return array (
     77            array (
     78                '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\' /> '
     80            ),
     81            array (
     82                '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\' /> '
     84            ),
     85            array (
     86                ':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>'
     88            ),
     89        );
     90    }
     91
     92    /**
     93     * @dataProvider get_custom_smilies_input_output
     94     *
     95     * Validate Custom Smilies are converted to images when use_smilies = 1
     96     * @uses $wpsmiliestrans
     97     */
     98    function test_convert_custom_smilies ( $in_txt, $converted_txt ) {
     99        global $wpsmiliestrans;
     100        $trans_orig = $wpsmiliestrans; // save original translations array
    58101
    59102        // custom smilies, use_smilies: ON
     
    68111        smilies_init();
    69112
    70         $inputs = array('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:',
    71                         '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:',
    72                         ':arrow:monkey:Lorem ipsum dolor sit amet enim. Etiam ullam:PP<br />corper. Suspendisse a pellentesque dui, non felis.<a>:arrow::arrow</a>'
    73                         );
    74 
    75         $outputs = array('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=\'icon_arrow\' class=\'wp-smiley\' />',
    76                         'Star Wars Jedi Knight<img src=\''.$includes_path.'icon_arrow.gif\' alt=\'icon_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=\'icon_nervou\' class=\'wp-smiley\' />',
    77                         '<img src=\''.$includes_path.'icon_arrow.gif\' alt=\'icon_arrow\' class=\'wp-smiley\' />monkey:Lorem ipsum dolor sit amet enim. Etiam ullam<img src=\''.$includes_path.'icon_tongue.gif\' alt=\'icon_tongue\' class=\'wp-smiley\' /><br />corper. Suspendisse a pellentesque dui, non felis.<a><img src=\''.$includes_path.'icon_arrow.gif\' alt=\'icon_arrow\' class=\'wp-smiley\' />:arrow</a>'
    78                         );
    79 
    80         foreach ( $inputs as $k => $input ) {
    81             $this->assertEquals( $outputs[$k], convert_smilies($input) );
    82         }
     113        $this->assertEquals( $converted_txt, convert_smilies($in_txt) );
     114
     115        // standard smilies, use_smilies: OFF
     116        update_option( 'use_smilies', 0 );
     117
     118        $this->assertEquals( $in_txt, convert_smilies($in_txt) );
     119
     120        $wpsmiliestrans = $trans_orig; // reset original translations array
     121    }
     122
     123
     124    /**
     125     * DataProvider of HTML elements/tags that smilie matches should be ignored in
     126     *
     127     */
     128    public function get_smilies_ignore_tags() {
     129        return array (
     130            array( 'pre' ),
     131            array( 'code' ),
     132            array( 'script' ),
     133            array( 'style' ),
     134            array( 'textarea'),
     135        );
     136    }
     137
     138    /**
     139     * Validate Conversion of Smilies is ignored in pre-determined tags
     140     * pre, code, script, style
     141     *
     142     * @ticket 16448
     143     * @dataProvider get_smilies_ignore_tags
     144     * @uses $wpsmiliestrans
     145     */
     146    public function test_ignore_smilies_in_tags( $element ) {
     147        global $wpsmiliestrans;
     148        $trans_orig = $wpsmiliestrans;  // save original translations array
     149
     150        $includes_path = includes_url("images/smilies/");
     151
     152        $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 . '>';
     154
     155        // standard smilies, use_smilies: ON
     156        update_option( 'use_smilies', 1 );
     157        smilies_init();
     158
     159        $this->assertEquals( $exp_str, convert_smilies($in_str) );
     160
     161        // standard smilies, use_smilies: OFF
     162        update_option( 'use_smilies', 0 );
     163
     164        $wpsmiliestrans = $trans_orig; // reset original translations array
     165    }
     166
     167    /**
     168     * DataProvider of Smilie Combinations
     169     *
     170     */
     171    public function get_smilies_combinations() {
     172        $includes_path = includes_url("images/smilies/");
     173
     174        return array (
     175            array (
     176                '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\' /> '
     178            ),
     179            array (
     180                '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\' /> '
     182            ),
     183            array (
     184                '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\' /> '
     186            ),
     187            array (
     188                '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\' /> '
     190            ),
     191            array (
     192                '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\' /> '
     194            ),
     195            array (
     196                '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\' /> '
     198            ),
     199        );
     200    }
     201
     202    /**
     203     * Validate Combinations of Smilies separated by single space
     204     * are converted correctly
     205     *
     206     * @ticket 20124
     207     * @dataProvider get_smilies_combinations
     208     * @uses $wpsmiliestrans
     209     */
     210    public function test_smilies_combinations( $in_txt, $converted_txt ) {
     211        global $wpsmiliestrans;
     212
     213        // custom smilies, use_smilies: ON
     214        update_option( 'use_smilies', 1 );
     215        smilies_init();
     216
     217        $this->assertEquals( $converted_txt, convert_smilies($in_txt) );
     218
     219        // custom smilies, use_smilies: OFF
     220        update_option( 'use_smilies', 0 );
     221
     222        $this->assertEquals( $in_txt, convert_smilies($in_txt) );
     223    }
     224
     225    /**
     226     * DataProvider of Single Smilies input and converted output
     227     *
     228     */
     229    public function get_single_smilies_input_output() {
     230        $includes_path = includes_url("images/smilies/");
     231
     232        return array (
     233            array (
     234                '8-O :-(',
     235                '8-O :-('
     236            ),
     237            array (
     238                '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\' /> '
     240            ),
     241            array (
     242                ':) :) :) :)',
     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\' /> '
     244            ),
     245        );
     246    }
     247
     248    /**
     249     * Validate Smilies are converted for single smilie in
     250     * the $wpsmiliestrans global array
     251     *
     252     * @ticket 25303
     253     * @dataProvider get_single_smilies_input_output
     254     * @uses $wpsmiliestrans
     255     */
     256    public function test_single_smilies_in_wpsmiliestrans( $in_txt, $converted_txt ) {
     257        global $wpsmiliestrans;
     258        $orig_trans = $wpsmiliestrans; // save original tranlations array
     259
     260        // standard smilies, use_smilies: ON
     261        update_option( 'use_smilies', 1 );
     262
     263        $wpsmiliestrans = array (
     264          ':)' => 'icon_smile.gif'
     265        );
     266
     267        smilies_init();
     268
     269        $this->assertEquals( $converted_txt, convert_smilies($in_txt) );
     270
     271        // standard smilies, use_smilies: OFF
     272        update_option( 'use_smilies', 0 );
     273
     274        $this->assertEquals( $in_txt, convert_smilies($in_txt) );
     275
     276        $wpsmiliestrans = $orig_trans; // reset original translations array
    83277    }
    84278}
Note: See TracChangeset for help on using the changeset viewer.