<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[26191] trunk: Don't place smilies inside of pre or code tags.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/26191">26191</a></dd>
<dt>Author</dt> <dd>wonderboymusic</dd>
<dt>Date</dt> <dd>2013-11-15 02:45:39 +0000 (Fri, 15 Nov 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>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 <a href="http://core.trac.wordpress.org/ticket/16448">#16448</a>, <a href="http://core.trac.wordpress.org/ticket/20124">#20124</a>, <a href="http://core.trac.wordpress.org/ticket/25303">#25303</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesformattingphp">trunk/src/wp-includes/formatting.php</a></li>
<li><a href="#trunksrcwpincludesfunctionsphp">trunk/src/wp-includes/functions.php</a></li>
<li><a href="#trunktestsphpunittestsformattingSmiliesphp">trunk/tests/phpunit/tests/formatting/Smilies.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesformattingphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/formatting.php (26190 => 26191)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/formatting.php 2013-11-15 02:42:05 UTC (rev 26190)
+++ trunk/src/wp-includes/formatting.php 2013-11-15 02:45:39 UTC (rev 26191)
</span><span class="lines">@@ -1793,18 +1793,36 @@
</span><span class="cx"> * @param string $text Content to convert smilies from text.
</span><span class="cx"> * @return string Converted content with text smilies replaced with images.
</span><span class="cx"> */
</span><del>-function convert_smilies($text) {
</del><ins>+function convert_smilies( $text ) {
</ins><span class="cx"> global $wp_smiliessearch;
</span><span class="cx"> $output = '';
</span><del>- if ( get_option('use_smilies') && !empty($wp_smiliessearch) ) {
</del><ins>+ if ( get_option( 'use_smilies' ) && ! empty( $wp_smiliessearch ) ) {
</ins><span class="cx"> // HTML loop taken from texturize function, could possible be consolidated
</span><del>- $textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
- $stop = count($textarr);// loop stuff
- for ($i = 0; $i < $stop; $i++) {
</del><ins>+ $textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // capture the tags as well as in between
+ $stop = count( $textarr );// loop stuff
+
+ // Ignore proessing of specific tags
+ $tags_to_ignore = 'code|pre|style|script|textarea';
+ $ignore_block_element = '';
+
+ for ( $i = 0; $i < $stop; $i++ ) {
</ins><span class="cx"> $content = $textarr[$i];
</span><del>- if ((strlen($content) > 0) && ('<' != $content[0])) { // If it's not a tag
- $content = preg_replace_callback($wp_smiliessearch, 'translate_smiley', $content);
</del><ins>+
+ // If we're in an ignore block, wait until we find its closing tag
+ if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) ) {
+ $ignore_block_element = $matches[1];
</ins><span class="cx"> }
</span><ins>+
+ // If it's not a tag and not in ignore block
+ if ( '' == $ignore_block_element && strlen( $content ) > 0 && '<' != $content[0] ) {
+ $content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content );
+ }
+
+ // did we exit ignore block
+ if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content ) {
+ $ignore_block_element = '';
+ }
+
</ins><span class="cx"> $output .= $content;
</span><span class="cx"> }
</span><span class="cx"> } else {
</span></span></pre></div>
<a id="trunksrcwpincludesfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/functions.php (26190 => 26191)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/functions.php 2013-11-15 02:42:05 UTC (rev 26190)
+++ trunk/src/wp-includes/functions.php 2013-11-15 02:45:39 UTC (rev 26191)
</span><span class="lines">@@ -2477,6 +2477,7 @@
</span><span class="cx"> return $input;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> /**
</span><span class="cx"> * Convert smiley code to the icon graphic file equivalent.
</span><span class="cx"> *
</span><span class="lines">@@ -2566,7 +2567,7 @@
</span><span class="cx"> */
</span><span class="cx"> krsort($wpsmiliestrans);
</span><span class="cx">
</span><del>- $wp_smiliessearch = '/(?:\s|^)';
</del><ins>+ $wp_smiliessearch = '/((?:\s|^)';
</ins><span class="cx">
</span><span class="cx"> $subchar = '';
</span><span class="cx"> foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
</span><span class="lines">@@ -2576,7 +2577,7 @@
</span><span class="cx"> // new subpattern?
</span><span class="cx"> if ($firstchar != $subchar) {
</span><span class="cx"> if ($subchar != '') {
</span><del>- $wp_smiliessearch .= ')|(?:\s|^)';
</del><ins>+ $wp_smiliessearch .= ')(?=\s|$))|((?:\s|^)'; ;
</ins><span class="cx"> }
</span><span class="cx"> $subchar = $firstchar;
</span><span class="cx"> $wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:';
</span><span class="lines">@@ -2586,7 +2587,8 @@
</span><span class="cx"> $wp_smiliessearch .= preg_quote($rest, '/');
</span><span class="cx"> }
</span><span class="cx">
</span><del>- $wp_smiliessearch .= ')(?:\s|$)/m';
</del><ins>+ $wp_smiliessearch .= ')(?=\s|$))/m';
+
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span></span></pre></div>
<a id="trunktestsphpunittestsformattingSmiliesphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/phpunit/tests/formatting/Smilies.php (26190 => 26191)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/phpunit/tests/formatting/Smilies.php 2013-11-15 02:42:05 UTC (rev 26190)
+++ trunk/tests/phpunit/tests/formatting/Smilies.php 2013-11-15 02:45:39 UTC (rev 26191)
</span><span class="lines">@@ -5,56 +5,99 @@
</span><span class="cx"> */
</span><span class="cx"> class Tests_Formatting_Smilies extends WP_UnitTestCase {
</span><span class="cx">
</span><del>- function test_convert_smilies() {
- global $wpsmiliestrans;
</del><ins>+ /**
+ * Basic Test Content DataProvider
+ *
+ * array ( input_txt, converted_output_txt)
+ */
+ public function get_smilies_input_output() {
</ins><span class="cx"> $includes_path = includes_url("images/smilies/");
</span><span class="cx">
</span><ins>+ return array (
+ array (
+ '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 :?:',
+ '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\' /> '
+ ),
+ array (
+ '<strong>Welcome to the jungle!</strong> We got fun n games! :) We got everything you want 8-) <em>Honey we know the names :)</em>',
+ '<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>'
+ ),
+ array (
+ "<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",
+ "<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"
+ ),
+ array (
+ '<strong style="here comes the sun :-D">and I say it\'s allright:D:D',
+ '<strong style="here comes the sun :-D">and I say it\'s allright:D:D'
+ ),
+ array (
+ '<!-- Woo-hoo, I\'m a comment, baby! :x > -->',
+ '<!-- Woo-hoo, I\'m a comment, baby! :x > -->'
+ ),
+ array (
+ ':?:P:?::-x:mrgreen:::',
+ ':?:P:?::-x:mrgreen:::'
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider get_smilies_input_output
+ *
+ * Basic Validation Test to confirm that smilies are converted to image
+ * when use_smilies = 1 and not when use_smilies = 0
+ */
+ function test_convert_standard_smilies( $in_txt, $converted_txt ) {
+ global $wpsmiliestrans;
+
</ins><span class="cx"> // standard smilies, use_smilies: ON
</span><span class="cx"> update_option( 'use_smilies', 1 );
</span><span class="cx">
</span><span class="cx"> smilies_init();
</span><span class="cx">
</span><del>- $inputs = array(
- '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 :?:',
- '<strong>Welcome to the jungle!</strong> We got fun n games! :) We got everything you want 8-) <em>Honey we know the names :)</em>',
- "<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",
- '<strong style="here comes the sun :-D">and I say it\'s allright:D:D',
- '<!-- Woo-hoo, I\'m a comment, baby! :x > -->',
- ':?:P:?::-x:mrgreen:::', /*
- 'the question is, <textarea>Should smilies be converted in textareas :?:</textarea>',
- 'the question is, <code>Should smilies be converted in code or pre tags :?:</code>',
- 'the question is, <code style="color:#fff">Should smilies be converted in code or pre tags :?:</code>',
- 'the question is, <code>Should smilies be converted in invalid code or pre tags :?:</pre>',
- '<Am I greedy?>Yes I am :)> :) The world makes me :mad:' */
- );
</del><ins>+ $this->assertEquals( $converted_txt, convert_smilies($in_txt) );
</ins><span class="cx">
</span><del>- $outputs = array(
- '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\' /> ',
- '<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>',
- "<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",
- '<strong style="here comes the sun :-D">and I say it\'s allright:D:D',
- '<!-- Woo-hoo, I\'m a comment, baby! :x > -->',
- ' <img src=\''.$includes_path.'icon_question.gif\' alt=\':?:\' class=\'wp-smiley\' /> P:?::-x:mrgreen:::', /*
- 'the question is, <textarea>Should smilies be converted in textareas :?:</textarea>',
- 'the question is, <code>Should smilies be converted in code or pre tags :?:</code>',
- 'the question is, <code style="color:#fff">Should smilies be converted in code or pre tags :?:</code>',
- 'the question is, <code>Should smilies be converted in invalid code or pre tags :?:</pre>',
- '<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\' />' */
- );
</del><ins>+ // standard smilies, use_smilies: OFF
+ update_option( 'use_smilies', 0 );
</ins><span class="cx">
</span><del>- foreach ( $inputs as $k => $input ) {
- $this->assertEquals( $outputs[$k], convert_smilies($input) );
- }
</del><ins>+ $this->assertEquals( $in_txt, convert_smilies($in_txt) );
</ins><span class="cx">
</span><del>- update_option( 'use_smilies', 0 );
</del><ins>+ unset( $wpsmiliestrans );
+ }
</ins><span class="cx">
</span><del>- // standard smilies, use_smilies: OFF
</del><ins>+ /**
+ * Custom Smilies Test Content DataProvider
+ *
+ * array ( input_txt, converted_output_txt)
+ */
+ public function get_custom_smilies_input_output() {
+ $includes_path = includes_url("images/smilies/");
</ins><span class="cx">
</span><del>- foreach ( $inputs as $input ) {
- $this->assertEquals( $input, convert_smilies($input) );
- }
</del><ins>+ return array (
+ 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:',
+ '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\' /> '
+ ),
+ array (
+ '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:',
+ '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\' /> '
+ ),
+ array (
+ ':arrow: monkey: Lorem ipsum dolor sit amet enim. Etiam ullam :PP <br />corper. Suspendisse a pellentesque dui, non felis.<a> :arrow: :arrow</a>',
+ ' <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>'
+ ),
+ );
+ }
</ins><span class="cx">
</span><del>- return;
</del><ins>+ /**
+ * @dataProvider get_custom_smilies_input_output
+ *
+ * Validate Custom Smilies are converted to images when use_smilies = 1
+ * @uses $wpsmiliestrans
+ */
+ function test_convert_custom_smilies ( $in_txt, $converted_txt ) {
+ global $wpsmiliestrans;
+ $trans_orig = $wpsmiliestrans; // save original translations array
</ins><span class="cx">
</span><span class="cx"> // custom smilies, use_smilies: ON
</span><span class="cx"> update_option( 'use_smilies', 1 );
</span><span class="lines">@@ -67,18 +110,169 @@
</span><span class="cx">
</span><span class="cx"> smilies_init();
</span><span class="cx">
</span><del>- $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:',
- '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:',
- ':arrow:monkey:Lorem ipsum dolor sit amet enim. Etiam ullam:PP<br />corper. Suspendisse a pellentesque dui, non felis.<a>:arrow::arrow</a>'
- );
</del><ins>+ $this->assertEquals( $converted_txt, convert_smilies($in_txt) );
</ins><span class="cx">
</span><del>- $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\' />',
- '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\' />',
- '<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>'
- );
</del><ins>+ // standard smilies, use_smilies: OFF
+ update_option( 'use_smilies', 0 );
</ins><span class="cx">
</span><del>- foreach ( $inputs as $k => $input ) {
- $this->assertEquals( $outputs[$k], convert_smilies($input) );
- }
</del><ins>+ $this->assertEquals( $in_txt, convert_smilies($in_txt) );
+
+ $wpsmiliestrans = $trans_orig; // reset original translations array
</ins><span class="cx"> }
</span><del>-}
</del><ins>+
+
+ /**
+ * DataProvider of HTML elements/tags that smilie matches should be ignored in
+ *
+ */
+ public function get_smilies_ignore_tags() {
+ return array (
+ array( 'pre' ),
+ array( 'code' ),
+ array( 'script' ),
+ array( 'style' ),
+ array( 'textarea'),
+ );
+ }
+
+ /**
+ * Validate Conversion of Smilies is ignored in pre-determined tags
+ * pre, code, script, style
+ *
+ * @ticket 16448
+ * @dataProvider get_smilies_ignore_tags
+ * @uses $wpsmiliestrans
+ */
+ public function test_ignore_smilies_in_tags( $element ) {
+ global $wpsmiliestrans;
+ $trans_orig = $wpsmiliestrans; // save original translations array
+
+ $includes_path = includes_url("images/smilies/");
+
+ $in_str = 'Do we ingore smilies ;-) in ' . $element . ' tags <' . $element . '>My Content Here :?: </' . $element . '>';
+ $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 . '>';
+
+ // standard smilies, use_smilies: ON
+ update_option( 'use_smilies', 1 );
+ smilies_init();
+
+ $this->assertEquals( $exp_str, convert_smilies($in_str) );
+
+ // standard smilies, use_smilies: OFF
+ update_option( 'use_smilies', 0 );
+
+ $wpsmiliestrans = $trans_orig; // reset original translations array
+ }
+
+ /**
+ * DataProvider of Smilie Combinations
+ *
+ */
+ public function get_smilies_combinations() {
+ $includes_path = includes_url("images/smilies/");
+
+ return array (
+ array (
+ '8-O :-(',
+ ' <img src=\'' . $includes_path . 'icon_eek.gif\' alt=\'8-O\' class=\'wp-smiley\' /> <img src=\'' . $includes_path . 'icon_sad.gif\' alt=\':-(\' class=\'wp-smiley\' /> '
+ ),
+ array (
+ '8-) 8-O',
+ ' <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\' /> '
+ ),
+ array (
+ '8-) 8O',
+ ' <img src=\'' . $includes_path . 'icon_cool.gif\' alt=\'8-)\' class=\'wp-smiley\' /> <img src=\'' . $includes_path . 'icon_eek.gif\' alt=\'8O\' class=\'wp-smiley\' /> '
+ ),
+ array (
+ '8-) :-(',
+ ' <img src=\'' . $includes_path . 'icon_cool.gif\' alt=\'8-)\' class=\'wp-smiley\' /> <img src=\'' . $includes_path . 'icon_sad.gif\' alt=\':-(\' class=\'wp-smiley\' /> '
+ ),
+ array (
+ '8-) :twisted:',
+ ' <img src=\'' . $includes_path . 'icon_cool.gif\' alt=\'8-)\' class=\'wp-smiley\' /> <img src=\'' . $includes_path . 'icon_twisted.gif\' alt=\':twisted:\' class=\'wp-smiley\' /> '
+ ),
+ array (
+ '8O :twisted: :( :? :(',
+ ' <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\' /> '
+ ),
+ );
+ }
+
+ /**
+ * Validate Combinations of Smilies separated by single space
+ * are converted correctly
+ *
+ * @ticket 20124
+ * @dataProvider get_smilies_combinations
+ * @uses $wpsmiliestrans
+ */
+ public function test_smilies_combinations( $in_txt, $converted_txt ) {
+ global $wpsmiliestrans;
+
+ // custom smilies, use_smilies: ON
+ update_option( 'use_smilies', 1 );
+ smilies_init();
+
+ $this->assertEquals( $converted_txt, convert_smilies($in_txt) );
+
+ // custom smilies, use_smilies: OFF
+ update_option( 'use_smilies', 0 );
+
+ $this->assertEquals( $in_txt, convert_smilies($in_txt) );
+ }
+
+ /**
+ * DataProvider of Single Smilies input and converted output
+ *
+ */
+ public function get_single_smilies_input_output() {
+ $includes_path = includes_url("images/smilies/");
+
+ return array (
+ array (
+ '8-O :-(',
+ '8-O :-('
+ ),
+ array (
+ '8O :) additional text here :)',
+ '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\' /> '
+ ),
+ array (
+ ':) :) :) :)',
+ ' <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\' /> '
+ ),
+ );
+ }
+
+ /**
+ * Validate Smilies are converted for single smilie in
+ * the $wpsmiliestrans global array
+ *
+ * @ticket 25303
+ * @dataProvider get_single_smilies_input_output
+ * @uses $wpsmiliestrans
+ */
+ public function test_single_smilies_in_wpsmiliestrans( $in_txt, $converted_txt ) {
+ global $wpsmiliestrans;
+ $orig_trans = $wpsmiliestrans; // save original tranlations array
+
+ // standard smilies, use_smilies: ON
+ update_option( 'use_smilies', 1 );
+
+ $wpsmiliestrans = array (
+ ':)' => 'icon_smile.gif'
+ );
+
+ smilies_init();
+
+ $this->assertEquals( $converted_txt, convert_smilies($in_txt) );
+
+ // standard smilies, use_smilies: OFF
+ update_option( 'use_smilies', 0 );
+
+ $this->assertEquals( $in_txt, convert_smilies($in_txt) );
+
+ $wpsmiliestrans = $orig_trans; // reset original translations array
+ }
+}
</ins><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>
</body>
</html>