Skip to content

Commit

Permalink
Convert managesieve test scripts to PHPUnit, add them to the suite
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Aug 31, 2012
1 parent afa0b1d commit 4bb0bff
Show file tree
Hide file tree
Showing 27 changed files with 276 additions and 487 deletions.
7 changes: 0 additions & 7 deletions plugins/managesieve/tests/Makefile

This file was deleted.

54 changes: 54 additions & 0 deletions plugins/managesieve/tests/Parser.php
@@ -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;
}
}
33 changes: 33 additions & 0 deletions plugins/managesieve/tests/Tokenizer.php
@@ -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));
}
}
120 changes: 0 additions & 120 deletions plugins/managesieve/tests/parser.phpt

This file was deleted.

49 changes: 0 additions & 49 deletions plugins/managesieve/tests/parser_body.phpt

This file was deleted.

28 changes: 0 additions & 28 deletions plugins/managesieve/tests/parser_imapflags.phpt

This file was deleted.

30 changes: 0 additions & 30 deletions plugins/managesieve/tests/parser_include.phpt

This file was deleted.

19 changes: 0 additions & 19 deletions plugins/managesieve/tests/parser_kep14.phpt

This file was deleted.

25 changes: 0 additions & 25 deletions plugins/managesieve/tests/parser_prefix.phpt

This file was deleted.

25 changes: 0 additions & 25 deletions plugins/managesieve/tests/parser_relational.phpt

This file was deleted.

0 comments on commit 4bb0bff

Please sign in to comment.