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.

Vacation.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. class Managesieve_Vacation extends PHPUnit_Framework_TestCase
  3. {
  4. function setUp()
  5. {
  6. include_once __DIR__ . '/../lib/Roundcube/rcube_sieve_engine.php';
  7. include_once __DIR__ . '/../lib/Roundcube/rcube_sieve_vacation.php';
  8. }
  9. /**
  10. * Plugin object construction test
  11. */
  12. function test_constructor()
  13. {
  14. $vacation = new rcube_sieve_vacation(true);
  15. $this->assertInstanceOf('rcube_sieve_vacation', $vacation);
  16. }
  17. function test_build_regexp_tests()
  18. {
  19. $tests = rcube_sieve_vacation::build_regexp_tests('2014-02-20', '2014-03-05', $error);
  20. $this->assertCount(2, $tests);
  21. $this->assertSame('header', $tests[0]['test']);
  22. $this->assertSame('regex', $tests[0]['type']);
  23. $this->assertSame('received', $tests[0]['arg1']);
  24. $this->assertSame('(20|21|22|23|24|25|26|27|28) Feb 2014', $tests[0]['arg2']);
  25. $this->assertSame('header', $tests[1]['test']);
  26. $this->assertSame('regex', $tests[1]['type']);
  27. $this->assertSame('received', $tests[1]['arg1']);
  28. $this->assertSame('([ 0]1|[ 0]2|[ 0]3|[ 0]4|[ 0]5) Mar 2014', $tests[1]['arg2']);
  29. $tests = rcube_sieve_vacation::build_regexp_tests('2014-02-20', '2014-01-05', $error);
  30. $this->assertSame(null, $tests);
  31. $this->assertSame('managesieve.invaliddateformat', $error);
  32. }
  33. function test_parse_regexp_tests()
  34. {
  35. $tests = array(
  36. array(
  37. 'test' => 'header',
  38. 'type' => 'regex',
  39. 'arg1' => 'received',
  40. 'arg2' => '(20|21|22|23|24|25|26|27|28) Feb 2014',
  41. ),
  42. array(
  43. 'test' => 'header',
  44. 'type' => 'regex',
  45. 'arg1' => 'received',
  46. 'arg2' => '([ 0]1|[ 0]2|[ 0]3|[ 0]4|[ 0]5) Mar 2014',
  47. )
  48. );
  49. $result = rcube_sieve_vacation::parse_regexp_tests($tests);
  50. $this->assertCount(2, $result);
  51. $this->assertSame('20 Feb 2014', $result['from']);
  52. $this->assertSame('05 Mar 2014', $result['to']);
  53. }
  54. }