public function test_calendar_update_subscription() { $this->resetAfterTest(true); $subscription = new stdClass(); $subscription->eventtype = 'site'; $subscription->name = 'test'; $id = calendar_add_subscription($subscription); $subscription = new stdClass(); $subscription->id = $id; $subscription->name = 'awesome'; calendar_update_subscription($subscription); $sub = calendar_get_subscription($id); $this->assertEquals($subscription->name, $sub->name); $subscription = new stdClass(); $subscription->id = $id; $subscription->name = 'awesome2'; $subscription->pollinterval = 604800; calendar_update_subscription($subscription); $sub = calendar_get_subscription($id); $this->assertEquals($subscription->name, $sub->name); $this->assertEquals($subscription->pollinterval, $sub->pollinterval); $subscription = new stdClass(); $subscription->name = 'awesome4'; $this->setExpectedException('coding_exception'); calendar_update_subscription($subscription); }
} else { $course = get_site(); $courses = calendar_get_default_courses(); } require_course_login($course); if (!calendar_user_can_add_event($course)) { print_error('errorcannotimport', 'calendar'); } $form = new calendar_addsubscription_form(null); $form->set_data(array('course' => $course->id)); $importresults = ''; $formdata = $form->get_data(); if (!empty($formdata)) { require_sesskey(); // Must have sesskey for all actions. $subscriptionid = calendar_add_subscription($formdata); if ($formdata->importfrom == CALENDAR_IMPORT_FROM_FILE) { // Blank the URL if it's a file import. $formdata->url = ''; $calendar = $form->get_file_content('importfile'); $ical = new iCalendar(); $ical->unserialize($calendar); $importresults = calendar_import_icalendar_events($ical, $courseid, $subscriptionid); } else { try { $importresults = calendar_update_subscription_events($subscriptionid); } catch (moodle_exception $e) { // Delete newly added subscription and show invalid url error. calendar_delete_subscription($subscriptionid); print_error($e->errorcode, $e->module, $PAGE->url); }
/** * Test calendar cron with a broken subscription URL. */ public function test_calendar_cron_broken_url() { global $CFG; require_once $CFG->dirroot . '/lib/cronlib.php'; $subscription = new stdClass(); $subscription->eventtype = 'site'; $subscription->name = 'test'; $subscription->url = 'brokenurl'; $subscription->pollinterval = 86400; $subscription->lastupdated = 0; calendar_add_subscription($subscription); $this->expectOutputRegex('/Error updating calendar subscription: The given iCal URL is invalid/'); calendar_cron(); }
/** * Tests for calendar_subscription_deleted event. */ public function test_calendar_subscription_deleted() { global $CFG; require_once $CFG->dirroot . '/calendar/lib.php'; $this->resetAfterTest(true); // Create a mock subscription. $subscription = new stdClass(); $subscription->eventtype = 'site'; $subscription->name = 'test'; $subscription->courseid = $this->course->id; $subscription->id = calendar_add_subscription($subscription); // Trigger and capture the event. $sink = $this->redirectEvents(); calendar_delete_subscription($subscription); $events = $sink->get_events(); $event = reset($events); // Check that the event data is valid. $this->assertInstanceOf('\\core\\event\\calendar_subscription_deleted', $event); $this->assertEquals($subscription->id, $event->objectid); $this->assertEquals($subscription->courseid, $event->other['courseid']); $this->assertDebuggingNotCalled(); $sink->close(); }
public function test_calendar_add_subscription() { global $DB, $CFG; require_once $CFG->dirroot . '/lib/bennu/bennu.inc.php'; $this->resetAfterTest(true); // Test for Microsoft Outlook 2010. $subscription = new stdClass(); $subscription->name = 'Microsoft Outlook 2010'; $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE; $subscription->eventtype = 'site'; $id = calendar_add_subscription($subscription); $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/ms_outlook_2010.ics'); $ical = new iCalendar(); $ical->unserialize($calendar); $this->assertEquals($ical->parser_errors, array()); $sub = calendar_get_subscription($id); $result = calendar_import_icalendar_events($ical, $sub->courseid, $sub->id); $count = $DB->count_records('event', array('subscriptionid' => $sub->id)); $this->assertEquals($count, 1); // Test for OSX Yosemite. $subscription = new stdClass(); $subscription->name = 'OSX Yosemite'; $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE; $subscription->eventtype = 'site'; $id = calendar_add_subscription($subscription); $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/osx_yosemite.ics'); $ical = new iCalendar(); $ical->unserialize($calendar); $this->assertEquals($ical->parser_errors, array()); $sub = calendar_get_subscription($id); $result = calendar_import_icalendar_events($ical, $sub->courseid, $sub->id); $count = $DB->count_records('event', array('subscriptionid' => $sub->id)); $this->assertEquals($count, 1); // Test for Google Gmail. $subscription = new stdClass(); $subscription->name = 'Google Gmail'; $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE; $subscription->eventtype = 'site'; $id = calendar_add_subscription($subscription); $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/google_gmail.ics'); $ical = new iCalendar(); $ical->unserialize($calendar); $this->assertEquals($ical->parser_errors, array()); $sub = calendar_get_subscription($id); $result = calendar_import_icalendar_events($ical, $sub->courseid, $sub->id); $count = $DB->count_records('event', array('subscriptionid' => $sub->id)); $this->assertEquals($count, 1); }