VJournalTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace Sabre\VObject\Component;
  3. use Sabre\VObject\Component;
  4. use Sabre\VObject\Reader;
  5. class VJournalTest extends \PHPUnit_Framework_TestCase {
  6. /**
  7. * @dataProvider timeRangeTestData
  8. */
  9. public function testInTimeRange(VJournal $vtodo,$start,$end,$outcome) {
  10. $this->assertEquals($outcome, $vtodo->isInTimeRange($start, $end));
  11. }
  12. public function testValidate() {
  13. $input = <<<HI
  14. BEGIN:VCALENDAR
  15. VERSION:2.0
  16. PRODID:YoYo
  17. BEGIN:VJOURNAL
  18. UID:12345678
  19. DTSTAMP:20140402T174100Z
  20. END:VJOURNAL
  21. END:VCALENDAR
  22. HI;
  23. $obj = Reader::read($input);
  24. $warnings = $obj->validate();
  25. $messages = array();
  26. foreach($warnings as $warning) {
  27. $messages[] = $warning['message'];
  28. }
  29. $this->assertEquals(array(), $messages);
  30. }
  31. public function testValidateBroken() {
  32. $input = <<<HI
  33. BEGIN:VCALENDAR
  34. VERSION:2.0
  35. PRODID:YoYo
  36. BEGIN:VJOURNAL
  37. UID:12345678
  38. DTSTAMP:20140402T174100Z
  39. URL:http://example.org/
  40. URL:http://example.com/
  41. END:VJOURNAL
  42. END:VCALENDAR
  43. HI;
  44. $obj = Reader::read($input);
  45. $warnings = $obj->validate();
  46. $messages = array();
  47. foreach($warnings as $warning) {
  48. $messages[] = $warning['message'];
  49. }
  50. $this->assertEquals(
  51. array("URL MUST NOT appear more than once in a VJOURNAL component"),
  52. $messages
  53. );
  54. }
  55. public function timeRangeTestData() {
  56. $calendar = new VCalendar();
  57. $tests = array();
  58. $vjournal = $calendar->createComponent('VJOURNAL');
  59. $vjournal->DTSTART = '20111223T120000Z';
  60. $tests[] = array($vjournal, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
  61. $tests[] = array($vjournal, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
  62. $vjournal2 = $calendar->createComponent('VJOURNAL');
  63. $vjournal2->DTSTART = '20111223';
  64. $vjournal2->DTSTART['VALUE'] = 'DATE';
  65. $tests[] = array($vjournal2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
  66. $tests[] = array($vjournal2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
  67. $vjournal3 = $calendar->createComponent('VJOURNAL');
  68. $tests[] = array($vjournal3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), false);
  69. $tests[] = array($vjournal3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
  70. return $tests;
  71. }
  72. }