Aleksander Machniak
2012-08-31 4bb0bffefe3d0772f10bfd4acc3e8ccb1193211d
Convert managesieve test scripts to PHPUnit, add them to the suite
12 files deleted
13 files added
2 files modified
763 ■■■■■ changed files
plugins/managesieve/tests/Makefile 7 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/Parser.php 54 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/Tokenizer.php 33 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/parser.phpt 120 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/parser_body.phpt 49 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/parser_imapflags.phpt 28 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/parser_include.phpt 30 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/parser_kep14.phpt 19 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/parser_prefix.phpt 25 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/parser_relational.phpt 25 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/parser_vacation.phpt 39 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/parser_variables.phpt 39 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/parset_subaddress.phpt 38 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/src/parser 52 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/src/parser.out 52 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/src/parser_body 17 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/src/parser_imapflags 7 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/src/parser_include 7 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/src/parser_kep14 2 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/src/parser_prefix 5 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/src/parser_relational 6 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/src/parser_subaddress 11 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/src/parser_vacation 12 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/src/parser_variables 12 ●●●●● patch | view | raw | blame | history
plugins/managesieve/tests/tokenize.phpt 66 ●●●●● patch | view | raw | blame | history
tests/HtmlToText.php 4 ●●●● patch | view | raw | blame | history
tests/phpunit.xml 4 ●●●● patch | view | raw | blame | history
plugins/managesieve/tests/Makefile
File was deleted
plugins/managesieve/tests/Parser.php
New file
@@ -0,0 +1,54 @@
<?php
class Parser extends PHPUnit_Framework_TestCase
{
    function setUp()
    {
        include_once dirname(__FILE__) . '/../lib/rcube_sieve_script.php';
    }
    /**
     * Sieve script parsing
     *
     * @dataProvider data_parser
     */
    function test_parser($input, $output, $message)
    {
        $script = new rcube_sieve_script($input);
        $result = $script->as_text();
        $this->assertEquals(trim($result), trim($output), $message);
    }
    /**
     * Data provider for test_parser()
     */
    function data_parser()
    {
        $dir_path = realpath(dirname(__FILE__) . '/src');
        $dir      = opendir($dir_path);
        $result   = array();
        while ($file = readdir($dir)) {
            if (preg_match('/^[a-z_]+$/', $file)) {
                $input = file_get_contents($dir_path . '/' . $file);
                if (file_exists($dir_path . '/' . $file . '.out')) {
                    $output = file_get_contents($dir_path . '/' . $file . '.out');
                }
                else {
                    $output = $input;
                }
                $result[] = array(
                    'input'   => $input,
                    'output'  => $output,
                    'message' => "Error in parsing '$file' file",
                );
            }
        }
        return $result;
    }
}
plugins/managesieve/tests/Tokenizer.php
New file
@@ -0,0 +1,33 @@
<?php
class Tokenizer extends PHPUnit_Framework_TestCase
{
    function setUp()
    {
        include_once dirname(__FILE__) . '/../lib/rcube_sieve_script.php';
    }
    function data_tokenizer()
    {
        return array(
            array(1, "text: #test\nThis is test ; message;\nMulti line\n.\n;\n", '"This is test ; message;\nMulti line"'),
            array(0, '["test1","test2"]', '[["test1","test2"]]'),
            array(1, '["test"]', '["test"]'),
            array(1, '"te\\"st"', '"te\\"st"'),
            array(0, 'test #comment', '["test"]'),
            array(0, "text:\ntest\n.\ntext:\ntest\n.\n", '["test","test"]'),
            array(1, '"\\a\\\\\\"a"', '"a\\\\\\"a"'),
        );
    }
    /**
     * @dataProvider data_tokenizer
     */
    function test_tokenizer($num, $input, $output)
    {
        $res = json_encode(rcube_sieve_script::tokenize($input, $num));
        $this->assertEquals(trim($res), trim($output));
    }
}
plugins/managesieve/tests/parser.phpt
File was deleted
plugins/managesieve/tests/parser_body.phpt
File was deleted
plugins/managesieve/tests/parser_imapflags.phpt
File was deleted
plugins/managesieve/tests/parser_include.phpt
File was deleted
plugins/managesieve/tests/parser_kep14.phpt
File was deleted
plugins/managesieve/tests/parser_prefix.phpt
File was deleted
plugins/managesieve/tests/parser_relational.phpt
File was deleted
plugins/managesieve/tests/parser_vacation.phpt
File was deleted
plugins/managesieve/tests/parser_variables.phpt
File was deleted
plugins/managesieve/tests/parset_subaddress.phpt
File was deleted
plugins/managesieve/tests/src/parser
New file
@@ -0,0 +1,52 @@
require ["fileinto","reject","envelope"];
# rule:[spam]
if anyof (header :contains "X-DSPAM-Result" "Spam")
{
    fileinto "Spam";
    stop;
}
# rule:[test1]
if anyof (header :comparator "i;ascii-casemap" :contains ["From","To"] "test@domain.tld")
{
    discard;
    stop;
}
# rule:[test2]
if anyof (not header :comparator "i;octet" :contains ["Subject"] "[test]", header :contains "Subject" "[test2]")
{
    fileinto "test";
    stop;
}
# rule:[comments]
if anyof (true) /* comment
 * "comment" #comment */ {
    /* comment */ stop;
# comment
}
# rule:[reject]
if size :over 5000K {
    reject "Message over 5MB size limit. Please contact me before sending this.";
}
# rule:[false]
if false # size :over 5000K
{
    stop; /* rule disabled */
}
# rule:[true]
if true
{
    stop;
}
fileinto "Test";
# rule:[address test]
if address :all :is "From" "nagios@domain.tld"
{
    fileinto "domain.tld";
    stop;
}
# rule:[envelope test]
if envelope :domain :is "From" "domain.tld"
{
    fileinto "domain.tld";
    stop;
}
plugins/managesieve/tests/src/parser.out
New file
@@ -0,0 +1,52 @@
require ["fileinto","reject","envelope"];
# rule:[spam]
if header :contains "X-DSPAM-Result" "Spam"
{
    fileinto "Spam";
    stop;
}
# rule:[test1]
if header :contains ["From","To"] "test@domain.tld"
{
    discard;
    stop;
}
# rule:[test2]
if anyof (not header :comparator "i;octet" :contains "Subject" "[test]", header :contains "Subject" "[test2]")
{
    fileinto "test";
    stop;
}
# rule:[comments]
if true
{
    stop;
}
# rule:[reject]
if size :over 5000K
{
    reject "Message over 5MB size limit. Please contact me before sending this.";
}
# rule:[false]
if false # size :over 5000K
{
    stop;
}
# rule:[true]
if true
{
    stop;
}
fileinto "Test";
# rule:[address test]
if address :all :is "From" "nagios@domain.tld"
{
    fileinto "domain.tld";
    stop;
}
# rule:[envelope test]
if envelope :domain :is "From" "domain.tld"
{
    fileinto "domain.tld";
    stop;
}
plugins/managesieve/tests/src/parser_body
New file
@@ -0,0 +1,17 @@
require ["body","fileinto"];
if body :raw :contains "MAKE MONEY FAST"
{
    stop;
}
if body :content "text" :contains ["missile","coordinates"]
{
    fileinto "secrets";
}
if body :content "audio/mp3" :contains ""
{
    fileinto "jukebox";
}
if body :text :contains "project schedule"
{
    fileinto "project/schedule";
}
plugins/managesieve/tests/src/parser_imapflags
New file
@@ -0,0 +1,7 @@
require ["imap4flags"];
# rule:[imapflags]
if header :matches "Subject" "^Test$"
{
    setflag "\\Seen";
    addflag ["\\Answered","\\Deleted"];
}
plugins/managesieve/tests/src/parser_include
New file
@@ -0,0 +1,7 @@
require ["include"];
include "script.sieve";
# rule:[two]
if true
{
    include :optional "second.sieve";
}
plugins/managesieve/tests/src/parser_kep14
New file
@@ -0,0 +1,2 @@
# EDITOR Roundcube
# EDITOR_VERSION 123
plugins/managesieve/tests/src/parser_prefix
New file
@@ -0,0 +1,5 @@
# this is a comment
# and the second line
require ["variables"];
set "b" "c";
plugins/managesieve/tests/src/parser_relational
New file
@@ -0,0 +1,6 @@
require ["relational","comparator-i;ascii-numeric"];
# rule:[redirect]
if header :value "ge" :comparator "i;ascii-numeric" "X-Spam-score" "14"
{
    redirect "test@test.tld";
}
plugins/managesieve/tests/src/parser_subaddress
New file
@@ -0,0 +1,11 @@
require ["envelope","subaddress","fileinto"];
if envelope :user "To" "postmaster"
{
    fileinto "postmaster";
    stop;
}
if envelope :detail :is "To" "mta-filters"
{
    fileinto "mta-filters";
    stop;
}
plugins/managesieve/tests/src/parser_vacation
New file
@@ -0,0 +1,12 @@
require ["vacation"];
# rule:[test-vacation]
if header :contains "Subject" "vacation"
{
    vacation :days 1 text:
# test
test test /* test */
test
.
;
    stop;
}
plugins/managesieve/tests/src/parser_variables
New file
@@ -0,0 +1,12 @@
require ["variables"];
set "honorific" "Mr";
set "vacation" text:
Dear ${HONORIFIC} ${last_name},
I am out, please leave a message after the meep.
.
;
set :length "b" "${a}";
set :lower "b" "${a}";
set :upperfirst "b" "${a}";
set :upperfirst :lower "b" "${a}";
set :quotewildcard "b" "Rock*";
plugins/managesieve/tests/tokenize.phpt
File was deleted
tests/HtmlToText.php
@@ -8,7 +8,7 @@
class HtmlToText extends PHPUnit_Framework_TestCase
{
    function data()
    function data_html2text()
    {
        return array(
            0 => array(
@@ -45,7 +45,7 @@
    }
    /**
     * @dataProvider data
     * @dataProvider data_html2text
     */
    function test_html2text($title, $in, $out)
    {
tests/phpunit.xml
@@ -29,5 +29,9 @@
            <file>HtmlToText.php</file>
            <file>MailFunc.php</file>
        </testsuite>
        <testsuite name="managesieve">
            <file>./../plugins/managesieve/tests/Parser.php</file>
            <file>./../plugins/managesieve/tests/Tokenizer.php</file>
        </testsuite>
    </testsuites>
</phpunit>