VTodoTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. namespace Sabre\VObject\Component;
  3. use
  4. Sabre\VObject\Component,
  5. Sabre\VObject\Reader;
  6. class VTodoTest extends \PHPUnit_Framework_TestCase {
  7. /**
  8. * @dataProvider timeRangeTestData
  9. */
  10. public function testInTimeRange(VTodo $vtodo,$start,$end,$outcome) {
  11. $this->assertEquals($outcome, $vtodo->isInTimeRange($start, $end));
  12. }
  13. public function timeRangeTestData() {
  14. $tests = array();
  15. $calendar = new VCalendar();
  16. $vtodo = $calendar->createComponent('VTODO');
  17. $vtodo->DTSTART = '20111223T120000Z';
  18. $tests[] = array($vtodo, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
  19. $tests[] = array($vtodo, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
  20. $vtodo2 = clone $vtodo;
  21. $vtodo2->DURATION = 'P1D';
  22. $tests[] = array($vtodo2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
  23. $tests[] = array($vtodo2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
  24. $vtodo3 = clone $vtodo;
  25. $vtodo3->DUE = '20111225';
  26. $tests[] = array($vtodo3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
  27. $tests[] = array($vtodo3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
  28. $vtodo4 = $calendar->createComponent('VTODO');
  29. $vtodo4->DUE = '20111225';
  30. $tests[] = array($vtodo4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
  31. $tests[] = array($vtodo4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
  32. $vtodo5 = $calendar->createComponent('VTODO');
  33. $vtodo5->COMPLETED = '20111225';
  34. $tests[] = array($vtodo5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
  35. $tests[] = array($vtodo5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
  36. $vtodo6 = $calendar->createComponent('VTODO');
  37. $vtodo6->CREATED = '20111225';
  38. $tests[] = array($vtodo6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
  39. $tests[] = array($vtodo6, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
  40. $vtodo7 = $calendar->createComponent('VTODO');
  41. $vtodo7->CREATED = '20111225';
  42. $vtodo7->COMPLETED = '20111226';
  43. $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
  44. $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
  45. $vtodo7 = $calendar->createComponent('VTODO');
  46. $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
  47. $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), true);
  48. return $tests;
  49. }
  50. public function testValidate() {
  51. $input = <<<HI
  52. BEGIN:VCALENDAR
  53. VERSION:2.0
  54. PRODID:YoYo
  55. BEGIN:VTODO
  56. UID:1234-21355-123156
  57. DTSTAMP:20140402T183400Z
  58. END:VTODO
  59. END:VCALENDAR
  60. HI;
  61. $obj = Reader::read($input);
  62. $warnings = $obj->validate();
  63. $messages = array();
  64. foreach($warnings as $warning) {
  65. $messages[] = $warning['message'];
  66. }
  67. $this->assertEquals(array(), $messages);
  68. }
  69. public function testValidateInvalid() {
  70. $input = <<<HI
  71. BEGIN:VCALENDAR
  72. VERSION:2.0
  73. PRODID:YoYo
  74. BEGIN:VTODO
  75. END:VTODO
  76. END:VCALENDAR
  77. HI;
  78. $obj = Reader::read($input);
  79. $warnings = $obj->validate();
  80. $messages = array();
  81. foreach($warnings as $warning) {
  82. $messages[] = $warning['message'];
  83. }
  84. $this->assertEquals(array(
  85. "UID MUST appear exactly once in a VTODO component",
  86. "DTSTAMP MUST appear exactly once in a VTODO component",
  87. ), $messages);
  88. }
  89. public function testValidateDUEDTSTARTMisMatch() {
  90. $input = <<<HI
  91. BEGIN:VCALENDAR
  92. VERSION:2.0
  93. PRODID:YoYo
  94. BEGIN:VTODO
  95. UID:FOO
  96. DTSTART;VALUE=DATE-TIME:20140520T131600Z
  97. DUE;VALUE=DATE:20140520
  98. DTSTAMP;VALUE=DATE-TIME:20140520T131600Z
  99. END:VTODO
  100. END:VCALENDAR
  101. HI;
  102. $obj = Reader::read($input);
  103. $warnings = $obj->validate();
  104. $messages = array();
  105. foreach($warnings as $warning) {
  106. $messages[] = $warning['message'];
  107. }
  108. $this->assertEquals(array(
  109. "The value type (DATE or DATE-TIME) must be identical for DUE and DTSTART",
  110. ), $messages);
  111. }
  112. public function testValidateDUEbeforeDTSTART() {
  113. $input = <<<HI
  114. BEGIN:VCALENDAR
  115. VERSION:2.0
  116. PRODID:YoYo
  117. BEGIN:VTODO
  118. UID:FOO
  119. DTSTART;VALUE=DATE:20140520
  120. DUE;VALUE=DATE:20140518
  121. DTSTAMP;VALUE=DATE-TIME:20140520T131600Z
  122. END:VTODO
  123. END:VCALENDAR
  124. HI;
  125. $obj = Reader::read($input);
  126. $warnings = $obj->validate();
  127. $messages = array();
  128. foreach($warnings as $warning) {
  129. $messages[] = $warning['message'];
  130. }
  131. $this->assertEquals(array(
  132. "DUE must occur after DTSTART",
  133. ), $messages);
  134. }
  135. }