Aleksander Machniak
2015-05-28 a76693ef4c57a12e2d09a48948840627f5543817
Fix replacing :$, :-$, O:) and O:-) with emoticons (#1490408, #1490409)
3 files modified
52 ■■■■ changed files
plugins/emoticons/composer.json 2 ●●● patch | view | raw | blame | history
plugins/emoticons/emoticons.php 8 ●●●● patch | view | raw | blame | history
plugins/emoticons/tests/Emoticons.php 42 ●●●●● patch | view | raw | blame | history
plugins/emoticons/composer.json
@@ -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",
plugins/emoticons/emoticons.php
@@ -36,8 +36,6 @@
        // 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 @@
            '/(?<!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'    ),
plugins/emoticons/tests/Emoticons.php
@@ -19,5 +19,45 @@
        $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']);
        }
    }
}