/usr/share/php/tests/Horde_Icalendar/Horde/Icalendar/FreeBusyTest.php is in php-horde-icalendar 2.0.7-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | <?php
/**
* @category Horde
* @package Icalendar
* @subpackage UnitTests
*/
/**
* @category Horde
* @package Icalendar
* @subpackage UnitTests
*/
class Horde_Icalendar_FreeBusyTest extends Horde_Test_Case
{
public function testRead()
{
$ical = new Horde_Icalendar();
$ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/vfreebusy1.ics'));
// Get the vFreeBusy component
$vfb = $ical->getComponent(0);
// Dump the type
$this->assertEquals(
'vFreebusy',
$vfb->getType()
);
// Dump the vfreebusy component again (the duration should be
// converted to start/end
$this->assertStringEqualsFile(
__DIR__ . '/fixtures/vfreebusy2.ics',
$vfb->exportvCalendar()
);
// Dump organizer name
$this->assertEquals(
'GunnarWrobel',
$vfb->getName()
);
// Dump organizer mail
$this->assertEquals(
'wrobel@demo2.pardus.de',
$vfb->getEmail()
);
// Dump busy periods
$this->assertEquals(
array(
1164258000 => 1164261600,
1164268800 => 1164276000
),
$vfb->getBusyPeriods()
);
// Decode the summary information
$extra = $vfb->getExtraParams();
$this->assertEquals(
'testtermin',
base64_decode($extra[1164258000]['X-SUMMARY'])
);
// Dump the free periods in between the two given time stamps
$this->assertEquals(
array(
1164261600 => 1164268800,
),
$vfb->getFreePeriods(1164261500, 1164268900)
);
// Dump start of the free/busy information
$this->assertEquals(
1164236400,
$vfb->getStart()
);
// Dump end of the free/busy information
$this->assertEquals(
1169420400,
$vfb->getEnd()
);
// Free periods don't get added
$vfb->addBusyPeriod('FREE', 1164261600, 1164268800);
$this->assertEquals(
array(
1164258000 => 1164261600,
1164268800 => 1164276000
),
$vfb->getBusyPeriods()
);
// Add a busy period with start/end (11:00 / 12:00)
$vfb->addBusyPeriod('BUSY', 1164279600, 1164283200);
// Add a busy period with start/duration (14:00 / 2h)
$vfb->addBusyPeriod('BUSY', 1164290400, null, 7200, array('X-SUMMARY' => 'dGVzdA==')
);
// Dump busy periods
$this->assertEquals(
array(
1164258000 => 1164261600,
1164268800 => 1164276000,
1164279600 => 1164283200,
1164290400 => 1164297600,
),
$vfb->getBusyPeriods()
);
// Dump the extra parameters
$this->assertEquals(
array(
1164258000 => array(
'X-UID' => 'MmZlNWU3NDRmMGFjNjZkNjRjZjFkZmFmYTE4NGFiZTQ=',
'X-SUMMARY' => 'dGVzdHRlcm1pbg=='
),
1164268800 => array(),
1164279600 => array(),
1164290400 => array('X-SUMMARY' => 'dGVzdA=='),
),
$vfb->getExtraParams()
);
return $vfb;
}
/**
* @depends testRead
*/
public function testMerge($vfb)
{
// Create new freebusy object for merging
$mfb = new Horde_Icalendar_Vfreebusy();
// 1. 3:55 / 10 minutes; summary "test4"
$mfb->addBusyPeriod('BUSY', 1164254100, null, 600,
array('X-SUMMARY' => 'dGVzdDQ='));
// 2. 4:00 / 1 hours 5 Minutes; summary "test3"
$mfb->addBusyPeriod('BUSY', 1164254400, null, 3900,
array('X-SUMMARY' => 'dGVzdDM='));
// 3. 5:55 / 10 minutes hours; summary "test5"
$mfb->addBusyPeriod('BUSY', 1164261300, null, 600,
array('X-SUMMARY' => 'dGVzdDU=='));
// 4. 7:55 / 10 min
$mfb->addBusyPeriod('BUSY', 1164268500, null, 600);
// 5. 9:55 / 10 min
$mfb->addBusyPeriod('BUSY', 1164275700, null, 600);
// 6. 11:00 / 4 hours; summary "test2"
$mfb->addBusyPeriod('BUSY', 1164279600, null, 14400,
array('X-SUMMARY' => 'dGVzdDI='));
// 7. 14:00 / 2 min
$mfb->addBusyPeriod('BUSY', 1164290400, null, 120);
// 8. 14:30 / 5 min; summary "test3"
$mfb->addBusyPeriod('BUSY', 1164292200, null, 300,
array('X-SUMMARY' => 'dGVzdDM='));
// 9. 15:55 / 5 min
$mfb->addBusyPeriod('BUSY', 1164297300, 1164297600);
// Dump busy periods
$this->assertEquals(
array(
1164254100 => 1164254700,
1164254400 => 1164258300,
1164261300 => 1164261900,
1164268500 => 1164269100,
1164275700 => 1164276300,
1164279600 => 1164294000,
1164290400 => 1164290520,
1164292200 => 1164292500,
1164297300 => 1164297600,
),
$mfb->getBusyPeriods()
);
$mfb->setAttribute('DTSTART', 1004297300);
$mfb->setAttribute('DTEND', 1014297300);
// Merge freebusy components without simplification
$vfb->merge($mfb, false);
$this->assertEquals(
1004297300,
$vfb->getAttribute('DTSTART')
);
$this->assertEquals(
1169420400,
$vfb->getAttribute('DTEND')
);
// Merged periods (there are some entries having the same start time ->
// merged to longer of the two)
$busy = $vfb->getBusyPeriods();
$extra = $vfb->getExtraParams();
$this->assertEquals(
array(
1164258000 => 1164261600,
1164268800 => 1164276000,
1164279600 => 1164294000,
1164290400 => 1164297600,
1164254100 => 1164254700,
1164254400 => 1164258300,
1164261300 => 1164261900,
1164268500 => 1164269100,
1164275700 => 1164276300,
1164292200 => 1164292500,
1164297300 => 1164297600,
),
$busy
);
// Check merging process (should have selected longer period)
// and dump extra information alongside
// 4 hours (instead of 2 hours)
$this->assertEquals(
14400,
$busy[1164279600] - 1164279600
);
$this->assertEquals(
'test2',
base64_decode($extra[1164279600]['X-SUMMARY'])
);
// 2 hours (instead of 2 minutes)
$this->assertEquals(
7200,
$busy[1164290400] - 1164290400
);
$this->assertEquals(
'test',
base64_decode($extra[1164290400]['X-SUMMARY'])
);
// Merge freebusy components again, simplify this time
$vfb->merge($mfb);
// Dump merged periods
$busy = $vfb->getBusyPeriods();
$extra = $vfb->getExtraParams();
// 1. 3:55 / 10 Minutes / test4
$this->assertEquals(
'20061123T035500Z',
$vfb->_exportDateTime(1164254100)
);
$this->assertEquals(
'20061123T040500Z',
$vfb->_exportDateTime($busy[1164254100])
);
$this->assertEquals(
'test4',
base64_decode($extra[1164254100]['X-SUMMARY'])
);
// 2. 4:05 / 1 hour / test3
$this->assertEquals(
'20061123T040500Z',
$vfb->_exportDateTime(1164254700)
);
$this->assertEquals(
'20061123T050500Z',
$vfb->_exportDateTime($busy[1164254700])
);
$this->assertEquals(
'test3',
base64_decode($extra[1164254700]['X-SUMMARY'])
);
// 3. 5:05 / 55 Minutes / testtermin
$this->assertEquals(
'20061123T050500Z',
$vfb->_exportDateTime(1164258300)
);
$this->assertEquals(
'20061123T060000Z',
$vfb->_exportDateTime($busy[1164258300])
);
$this->assertEquals(
'testtermin',
base64_decode($extra[1164258300]['X-SUMMARY'])
);
// 4. 6:00 / 5 Minutes / test5
$this->assertEquals(
'20061123T060000Z',
$vfb->_exportDateTime(1164261600)
);
$this->assertEquals(
'20061123T060500Z',
$vfb->_exportDateTime($busy[1164261600])
);
$this->assertEquals(
'test5',
base64_decode($extra[1164261600]['X-SUMMARY'])
);
// 5. 7:55 / 2 hours 10 Minutes
$this->assertEquals(
'20061123T075500Z',
$vfb->_exportDateTime(1164268500)
);
$this->assertEquals(
'20061123T100500Z',
$vfb->_exportDateTime($busy[1164268500])
);
$this->assertArrayNotHasKey(
'X-SUMMARY',
$extra[1164268500]
);
// 6. 11:00 / 4 hours / test2
$this->assertEquals(
'20061123T110000Z',
$vfb->_exportDateTime(1164279600)
);
$this->assertEquals(
'20061123T150000Z',
$vfb->_exportDateTime($busy[1164279600])
);
$this->assertEquals(
'test2',
base64_decode($extra[1164279600]['X-SUMMARY'])
);
// 7. 15:00 / 1 hour / test
$this->assertEquals(
'20061123T150000Z',
$vfb->_exportDateTime(1164294000)
);
$this->assertEquals(
'20061123T160000Z',
$vfb->_exportDateTime($busy[1164294000])
);
$this->assertEquals(
'test',
base64_decode($extra[1164294000]['X-SUMMARY'])
);
}
}
|