Fix replacing :$, :-$, O:) and O:-) with emoticons (#1490408, #1490409)
| | |
| | | "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", |
| | |
| | | |
| | | // 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', ':(' ), |
| | |
| | | '/(?<!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' ), |
| | |
| | | $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']); |
| | | } |
| | | } |
| | | } |