commit | author | age
|
4bb0bf
|
1 |
<?php |
AM |
2 |
|
|
3 |
class Parser extends PHPUnit_Framework_TestCase |
|
4 |
{ |
|
5 |
|
|
6 |
function setUp() |
|
7 |
{ |
0ea079
|
8 |
include_once __DIR__ . '/../lib/Roundcube/rcube_sieve_script.php'; |
4bb0bf
|
9 |
} |
AM |
10 |
|
|
11 |
/** |
|
12 |
* Sieve script parsing |
|
13 |
* |
|
14 |
* @dataProvider data_parser |
|
15 |
*/ |
|
16 |
function test_parser($input, $output, $message) |
|
17 |
{ |
7641e4
|
18 |
// get capabilities list from the script |
AM |
19 |
$caps = array(); |
|
20 |
if (preg_match('/require \[([a-z0-9", ]+)\]/', $input, $m)) { |
|
21 |
foreach (explode(',', $m[1]) as $cap) { |
|
22 |
$caps[] = trim($cap, '" '); |
|
23 |
} |
|
24 |
} |
|
25 |
|
|
26 |
$script = new rcube_sieve_script($input, $caps); |
4bb0bf
|
27 |
$result = $script->as_text(); |
AM |
28 |
|
|
29 |
$this->assertEquals(trim($result), trim($output), $message); |
|
30 |
} |
|
31 |
|
|
32 |
/** |
|
33 |
* Data provider for test_parser() |
|
34 |
*/ |
|
35 |
function data_parser() |
|
36 |
{ |
0ea079
|
37 |
$dir_path = realpath(__DIR__ . '/src'); |
4bb0bf
|
38 |
$dir = opendir($dir_path); |
AM |
39 |
$result = array(); |
|
40 |
|
|
41 |
while ($file = readdir($dir)) { |
1d8e86
|
42 |
if (preg_match('/^[a-z0-9_]+$/', $file)) { |
4bb0bf
|
43 |
$input = file_get_contents($dir_path . '/' . $file); |
AM |
44 |
|
|
45 |
if (file_exists($dir_path . '/' . $file . '.out')) { |
|
46 |
$output = file_get_contents($dir_path . '/' . $file . '.out'); |
|
47 |
} |
|
48 |
else { |
|
49 |
$output = $input; |
|
50 |
} |
|
51 |
|
|
52 |
$result[] = array( |
|
53 |
'input' => $input, |
|
54 |
'output' => $output, |
|
55 |
'message' => "Error in parsing '$file' file", |
|
56 |
); |
|
57 |
} |
|
58 |
} |
|
59 |
|
|
60 |
return $result; |
|
61 |
} |
|
62 |
} |