[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Defines test class to test manage rrule during ical imports. 19 * 20 * @package core_calendar 21 * @category test 22 * @copyright 2014 onwards Ankit Agarwal <[email protected]> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 class core_calendar_rrule_manager_testcase extends advanced_testcase { 26 27 /** @var stdClass a dummy event */ 28 protected $event; 29 30 /** @var string system timezone */ 31 protected $tz; 32 33 /** 34 * Set up method. 35 */ 36 protected function setUp() { 37 global $DB; 38 $this->resetAfterTest(); 39 $this->tz = date_default_timezone_get(); 40 date_default_timezone_set('Australia/Perth'); 41 42 $user = $this->getDataGenerator()->create_user(); 43 $sub = new stdClass(); 44 $sub->url = ''; 45 $sub->courseid = 0; 46 $sub->groupid = 0; 47 $sub->userid = $user->id; 48 $sub->pollinterval = 0; 49 $subid = $DB->insert_record('event_subscriptions', $sub, true); 50 51 $event = new stdClass(); 52 $event->name = 'Event name'; 53 $event->description = ''; 54 $event->timestart = 1385913700; // A 2013-12-2 Monday event. 55 $event->timeduration = 3600; 56 $event->uuid = 'uuid'; 57 $event->subscriptionid = $subid; 58 $event->userid = $user->id; 59 $event->groupid = 0; 60 $event->courseid = 0; 61 $event->eventtype = 'user'; 62 $eventobj = calendar_event::create($event, false); 63 $DB->set_field('event', 'repeatid', $eventobj->id, array('id' => $eventobj->id)); 64 $eventobj->repeatid = $eventobj->id; 65 $this->event = $eventobj; 66 } 67 68 /** 69 * Tear down method. 70 */ 71 protected function tearDown() { 72 date_default_timezone_set($this->tz); 73 } 74 75 /** 76 * Test parse_rrule() method. 77 */ 78 public function test_parse_rrule() { 79 80 $rrule = "FREQ=DAILY;COUNT=3;INTERVAL=4;BYSECOND=20,40;BYMINUTE=2,30;BYHOUR=3,4;BYDAY=MO,TH;BYMONTHDAY=20, 81 30;BYYEARDAY=300,-20;BYWEEKNO=22,33;BYMONTH=3,4"; 82 $mang = new core_tests_calendar_rrule_manager($rrule); 83 $mang->parse_rrule(); 84 $this->assertEquals(\core_calendar\rrule_manager::FREQ_DAILY, $mang->freq); 85 $this->assertEquals(3, $mang->count); 86 $this->assertEquals(4, $mang->interval); 87 $this->assertEquals(array(20, 40), $mang->bysecond); 88 $this->assertEquals(array(2, 30), $mang->byminute); 89 $this->assertEquals(array(3, 4), $mang->byhour); 90 $this->assertEquals(array('MO', 'TH'), $mang->byday); 91 $this->assertEquals(array(20, 30), $mang->bymonthday); 92 $this->assertEquals(array(300, -20), $mang->byyearday); 93 $this->assertEquals(array(22, 33), $mang->byweekno); 94 $this->assertEquals(array(3, 4), $mang->bymonth); 95 } 96 97 /** 98 * Test exception is thrown for invalid property. 99 */ 100 public function test_parse_rrule_validation() { 101 102 $rrule = "RANDOM=PROPERTY;"; 103 $this->setExpectedException('moodle_exception'); 104 $mang = new core_tests_calendar_rrule_manager($rrule); 105 $mang->parse_rrule(); 106 } 107 108 /** 109 * Test exception is thrown for invalid frequency. 110 */ 111 public function test_freq_validation() { 112 113 $rrule = "FREQ=RANDOMLY;"; 114 $this->setExpectedException('moodle_exception'); 115 $mang = new core_tests_calendar_rrule_manager($rrule); 116 $mang->parse_rrule(); 117 } 118 119 /** 120 * Test recurrence rules for daily frequency. 121 */ 122 public function test_daily_events() { 123 global $DB; 124 125 $rrule = 'FREQ=DAILY;COUNT=3'; // This should generate 2 child events + 1 parent. 126 $mang = new \core_calendar\rrule_manager($rrule); 127 $mang->parse_rrule(); 128 $mang->create_events($this->event); 129 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 130 $this->assertEquals(3, $count); 131 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 132 'timestart' => ($this->event->timestart + DAYSECS))); 133 $this->assertTrue($result); 134 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 135 'timestart' => ($this->event->timestart + 2 * DAYSECS))); 136 $this->assertTrue($result); 137 138 $until = $this->event->timestart + DAYSECS * 2; 139 $until = date('Y-m-d', $until); 140 $rrule = "FREQ=DAILY;UNTIL=$until"; // This should generate 1 child event + 1 parent,since by then until bound would be hit. 141 $mang = new \core_calendar\rrule_manager($rrule); 142 $mang->parse_rrule(); 143 $mang->create_events($this->event); 144 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 145 $this->assertEquals(2, $count); 146 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 147 'timestart' => ($this->event->timestart + DAYSECS))); 148 $this->assertTrue($result); 149 150 $rrule = 'FREQ=DAILY;COUNT=3;INTERVAL=3'; // This should generate 2 child events + 1 parent, every 3rd day. 151 $mang = new \core_calendar\rrule_manager($rrule); 152 $mang->parse_rrule(); 153 $mang->create_events($this->event); 154 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 155 $this->assertEquals(3, $count); 156 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 157 'timestart' => ($this->event->timestart + 3 * DAYSECS))); 158 $this->assertTrue($result); 159 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 160 'timestart' => ($this->event->timestart + 6 * DAYSECS))); 161 $this->assertTrue($result); 162 163 // Forever event. This should generate events for time() + 10 year period, every 300th day. 164 $rrule = 'FREQ=DAILY;INTERVAL=300'; 165 $mang = new \core_calendar\rrule_manager($rrule); 166 $until = time() + (YEARSECS * $mang::TIME_UNLIMITED_YEARS); 167 $mang->parse_rrule(); 168 $mang->create_events($this->event); 169 for ($i = 0, $time = $this->event->timestart; $time < $until; $i++, $time = $this->event->timestart + 300 * DAYSECS * $i) { 170 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 171 'timestart' => ($time))); 172 $this->assertTrue($result); 173 } 174 } 175 176 /** 177 * Test recurrence rules for weekly frequency. 178 */ 179 public function test_weekly_events() { 180 global $DB; 181 182 $rrule = 'FREQ=WEEKLY;COUNT=1'; // This should generate 7 events in total, one for each day. 183 $mang = new \core_calendar\rrule_manager($rrule); 184 $mang->parse_rrule(); 185 $mang->create_events($this->event); 186 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 187 $this->assertEquals(7, $count); 188 for ($i = 0; $i < 7; $i++) { 189 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 190 'timestart' => ($this->event->timestart + $i * DAYSECS))); 191 $this->assertTrue($result); 192 } 193 194 // This should generate 4 child event + 1 parent, since by then until bound would be hit. 195 $until = $this->event->timestart + WEEKSECS * 4; 196 $until = date('YmdThis', $until); 197 $rrule = "FREQ=WEEKLY;BYDAY=MO;UNTIL=$until"; 198 $mang = new \core_calendar\rrule_manager($rrule); 199 $mang->parse_rrule(); 200 $mang->create_events($this->event); 201 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 202 $this->assertEquals(5, $count); 203 for ($i = 0; $i < 5; $i++) { 204 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 205 'timestart' => ($this->event->timestart + $i * WEEKSECS))); 206 $this->assertTrue($result); 207 } 208 209 // This should generate 4 events in total every monday and Wednesday of every 3rd week. 210 $rrule = 'FREQ=WEEKLY;INTERVAL=3;BYDAY=MO,WE;COUNT=2'; 211 $mang = new \core_calendar\rrule_manager($rrule); 212 $mang->parse_rrule(); 213 $mang->create_events($this->event); 214 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 215 $this->assertEquals(4, $count); 216 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 217 'timestart' => ($this->event->timestart + 3 * WEEKSECS))); // Monday event. 218 $this->assertTrue($result); 219 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 220 'timestart' => ($this->event->timestart + 2 * DAYSECS))); // Wednesday event. 221 $this->assertTrue($result); 222 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 223 'timestart' => ($this->event->timestart + 3 * WEEKSECS + 2 * DAYSECS))); // Wednesday event. 224 $this->assertTrue($result); 225 226 // Forever event. This should generate events over time() + 10 year period, every 50th monday. 227 $rrule = 'FREQ=WEEKLY;BYDAY=MO;INTERVAL=50'; 228 $mang = new \core_calendar\rrule_manager($rrule); 229 $until = time() + (YEARSECS * $mang::TIME_UNLIMITED_YEARS); 230 $mang->parse_rrule(); 231 $mang->create_events($this->event); 232 for ($i = 0, $time = $this->event->timestart; $time < $until; $i++, $time = $this->event->timestart + 50 * WEEKSECS * $i) { 233 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 234 'timestart' => ($time))); 235 $this->assertTrue($result); 236 } 237 } 238 239 /** 240 * Test recurrence rules for monthly frequency. 241 */ 242 public function test_monthly_events() { 243 global $DB; 244 $rrule = 'FREQ=MONTHLY;COUNT=3;BYMONTHDAY=2'; // This should generate 3 events in total. 245 $mang = new \core_calendar\rrule_manager($rrule); 246 $mang->parse_rrule(); 247 $mang->create_events($this->event); 248 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 249 $this->assertEquals(3, $count); 250 for ($i = 0; $i < 3; $i++) { 251 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 252 'timestart' => (strtotime("+$i month", $this->event->timestart)))); 253 $this->assertTrue($result); 254 } 255 256 // This much seconds after the start of the day. 257 $offset = $this->event->timestart - mktime(0, 0, 0, date("n", $this->event->timestart), date("j", $this->event->timestart), 258 date("Y", $this->event->timestart)); 259 $monthstart = mktime(0, 0, 0, date("n", $this->event->timestart), 1, date("Y", $this->event->timestart)); 260 261 $rrule = 'FREQ=MONTHLY;COUNT=3;BYDAY=1MO'; // This should generate 3 events in total, first monday of the month. 262 $mang = new \core_calendar\rrule_manager($rrule); 263 $mang->parse_rrule(); 264 $mang->create_events($this->event); 265 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 266 $this->assertEquals(3, $count); 267 $time = strtotime('1 Monday', strtotime("+1 months", $monthstart)) + $offset; 268 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 'timestart' => $time)); 269 $this->assertTrue($result); 270 $time = strtotime('1 Monday', strtotime("+2 months", $monthstart)) + $offset; 271 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 'timestart' => $time)); 272 $this->assertTrue($result); 273 274 // This should generate 10 child event + 1 parent, since by then until bound would be hit. 275 $until = strtotime('+1 day +10 months', $this->event->timestart); 276 $until = date('YmdThis', $until); 277 $rrule = "FREQ=MONTHLY;BYMONTHDAY=2;UNTIL=$until"; 278 $mang = new \core_calendar\rrule_manager($rrule); 279 $mang->parse_rrule(); 280 $mang->create_events($this->event); 281 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 282 $this->assertEquals(11, $count); 283 for ($i = 0; $i < 11; $i++) { 284 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 285 'timestart' => (strtotime("+$i month", $this->event->timestart)))); 286 $this->assertTrue($result); 287 } 288 289 // This should generate 10 child event + 1 parent, since by then until bound would be hit. 290 $until = strtotime('+1 day +10 months', $this->event->timestart); 291 $until = date('YmdThis', $until); 292 $rrule = "FREQ=MONTHLY;BYDAY=1MO;UNTIL=$until"; 293 $mang = new \core_calendar\rrule_manager($rrule); 294 $mang->parse_rrule(); 295 $mang->create_events($this->event); 296 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 297 $this->assertEquals(10, $count); 298 for ($i = 0; $i < 10; $i++) { 299 $time = strtotime('1 Monday', strtotime("+$i months", $monthstart)) + $offset; 300 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 'timestart' => $time)); 301 $this->assertTrue($result); 302 } 303 304 // This should generate 11 child event + 1 parent, since by then until bound would be hit. 305 $until = strtotime('+10 day +10 months', $this->event->timestart); // 12 oct 2014. 306 $until = date('YmdThis', $until); 307 $rrule = "FREQ=MONTHLY;INTERVAL=2;BYMONTHDAY=2,5;UNTIL=$until"; 308 $mang = new \core_calendar\rrule_manager($rrule); 309 $mang->parse_rrule(); 310 $mang->create_events($this->event); 311 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 312 $this->assertEquals(12, $count); 313 for ($i = 0; $i < 6; $i++) { 314 $moffset = $i * 2; 315 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 316 'timestart' => (strtotime("+$moffset month", $this->event->timestart)))); 317 $this->assertTrue($result); 318 // Event on the 5th of a month. 319 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 320 'timestart' => (strtotime("+3 days +$moffset month", $this->event->timestart)))); 321 $this->assertTrue($result); 322 } 323 324 // This should generate 11 child event + 1 parent, since by then until bound would be hit. 325 $until = strtotime('+20 day +10 months', $this->event->timestart); // 22 oct 2014. 326 $until = date('YmdTHis', $until); 327 $rrule = "FREQ=MONTHLY;INTERVAL=2;BYDAY=1MO,3WE;UNTIL=$until"; 328 $mang = new \core_calendar\rrule_manager($rrule); 329 $mang->parse_rrule(); 330 $mang->create_events($this->event); 331 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 332 $this->assertEquals(12, $count); 333 for ($i = 0; $i < 6; $i++) { 334 $moffset = $i * 2; 335 $time = strtotime("+$moffset month", $monthstart); 336 $time2 = strtotime("+1 Monday", $time) + $offset; 337 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 'timestart' => $time2)); 338 $this->assertTrue($result); 339 $time2 = strtotime("+3 Wednesday", $time) + $offset; 340 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 341 'timestart' => $time2)); // Event on the 5th of a month. 342 $this->assertTrue($result); 343 } 344 345 // Forever event. This should generate events over 10 year period, on 2nd of every 12th month. 346 $rrule = 'FREQ=MONTHLY;INTERVAL=12;BYMONTHDAY=2'; 347 $mang = new \core_calendar\rrule_manager($rrule); 348 $until = time() + (YEARSECS * $mang::TIME_UNLIMITED_YEARS); 349 $mang->parse_rrule(); 350 $mang->create_events($this->event); 351 for ($i = 0, $time = $this->event->timestart; $time < $until; $i++, $moffset = $i * 12, 352 $time = strtotime("+$moffset month", $this->event->timestart)) { 353 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 354 'timestart' => ($time))); 355 $this->assertTrue($result); 356 } 357 358 // Forever event. This should generate 10 child events + 1 parent over 10 year period, every 50th Monday. 359 $rrule = 'FREQ=MONTHLY;BYDAY=1MO;INTERVAL=12'; 360 $mang = new \core_calendar\rrule_manager($rrule); 361 $until = time() + (YEARSECS * $mang::TIME_UNLIMITED_YEARS); 362 $mang->parse_rrule(); 363 $mang->create_events($this->event); 364 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 365 $this->assertEquals(11, $count); 366 for ($i = 0, $moffset = 0, $time = $this->event->timestart; $time < $until; $i++, $moffset = $i * 12) { 367 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 'timestart' => ($time))); 368 $this->assertTrue($result); 369 $time = strtotime("+$moffset month", $monthstart); 370 $time = strtotime("+1 Monday", $time) + $offset; 371 } 372 } 373 374 /** 375 * Test recurrence rules for yearly frequency. 376 */ 377 public function test_yearly_events() { 378 global $DB; 379 380 $rrule = 'FREQ=YEARLY;COUNT=3;BYMONTH=12'; // This should generate 3 events in total. 381 $mang = new \core_calendar\rrule_manager($rrule); 382 $mang->parse_rrule(); 383 $mang->create_events($this->event); 384 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 385 $this->assertEquals(3, $count); 386 for ($i = 0, $time = $this->event->timestart; $i < 3; $i++, $time = strtotime("+$i years", $this->event->timestart)) { 387 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 'timestart' => $time)); 388 $this->assertTrue($result); 389 } 390 391 // Create an event every december, until the time limit is hit. 392 $until = strtotime('+20 day +10 years', $this->event->timestart); 393 $until = date('YmdTHis', $until); 394 $rrule = "FREQ=YEARLY;BYMONTH=12;UNTIL=$until"; // Forever event. 395 $mang = new \core_calendar\rrule_manager($rrule); 396 $until = time() + (YEARSECS * $mang::TIME_UNLIMITED_YEARS); 397 $mang->parse_rrule(); 398 $mang->create_events($this->event); 399 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 400 $this->assertEquals(11, $count); 401 for ($i = 0, $time = $this->event->timestart; $time < $until; $i++, $yoffset = $i * 2, 402 $time = strtotime("+$yoffset years", $this->event->timestart)) { 403 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 404 'timestart' => ($time))); 405 $this->assertTrue($result); 406 } 407 408 // This should generate 5 events in total, every second year in the month of december. 409 $rrule = 'FREQ=YEARLY;BYMONTH=12;INTERVAL=2;COUNT=5'; 410 $mang = new \core_calendar\rrule_manager($rrule); 411 $mang->parse_rrule(); 412 $mang->create_events($this->event); 413 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 414 $this->assertEquals(5, $count); 415 for ($i = 0, $time = $this->event->timestart; $i < 5; $i++, $yoffset = $i * 2, 416 $time = strtotime("+$yoffset years", $this->event->timestart)) { 417 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 418 'timestart' => ($time))); 419 $this->assertTrue($result); 420 } 421 422 $rrule = 'FREQ=YEARLY;BYMONTH=12;INTERVAL=2'; // Forever event. 423 $mang = new \core_calendar\rrule_manager($rrule); 424 $until = time() + (YEARSECS * $mang::TIME_UNLIMITED_YEARS); 425 $mang->parse_rrule(); 426 $mang->create_events($this->event); 427 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 428 $this->assertEquals(6, $count); 429 for ($i = 0, $time = $this->event->timestart; $time < $until; $i++, $yoffset = $i * 2, 430 $time = strtotime("+$yoffset years", $this->event->timestart)) { 431 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 432 'timestart' => ($time))); 433 $this->assertTrue($result); 434 } 435 436 // This much seconds after the start of the day. 437 $offset = $this->event->timestart - mktime(0, 0, 0, date("n", $this->event->timestart), date("j", $this->event->timestart), 438 date("Y", $this->event->timestart)); 439 $yearstart = mktime(0, 0, 0, 1, 1, date("Y", $this->event->timestart)); 440 441 $rrule = 'FREQ=YEARLY;COUNT=3;BYMONTH=12;BYDAY=1MO'; // This should generate 3 events in total. 442 $mang = new \core_calendar\rrule_manager($rrule); 443 $mang->parse_rrule(); 444 $mang->create_events($this->event); 445 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 446 $this->assertEquals(3, $count); 447 for ($i = 0; $i < 3; $i++) { 448 $time = strtotime("+11 months +$i years", $yearstart); 449 $time = strtotime("+1 Monday", $time) + $offset; 450 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 'timestart' => $time)); 451 $this->assertTrue($result); 452 } 453 454 // Create an event every december, until the time limit is hit. 455 $until = strtotime('+20 day +10 years', $this->event->timestart); 456 $until = date('YmdTHis', $until); 457 $rrule = "FREQ=YEARLY;BYMONTH=12;UNTIL=$until;BYDAY=1MO"; 458 $mang = new \core_calendar\rrule_manager($rrule); 459 $until = time() + (YEARSECS * $mang::TIME_UNLIMITED_YEARS); 460 $mang->parse_rrule(); 461 $mang->create_events($this->event); 462 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 463 $this->assertEquals(11, $count); 464 for ($i = 0, $time = $this->event->timestart; $time < $until; $i++) { 465 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 466 'timestart' => ($time))); 467 $this->assertTrue($result); 468 $time = strtotime("+11 months +$i years", $yearstart); 469 $time = strtotime("+1 Monday", $time) + $offset; 470 } 471 472 // This should generate 5 events in total, every second year in the month of december. 473 $rrule = 'FREQ=YEARLY;BYMONTH=12;INTERVAL=2;COUNT=5;BYDAY=1MO'; 474 $mang = new \core_calendar\rrule_manager($rrule); 475 $mang->parse_rrule(); 476 $mang->create_events($this->event); 477 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 478 $this->assertEquals(5, $count); 479 for ($i = $yoffset = 0, $time = $this->event->timestart; $i < 5; $i++, $yoffset = $i * 2) { 480 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 481 'timestart' => ($time))); 482 $this->assertTrue($result); 483 $time = strtotime("+11 months +$yoffset years", $yearstart); 484 $time = strtotime("+1 Monday", $time) + $offset; 485 } 486 487 $rrule = 'FREQ=YEARLY;BYMONTH=12;INTERVAL=2;BYDAY=1MO'; // Forever event. 488 $mang = new \core_calendar\rrule_manager($rrule); 489 $until = time() + (YEARSECS * $mang::TIME_UNLIMITED_YEARS); 490 $mang->parse_rrule(); 491 $mang->create_events($this->event); 492 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 493 $this->assertEquals(6, $count); 494 for ($i = 0, $time = $this->event->timestart; $time < $until; $i++, $yoffset = $i * 2) { 495 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 496 'timestart' => ($time))); 497 $this->assertTrue($result); 498 $time = strtotime("+11 months +$yoffset years", $yearstart); 499 $time = strtotime("+1 Monday", $time) + $offset; 500 } 501 502 $rrule = 'FREQ=YEARLY;INTERVAL=2'; // Forever event. 503 $mang = new \core_calendar\rrule_manager($rrule); 504 $until = time() + (YEARSECS * $mang::TIME_UNLIMITED_YEARS); 505 $mang->parse_rrule(); 506 $mang->create_events($this->event); 507 $count = $DB->count_records('event', array('repeatid' => $this->event->id)); 508 $this->assertEquals(6, $count); 509 for ($i = 0, $time = $this->event->timestart; $time < $until; $i++, $yoffset = $i * 2) { 510 $result = $DB->record_exists('event', array('repeatid' => $this->event->id, 511 'timestart' => ($time))); 512 $this->assertTrue($result); 513 $time = strtotime("+11 months +$yoffset years", $yearstart); 514 $time = strtotime("+1 Monday", $time) + $offset; 515 } 516 } 517 } 518 519 /** 520 * Class core_calendar_test_rrule_manager 521 * 522 * Wrapper to access protected vars for testing. 523 * 524 * @package core_calendar 525 * @category test 526 * @copyright 2014 onwards Ankit Agarwal <[email protected]> 527 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 528 */ 529 class core_tests_calendar_rrule_manager extends \core_calendar\rrule_manager{ 530 531 /** 532 * Magic method to get properties. 533 * 534 * @param $prop string property 535 * 536 * @return mixed 537 * @throws coding_exception 538 */ 539 public function __get($prop) { 540 if (property_exists($this, $prop)) { 541 return $this->$prop; 542 } 543 throw new coding_exception('invalidproperty'); 544 } 545 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |