Fix replacing :$, :-$, O:) and O:-) with emoticons (#1490408, #1490409)

pull/280/head
Aleksander Machniak 10 years ago
parent 245619e98d
commit a76693ef4c

@ -3,7 +3,7 @@
"type": "roundcube-plugin",
"description": "Sample plugin to replace emoticons in plain text message body with real icons.",
"license": "GPLv3+",
"version": "1.3",
"version": "1.4",
"authors": [
{
"name": "Thomas Bruederli",

@ -36,8 +36,6 @@ class emoticons extends rcube_plugin
// map of emoticon replacements
$map = array(
'/:\)/' => $this->img_tag('smiley-smile.gif', ':)' ),
'/:-\)/' => $this->img_tag('smiley-smile.gif', ':-)' ),
'/(?<!mailto):D/' => $this->img_tag('smiley-laughing.gif', ':D' ),
'/:-D/' => $this->img_tag('smiley-laughing.gif', ':-D' ),
'/:\(/' => $this->img_tag('smiley-frown.gif', ':(' ),
@ -54,8 +52,10 @@ class emoticons extends rcube_plugin
'/(?<!mailto):-@/i' => $this->img_tag('smiley-yell.gif', ':-@' ),
'/O:\)/i' => $this->img_tag('smiley-innocent.gif', 'O:)' ),
'/O:-\)/i' => $this->img_tag('smiley-innocent.gif', 'O:-)' ),
'/(?<!mailto):$/' => $this->img_tag('smiley-embarassed.gif', ':$' ),
'/(?<!mailto):-$/' => $this->img_tag('smiley-embarassed.gif', ':-$' ),
'/(?<!O):\)/' => $this->img_tag('smiley-smile.gif', ':)' ),
'/(?<!O):-\)/' => $this->img_tag('smiley-smile.gif', ':-)' ),
'/(?<!mailto):\$/' => $this->img_tag('smiley-embarassed.gif', ':$' ),
'/(?<!mailto):-\$/' => $this->img_tag('smiley-embarassed.gif', ':-$' ),
'/(?<!mailto):\*/i' => $this->img_tag('smiley-kiss.gif', ':*' ),
'/(?<!mailto):-\*/i' => $this->img_tag('smiley-kiss.gif', ':-*' ),
'/(?<!mailto):S/i' => $this->img_tag('smiley-undecided.gif', ':S' ),

@ -19,5 +19,45 @@ class Emoticons_Plugin extends PHPUnit_Framework_TestCase
$this->assertInstanceOf('emoticons', $plugin);
$this->assertInstanceOf('rcube_plugin', $plugin);
}
}
/**
* replace() method tests
*/
function test_replace()
{
$rcube = rcube::get_instance();
$plugin = new emoticons($rcube->api);
$map = array(
':D' => array('smiley-laughing.gif', ':D' ),
':-D' => array('smiley-laughing.gif', ':-D' ),
':(' => array('smiley-frown.gif', ':(' ),
':-(' => array('smiley-frown.gif', ':-(' ),
'8)' => array('smiley-cool.gif', '8)' ),
'8-)' => array('smiley-cool.gif', '8-)' ),
':O' => array('smiley-surprised.gif', ':O' ),
':-O' => array('smiley-surprised.gif', ':-O' ),
':P' => array('smiley-tongue-out.gif', ':P' ),
':-P' => array('smiley-tongue-out.gif', ':-P' ),
':@' => array('smiley-yell.gif', ':@' ),
':-@' => array('smiley-yell.gif', ':-@' ),
'O:)' => array('smiley-innocent.gif', 'O:)' ),
'O:-)' => array('smiley-innocent.gif', 'O:-)' ),
':)' => array('smiley-smile.gif', ':)' ),
':-)' => array('smiley-smile.gif', ':-)' ),
':$' => array('smiley-embarassed.gif', ':$' ),
':-$' => array('smiley-embarassed.gif', ':-$' ),
':*' => array('smiley-kiss.gif', ':*' ),
':-*' => array('smiley-kiss.gif', ':-*' ),
':S' => array('smiley-undecided.gif', ':S' ),
':-S' => array('smiley-undecided.gif', ':-S' ),
);
foreach ($map as $body => $expected) {
$args = array('type' => 'plain', 'body' => $body);
$args = $plugin->replace($args);
$this->assertRegExp('/' . preg_quote($expected[0], '/') . '/', $args['body']);
$this->assertRegExp('/title="' . preg_quote($expected[1], '/') . '"/', $args['body']);
}
}
}

Loading…
Cancel
Save