You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Parser.php 1.6KB

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