Mercurial > hg > rc1
comparison vendor/sabre/vobject/tests/VObject/Component/VTodoTest.php @ 7:430dbd5346f7
vendor sabre as distributed
| author | Charlie Root |
|---|---|
| date | Sat, 13 Jan 2018 09:06:10 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 6:cec75ba50afc | 7:430dbd5346f7 |
|---|---|
| 1 <?php | |
| 2 | |
| 3 namespace Sabre\VObject\Component; | |
| 4 | |
| 5 use | |
| 6 Sabre\VObject\Component, | |
| 7 Sabre\VObject\Reader; | |
| 8 | |
| 9 class VTodoTest extends \PHPUnit_Framework_TestCase { | |
| 10 | |
| 11 /** | |
| 12 * @dataProvider timeRangeTestData | |
| 13 */ | |
| 14 public function testInTimeRange(VTodo $vtodo,$start,$end,$outcome) { | |
| 15 | |
| 16 $this->assertEquals($outcome, $vtodo->isInTimeRange($start, $end)); | |
| 17 | |
| 18 } | |
| 19 | |
| 20 public function timeRangeTestData() { | |
| 21 | |
| 22 $tests = array(); | |
| 23 | |
| 24 $calendar = new VCalendar(); | |
| 25 | |
| 26 $vtodo = $calendar->createComponent('VTODO'); | |
| 27 $vtodo->DTSTART = '20111223T120000Z'; | |
| 28 $tests[] = array($vtodo, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); | |
| 29 $tests[] = array($vtodo, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); | |
| 30 | |
| 31 $vtodo2 = clone $vtodo; | |
| 32 $vtodo2->DURATION = 'P1D'; | |
| 33 $tests[] = array($vtodo2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); | |
| 34 $tests[] = array($vtodo2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); | |
| 35 | |
| 36 $vtodo3 = clone $vtodo; | |
| 37 $vtodo3->DUE = '20111225'; | |
| 38 $tests[] = array($vtodo3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); | |
| 39 $tests[] = array($vtodo3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); | |
| 40 | |
| 41 $vtodo4 = $calendar->createComponent('VTODO'); | |
| 42 $vtodo4->DUE = '20111225'; | |
| 43 $tests[] = array($vtodo4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); | |
| 44 $tests[] = array($vtodo4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); | |
| 45 | |
| 46 $vtodo5 = $calendar->createComponent('VTODO'); | |
| 47 $vtodo5->COMPLETED = '20111225'; | |
| 48 $tests[] = array($vtodo5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); | |
| 49 $tests[] = array($vtodo5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); | |
| 50 | |
| 51 $vtodo6 = $calendar->createComponent('VTODO'); | |
| 52 $vtodo6->CREATED = '20111225'; | |
| 53 $tests[] = array($vtodo6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); | |
| 54 $tests[] = array($vtodo6, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); | |
| 55 | |
| 56 $vtodo7 = $calendar->createComponent('VTODO'); | |
| 57 $vtodo7->CREATED = '20111225'; | |
| 58 $vtodo7->COMPLETED = '20111226'; | |
| 59 $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); | |
| 60 $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false); | |
| 61 | |
| 62 $vtodo7 = $calendar->createComponent('VTODO'); | |
| 63 $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true); | |
| 64 $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), true); | |
| 65 | |
| 66 return $tests; | |
| 67 | |
| 68 } | |
| 69 | |
| 70 public function testValidate() { | |
| 71 | |
| 72 $input = <<<HI | |
| 73 BEGIN:VCALENDAR | |
| 74 VERSION:2.0 | |
| 75 PRODID:YoYo | |
| 76 BEGIN:VTODO | |
| 77 UID:1234-21355-123156 | |
| 78 DTSTAMP:20140402T183400Z | |
| 79 END:VTODO | |
| 80 END:VCALENDAR | |
| 81 HI; | |
| 82 | |
| 83 $obj = Reader::read($input); | |
| 84 | |
| 85 $warnings = $obj->validate(); | |
| 86 $messages = array(); | |
| 87 foreach($warnings as $warning) { | |
| 88 $messages[] = $warning['message']; | |
| 89 } | |
| 90 | |
| 91 $this->assertEquals(array(), $messages); | |
| 92 | |
| 93 } | |
| 94 | |
| 95 public function testValidateInvalid() { | |
| 96 | |
| 97 $input = <<<HI | |
| 98 BEGIN:VCALENDAR | |
| 99 VERSION:2.0 | |
| 100 PRODID:YoYo | |
| 101 BEGIN:VTODO | |
| 102 END:VTODO | |
| 103 END:VCALENDAR | |
| 104 HI; | |
| 105 | |
| 106 $obj = Reader::read($input); | |
| 107 | |
| 108 $warnings = $obj->validate(); | |
| 109 $messages = array(); | |
| 110 foreach($warnings as $warning) { | |
| 111 $messages[] = $warning['message']; | |
| 112 } | |
| 113 | |
| 114 $this->assertEquals(array( | |
| 115 "UID MUST appear exactly once in a VTODO component", | |
| 116 "DTSTAMP MUST appear exactly once in a VTODO component", | |
| 117 ), $messages); | |
| 118 | |
| 119 } | |
| 120 | |
| 121 public function testValidateDUEDTSTARTMisMatch() { | |
| 122 | |
| 123 $input = <<<HI | |
| 124 BEGIN:VCALENDAR | |
| 125 VERSION:2.0 | |
| 126 PRODID:YoYo | |
| 127 BEGIN:VTODO | |
| 128 UID:FOO | |
| 129 DTSTART;VALUE=DATE-TIME:20140520T131600Z | |
| 130 DUE;VALUE=DATE:20140520 | |
| 131 DTSTAMP;VALUE=DATE-TIME:20140520T131600Z | |
| 132 END:VTODO | |
| 133 END:VCALENDAR | |
| 134 HI; | |
| 135 | |
| 136 $obj = Reader::read($input); | |
| 137 | |
| 138 $warnings = $obj->validate(); | |
| 139 $messages = array(); | |
| 140 foreach($warnings as $warning) { | |
| 141 $messages[] = $warning['message']; | |
| 142 } | |
| 143 | |
| 144 $this->assertEquals(array( | |
| 145 "The value type (DATE or DATE-TIME) must be identical for DUE and DTSTART", | |
| 146 ), $messages); | |
| 147 | |
| 148 } | |
| 149 | |
| 150 public function testValidateDUEbeforeDTSTART() { | |
| 151 | |
| 152 $input = <<<HI | |
| 153 BEGIN:VCALENDAR | |
| 154 VERSION:2.0 | |
| 155 PRODID:YoYo | |
| 156 BEGIN:VTODO | |
| 157 UID:FOO | |
| 158 DTSTART;VALUE=DATE:20140520 | |
| 159 DUE;VALUE=DATE:20140518 | |
| 160 DTSTAMP;VALUE=DATE-TIME:20140520T131600Z | |
| 161 END:VTODO | |
| 162 END:VCALENDAR | |
| 163 HI; | |
| 164 | |
| 165 $obj = Reader::read($input); | |
| 166 | |
| 167 $warnings = $obj->validate(); | |
| 168 $messages = array(); | |
| 169 foreach($warnings as $warning) { | |
| 170 $messages[] = $warning['message']; | |
| 171 } | |
| 172 | |
| 173 $this->assertEquals(array( | |
| 174 "DUE must occur after DTSTART", | |
| 175 ), $messages); | |
| 176 | |
| 177 } | |
| 178 | |
| 179 } | |
| 180 |
