diff options
| author | Hugues Hiegel <root@paranoid> | 2015-04-21 12:49:44 +0200 | 
|---|---|---|
| committer | Hugues Hiegel <root@paranoid> | 2015-04-21 12:49:44 +0200 | 
| commit | 733f8e8d0ce6217d906d06dc4fb08e36d48ed794 (patch) | |
| tree | cff28366ff63ea6596f8026e1698090bd0b9405c /plugins/managesieve/tests | |
| parent | ef2e7b3f9d264ec146d4dae257b1e295ab3b462a (diff) | |
| parent | a4ba3df54834ee90fb2c9930669f1229dc80261a (diff) | |
Conflicts:
	composer.json-dist
	config/defaults.inc.php
	plugins
	plugins/acl/acl.js
	plugins/acl/acl.php
	plugins/acl/skins/classic/templates/table.html
	plugins/acl/skins/larry/templates/table.html
	plugins/enigma/README
	plugins/enigma/config.inc.php.dist
	plugins/enigma/enigma.js
	plugins/enigma/enigma.php
	plugins/enigma/lib/enigma_driver.php
	plugins/enigma/lib/enigma_driver_gnupg.php
	plugins/enigma/lib/enigma_driver_phpssl.php
	plugins/enigma/lib/enigma_engine.php
	plugins/enigma/lib/enigma_error.php
	plugins/enigma/lib/enigma_key.php
	plugins/enigma/lib/enigma_signature.php
	plugins/enigma/lib/enigma_subkey.php
	plugins/enigma/lib/enigma_ui.php
	plugins/enigma/lib/enigma_userid.php
	plugins/enigma/localization/en_US.inc
	plugins/enigma/localization/ja_JP.inc
	plugins/enigma/localization/ru_RU.inc
	plugins/enigma/skins/classic/enigma.css
	plugins/enigma/skins/classic/templates/keys.html
	plugins/help/config.inc.php.dist
	plugins/help/help.php
	plugins/help/localization/en_US.inc
	plugins/jqueryui/jqueryui.php
	plugins/managesieve/Changelog
	plugins/managesieve/composer.json
	plugins/managesieve/config.inc.php.dist
	plugins/managesieve/lib/Roundcube/rcube_sieve.php
	plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php
	plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php
	plugins/managesieve/localization/en_US.inc
	plugins/managesieve/managesieve.js
	plugins/managesieve/skins/classic/managesieve.css
	plugins/managesieve/skins/larry/managesieve.css
	plugins/password/README
	plugins/password/config.inc.php.dist
	plugins/password/drivers/ldap.php
	plugins/password/drivers/poppassd.php
	plugins/password/drivers/vpopmaild.php
	plugins/vcard_attachments/vcardattach.js
	plugins/zipdownload/zipdownload.php
Diffstat (limited to 'plugins/managesieve/tests')
23 files changed, 499 insertions, 0 deletions
diff --git a/plugins/managesieve/tests/Managesieve.php b/plugins/managesieve/tests/Managesieve.php new file mode 100644 index 000000000..6e930b81d --- /dev/null +++ b/plugins/managesieve/tests/Managesieve.php @@ -0,0 +1,23 @@ +<?php + +class Managesieve_Plugin extends PHPUnit_Framework_TestCase +{ + +    function setUp() +    { +        include_once __DIR__ . '/../managesieve.php'; +    } + +    /** +     * Plugin object construction test +     */ +    function test_constructor() +    { +        $rcube  = rcube::get_instance(); +        $plugin = new managesieve($rcube->api); + +        $this->assertInstanceOf('managesieve', $plugin); +        $this->assertInstanceOf('rcube_plugin', $plugin); +    } +} + diff --git a/plugins/managesieve/tests/Parser.php b/plugins/managesieve/tests/Parser.php new file mode 100644 index 000000000..33edce0f0 --- /dev/null +++ b/plugins/managesieve/tests/Parser.php @@ -0,0 +1,62 @@ +<?php + +class Parser extends PHPUnit_Framework_TestCase +{ + +    function setUp() +    { +        include_once __DIR__ . '/../lib/Roundcube/rcube_sieve_script.php'; +    } + +    /** +     * Sieve script parsing +     * +     * @dataProvider data_parser +     */ +    function test_parser($input, $output, $message) +    { +        // get capabilities list from the script +        $caps = array(); +        if (preg_match('/require \[([a-z0-9", ]+)\]/', $input, $m)) { +            foreach (explode(',', $m[1]) as $cap) { +                $caps[] = trim($cap, '" '); +            } +        } + +        $script = new rcube_sieve_script($input, $caps); +        $result = $script->as_text(); + +        $this->assertEquals(trim($result), trim($output), $message); +    } + +    /** +     * Data provider for test_parser() +     */ +    function data_parser() +    { +        $dir_path = realpath(__DIR__ . '/src'); +        $dir      = opendir($dir_path); +        $result   = array(); + +        while ($file = readdir($dir)) { +            if (preg_match('/^[a-z0-9_]+$/', $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; +    } +} diff --git a/plugins/managesieve/tests/Tokenizer.php b/plugins/managesieve/tests/Tokenizer.php new file mode 100644 index 000000000..f50ed75b7 --- /dev/null +++ b/plugins/managesieve/tests/Tokenizer.php @@ -0,0 +1,33 @@ +<?php + +class Tokenizer extends PHPUnit_Framework_TestCase +{ + +    function setUp() +    { +        include_once __DIR__ . '/../lib/Roundcube/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)); +    } +} diff --git a/plugins/managesieve/tests/Vacation.php b/plugins/managesieve/tests/Vacation.php new file mode 100644 index 000000000..942525c2f --- /dev/null +++ b/plugins/managesieve/tests/Vacation.php @@ -0,0 +1,66 @@ +<?php + +class Managesieve_Vacation extends PHPUnit_Framework_TestCase +{ + +    function setUp() +    { +        include_once __DIR__ . '/../lib/Roundcube/rcube_sieve_engine.php'; +        include_once __DIR__ . '/../lib/Roundcube/rcube_sieve_vacation.php'; +    } + +    /** +     * Plugin object construction test +     */ +    function test_constructor() +    { +        $vacation = new rcube_sieve_vacation(true); + +        $this->assertInstanceOf('rcube_sieve_vacation', $vacation); +    } + +    function test_build_regexp_tests() +    { +        $tests = rcube_sieve_vacation::build_regexp_tests('2014-02-20', '2014-03-05', $error); + +        $this->assertCount(2, $tests); +        $this->assertSame('header', $tests[0]['test']); +        $this->assertSame('regex', $tests[0]['type']); +        $this->assertSame('received', $tests[0]['arg1']); +        $this->assertSame('(20|21|22|23|24|25|26|27|28) Feb 2014', $tests[0]['arg2']); +        $this->assertSame('header', $tests[1]['test']); +        $this->assertSame('regex', $tests[1]['type']); +        $this->assertSame('received', $tests[1]['arg1']); +        $this->assertSame('([ 0]1|[ 0]2|[ 0]3|[ 0]4|[ 0]5) Mar 2014', $tests[1]['arg2']); + +        $tests = rcube_sieve_vacation::build_regexp_tests('2014-02-20', '2014-01-05', $error); + +        $this->assertSame(null, $tests); +        $this->assertSame('managesieve.invaliddateformat', $error); +    } + +    function test_parse_regexp_tests() +    { +        $tests = array( +            array( +                'test' => 'header', +                'type' => 'regex', +                'arg1' => 'received', +                'arg2' => '(20|21|22|23|24|25|26|27|28) Feb 2014', +            ), +            array( +                'test' => 'header', +                'type' => 'regex', +                'arg1' => 'received', +                'arg2' => '([ 0]1|[ 0]2|[ 0]3|[ 0]4|[ 0]5) Mar 2014', +            ) +        ); + +        $result = rcube_sieve_vacation::parse_regexp_tests($tests); + +        $this->assertCount(2, $result); +        $this->assertSame('20 Feb 2014', $result['from']); +        $this->assertSame('05 Mar 2014', $result['to']); +    } +} + diff --git a/plugins/managesieve/tests/src/parser b/plugins/managesieve/tests/src/parser new file mode 100644 index 000000000..c99b49814 --- /dev/null +++ b/plugins/managesieve/tests/src/parser @@ -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 :contains :comparator "i;ascii-casemap" ["From","To"] "test@domain.tld") +{ +	discard; +	stop; +} +# rule:[test2] +if anyof (not header :contains :comparator "i;octet" ["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; +} diff --git a/plugins/managesieve/tests/src/parser.out b/plugins/managesieve/tests/src/parser.out new file mode 100644 index 000000000..796343d4a --- /dev/null +++ b/plugins/managesieve/tests/src/parser.out @@ -0,0 +1,52 @@ +require ["envelope","fileinto","reject"]; +# 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 :contains :comparator "i;octet" "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 :is "From" "nagios@domain.tld" +{ +	fileinto "domain.tld"; +	stop; +} +# rule:[envelope test] +if envelope :domain :is "From" "domain.tld" +{ +	fileinto "domain.tld"; +	stop; +} diff --git a/plugins/managesieve/tests/src/parser_body b/plugins/managesieve/tests/src/parser_body new file mode 100644 index 000000000..bd142ed8c --- /dev/null +++ b/plugins/managesieve/tests/src/parser_body @@ -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"; +} diff --git a/plugins/managesieve/tests/src/parser_date b/plugins/managesieve/tests/src/parser_date new file mode 100644 index 000000000..06b00333f --- /dev/null +++ b/plugins/managesieve/tests/src/parser_date @@ -0,0 +1,21 @@ +require ["comparator-i;ascii-numeric","date","fileinto","relational"]; +# rule:[date] +if allof (date :originalzone :value "ge" :comparator "i;ascii-numeric" "date" "hour" "09") +{ +	fileinto "urgent"; +} +# rule:[date-weekday] +if date :is "received" "weekday" "0" +{ +	fileinto "weekend"; +} +# rule:[date-zone] +if date :zone "-0500" :value "gt" :comparator "i;ascii-numeric" "received" "iso8601" "2007-02-26T09:00:00-05:00" +{ +	stop; +} +# rule:[currentdate] +if anyof (currentdate :is "weekday" "0", currentdate :value "lt" :comparator "i;ascii-numeric" "hour" "09", currentdate :value "ge" :comparator "i;ascii-numeric" "date" "2007-06-30") +{ +	stop; +} diff --git a/plugins/managesieve/tests/src/parser_enotify_a b/plugins/managesieve/tests/src/parser_enotify_a new file mode 100644 index 000000000..68a9ef5cc --- /dev/null +++ b/plugins/managesieve/tests/src/parser_enotify_a @@ -0,0 +1,19 @@ +require ["enotify","variables"]; +# rule:[notify1] +if header :contains "from" "boss@example.org" +{ +	notify :importance "1" :message "This is probably very important" "mailto:alm@example.com"; +	stop; +} +# rule:[subject] +if header :matches "Subject" "*" +{ +	set "subject" "${1}"; +} +# rule:[from notify2] +if header :matches "From" "*" +{ +	set "from" "${1}"; +	notify :importance "3" :message "${from}: ${subject}" "mailto:alm@example.com"; +} + diff --git a/plugins/managesieve/tests/src/parser_enotify_b b/plugins/managesieve/tests/src/parser_enotify_b new file mode 100644 index 000000000..a3011bac2 --- /dev/null +++ b/plugins/managesieve/tests/src/parser_enotify_b @@ -0,0 +1,18 @@ +require ["enotify","envelope","variables"]; +# rule:[from] +if envelope :matches "from" "*" +{ +	set "env_from" " [really: ${1}]"; +} +# rule:[subject] +if header :matches "Subject" "*" +{ +	set "subject" "${1}"; +} +# rule:[from notify] +if address :matches "from" "*" +{ +	set "from_addr" "${1}"; +	notify :message "${from_addr}${env_from}: ${subject}" "mailto:alm@example.com"; +} + diff --git a/plugins/managesieve/tests/src/parser_imapflags b/plugins/managesieve/tests/src/parser_imapflags new file mode 100644 index 000000000..e67bf7cfc --- /dev/null +++ b/plugins/managesieve/tests/src/parser_imapflags @@ -0,0 +1,7 @@ +require ["imap4flags"]; +# rule:[imapflags] +if header :matches "Subject" "^Test$" +{ +	setflag "\\Seen"; +	addflag ["\\Answered","\\Deleted"]; +} diff --git a/plugins/managesieve/tests/src/parser_include b/plugins/managesieve/tests/src/parser_include new file mode 100644 index 000000000..b5585a4ba --- /dev/null +++ b/plugins/managesieve/tests/src/parser_include @@ -0,0 +1,7 @@ +require ["include"]; +include "script.sieve"; +# rule:[two] +if true +{ +	include :optional "second.sieve"; +} diff --git a/plugins/managesieve/tests/src/parser_index b/plugins/managesieve/tests/src/parser_index new file mode 100644 index 000000000..ca9f86d56 --- /dev/null +++ b/plugins/managesieve/tests/src/parser_index @@ -0,0 +1,24 @@ +require ["comparator-i;ascii-numeric","date","fileinto","index","relational"]; +# rule:[index-header1] +if header :index 1 :last :contains "X-DSPAM-Result" "Spam" +{ +	fileinto "Spam"; +	stop; +} +# rule:[index-header2] +if header :index 2 :contains ["From","To"] "test@domain.tld" +{ +	discard; +	stop; +} +# rule:[index-address] +if address :index 1 :is "From" "nagios@domain.tld" +{ +	fileinto "domain.tld"; +	stop; +} +# rule:[index-date] +if date :index 1 :last :zone "-0500" :value "gt" :comparator "i;ascii-numeric" "received" "iso8601" "2007-02-26T09:00:00-05:00" +{ +	stop; +} diff --git a/plugins/managesieve/tests/src/parser_kep14 b/plugins/managesieve/tests/src/parser_kep14 new file mode 100644 index 000000000..1ded8d8d4 --- /dev/null +++ b/plugins/managesieve/tests/src/parser_kep14 @@ -0,0 +1,2 @@ +# EDITOR Roundcube +# EDITOR_VERSION 123 diff --git a/plugins/managesieve/tests/src/parser_kep14.out b/plugins/managesieve/tests/src/parser_kep14.out new file mode 100644 index 000000000..cb7faa7f8 --- /dev/null +++ b/plugins/managesieve/tests/src/parser_kep14.out @@ -0,0 +1,3 @@ +require ["variables"]; +set "EDITOR" "Roundcube"; +set "EDITOR_VERSION" "123"; diff --git a/plugins/managesieve/tests/src/parser_notify_a b/plugins/managesieve/tests/src/parser_notify_a new file mode 100644 index 000000000..e51e2aa8d --- /dev/null +++ b/plugins/managesieve/tests/src/parser_notify_a @@ -0,0 +1,18 @@ +require ["notify","variables"]; +# rule:[notify1] +if header :contains "from" "boss@example.org" +{ +	notify :low :message "This is probably very important"; +	stop; +} +# rule:[subject] +if header :matches "Subject" "*" +{ +	set "subject" "${1}"; +} +# rule:[from notify2] +if header :matches "From" "*" +{ +	set "from" "${1}"; +	notify :high :method "mailto" :options "test@example.org" :message "${from}: ${subject}"; +} diff --git a/plugins/managesieve/tests/src/parser_notify_b b/plugins/managesieve/tests/src/parser_notify_b new file mode 100644 index 000000000..f942e155f --- /dev/null +++ b/plugins/managesieve/tests/src/parser_notify_b @@ -0,0 +1,17 @@ +require ["envelope","notify","variables"]; +# rule:[from] +if envelope :matches "from" "*" +{ +	set "env_from" " [really: ${1}]"; +} +# rule:[subject] +if header :matches "Subject" "*" +{ +	set "subject" "${1}"; +} +# rule:[from notify] +if address :matches "from" "*" +{ +	set "from_addr" "${1}"; +	notify :method "sms" :options "1234567890" :message "${from_addr}${env_from}: ${subject}"; +} diff --git a/plugins/managesieve/tests/src/parser_prefix b/plugins/managesieve/tests/src/parser_prefix new file mode 100644 index 000000000..9f6a33a1c --- /dev/null +++ b/plugins/managesieve/tests/src/parser_prefix @@ -0,0 +1,5 @@ +# this is a comment +# and the second line + +require ["variables"]; +set "b" "c"; diff --git a/plugins/managesieve/tests/src/parser_relational b/plugins/managesieve/tests/src/parser_relational new file mode 100644 index 000000000..92c5e1a8e --- /dev/null +++ b/plugins/managesieve/tests/src/parser_relational @@ -0,0 +1,6 @@ +require ["comparator-i;ascii-numeric","relational"]; +# rule:[redirect] +if header :value "ge" :comparator "i;ascii-numeric" "X-Spam-score" "14" +{ +	redirect "test@test.tld"; +} diff --git a/plugins/managesieve/tests/src/parser_subaddress b/plugins/managesieve/tests/src/parser_subaddress new file mode 100644 index 000000000..e44555096 --- /dev/null +++ b/plugins/managesieve/tests/src/parser_subaddress @@ -0,0 +1,11 @@ +require ["envelope","fileinto","subaddress"]; +if envelope :user "To" "postmaster" +{ +	fileinto "postmaster"; +	stop; +} +if envelope :detail :is "To" "mta-filters" +{ +	fileinto "mta-filters"; +	stop; +} diff --git a/plugins/managesieve/tests/src/parser_vacation b/plugins/managesieve/tests/src/parser_vacation new file mode 100644 index 000000000..93026db45 --- /dev/null +++ b/plugins/managesieve/tests/src/parser_vacation @@ -0,0 +1,12 @@ +require ["vacation"]; +# rule:[test-vacation] +if header :contains "Subject" "vacation" +{ +	vacation :days 1 text: +# test +test test /* test */ +test +. +; +	stop; +} diff --git a/plugins/managesieve/tests/src/parser_vacation_seconds b/plugins/managesieve/tests/src/parser_vacation_seconds new file mode 100644 index 000000000..75cbcae46 --- /dev/null +++ b/plugins/managesieve/tests/src/parser_vacation_seconds @@ -0,0 +1,12 @@ +require ["vacation-seconds"]; +# rule:[test-vacation] +if header :contains "Subject" "vacation" +{ +	vacation :seconds 0 text: +# test +test test /* test */ +test +. +; +	stop; +} diff --git a/plugins/managesieve/tests/src/parser_variables b/plugins/managesieve/tests/src/parser_variables new file mode 100644 index 000000000..bd5941c02 --- /dev/null +++ b/plugins/managesieve/tests/src/parser_variables @@ -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*";  | 
