1<?php 2 3namespace Sabre\VObject; 4 5class FreeBusyDataTest extends \PHPUnit_Framework_TestCase { 6 7 function testGetData() { 8 9 $fb = new FreeBusyData(100, 200); 10 11 $this->assertEquals( 12 [ 13 [ 14 'start' => 100, 15 'end' => 200, 16 'type' => 'FREE', 17 ] 18 ], 19 $fb->getData() 20 ); 21 22 } 23 24 /** 25 * @depends testGetData 26 */ 27 function testAddBeginning() { 28 29 $fb = new FreeBusyData(100, 200); 30 31 // Overwriting the first half 32 $fb->add(100, 150, 'BUSY'); 33 34 35 $this->assertEquals( 36 [ 37 [ 38 'start' => 100, 39 'end' => 150, 40 'type' => 'BUSY', 41 ], 42 [ 43 'start' => 150, 44 'end' => 200, 45 'type' => 'FREE', 46 ] 47 ], 48 $fb->getData() 49 ); 50 51 // Overwriting the first half again 52 $fb->add(100, 150, 'BUSY-TENTATIVE'); 53 54 $this->assertEquals( 55 [ 56 [ 57 'start' => 100, 58 'end' => 150, 59 'type' => 'BUSY-TENTATIVE', 60 ], 61 [ 62 'start' => 150, 63 'end' => 200, 64 'type' => 'FREE', 65 ] 66 ], 67 $fb->getData() 68 ); 69 70 } 71 72 /** 73 * @depends testAddBeginning 74 */ 75 function testAddEnd() { 76 77 $fb = new FreeBusyData(100, 200); 78 79 // Overwriting the first half 80 $fb->add(150, 200, 'BUSY'); 81 82 83 $this->assertEquals( 84 [ 85 [ 86 'start' => 100, 87 'end' => 150, 88 'type' => 'FREE', 89 ], 90 [ 91 'start' => 150, 92 'end' => 200, 93 'type' => 'BUSY', 94 ], 95 ], 96 $fb->getData() 97 ); 98 99 100 } 101 102 /** 103 * @depends testAddEnd 104 */ 105 function testAddMiddle() { 106 107 $fb = new FreeBusyData(100, 200); 108 109 // Overwriting the first half 110 $fb->add(150, 160, 'BUSY'); 111 112 113 $this->assertEquals( 114 [ 115 [ 116 'start' => 100, 117 'end' => 150, 118 'type' => 'FREE', 119 ], 120 [ 121 'start' => 150, 122 'end' => 160, 123 'type' => 'BUSY', 124 ], 125 [ 126 'start' => 160, 127 'end' => 200, 128 'type' => 'FREE', 129 ], 130 ], 131 $fb->getData() 132 ); 133 134 } 135 136 /** 137 * @depends testAddMiddle 138 */ 139 function testAddMultiple() { 140 141 $fb = new FreeBusyData(100, 200); 142 143 $fb->add(110, 120, 'BUSY'); 144 $fb->add(130, 140, 'BUSY'); 145 146 $this->assertEquals( 147 [ 148 [ 149 'start' => 100, 150 'end' => 110, 151 'type' => 'FREE', 152 ], 153 [ 154 'start' => 110, 155 'end' => 120, 156 'type' => 'BUSY', 157 ], 158 [ 159 'start' => 120, 160 'end' => 130, 161 'type' => 'FREE', 162 ], 163 [ 164 'start' => 130, 165 'end' => 140, 166 'type' => 'BUSY', 167 ], 168 [ 169 'start' => 140, 170 'end' => 200, 171 'type' => 'FREE', 172 ], 173 ], 174 $fb->getData() 175 ); 176 177 } 178 179 /** 180 * @depends testAddMultiple 181 */ 182 function testAddMultipleOverlap() { 183 184 $fb = new FreeBusyData(100, 200); 185 186 $fb->add(110, 120, 'BUSY'); 187 $fb->add(130, 140, 'BUSY'); 188 189 $this->assertEquals( 190 [ 191 [ 192 'start' => 100, 193 'end' => 110, 194 'type' => 'FREE', 195 ], 196 [ 197 'start' => 110, 198 'end' => 120, 199 'type' => 'BUSY', 200 ], 201 [ 202 'start' => 120, 203 'end' => 130, 204 'type' => 'FREE', 205 ], 206 [ 207 'start' => 130, 208 'end' => 140, 209 'type' => 'BUSY', 210 ], 211 [ 212 'start' => 140, 213 'end' => 200, 214 'type' => 'FREE', 215 ], 216 ], 217 $fb->getData() 218 ); 219 220 $fb->add(115, 135, 'BUSY-TENTATIVE'); 221 222 $this->assertEquals( 223 [ 224 [ 225 'start' => 100, 226 'end' => 110, 227 'type' => 'FREE', 228 ], 229 [ 230 'start' => 110, 231 'end' => 115, 232 'type' => 'BUSY', 233 ], 234 [ 235 'start' => 115, 236 'end' => 135, 237 'type' => 'BUSY-TENTATIVE', 238 ], 239 [ 240 'start' => 135, 241 'end' => 140, 242 'type' => 'BUSY', 243 ], 244 [ 245 'start' => 140, 246 'end' => 200, 247 'type' => 'FREE', 248 ], 249 ], 250 $fb->getData() 251 ); 252 } 253 254 /** 255 * @depends testAddMultipleOverlap 256 */ 257 function testAddMultipleOverlapAndMerge() { 258 259 $fb = new FreeBusyData(100, 200); 260 261 $fb->add(110, 120, 'BUSY'); 262 $fb->add(130, 140, 'BUSY'); 263 264 $this->assertEquals( 265 [ 266 [ 267 'start' => 100, 268 'end' => 110, 269 'type' => 'FREE', 270 ], 271 [ 272 'start' => 110, 273 'end' => 120, 274 'type' => 'BUSY', 275 ], 276 [ 277 'start' => 120, 278 'end' => 130, 279 'type' => 'FREE', 280 ], 281 [ 282 'start' => 130, 283 'end' => 140, 284 'type' => 'BUSY', 285 ], 286 [ 287 'start' => 140, 288 'end' => 200, 289 'type' => 'FREE', 290 ], 291 ], 292 $fb->getData() 293 ); 294 295 $fb->add(115, 135, 'BUSY'); 296 297 $this->assertEquals( 298 [ 299 [ 300 'start' => 100, 301 'end' => 110, 302 'type' => 'FREE', 303 ], 304 [ 305 'start' => 110, 306 'end' => 140, 307 'type' => 'BUSY', 308 ], 309 [ 310 'start' => 140, 311 'end' => 200, 312 'type' => 'FREE', 313 ], 314 ], 315 $fb->getData() 316 ); 317 } 318} 319