Exemple #1
0
 /**
  * @expectedException coding_exception
  */
 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 = calendar_get_subscription($id);
     $subscription->name = 'awesome';
     calendar_update_subscription($subscription);
     $sub = calendar_get_subscription($id);
     $this->assertEquals($subscription->name, $sub->name);
     $subscription = new stdClass();
     $subscription = calendar_get_subscription($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';
     calendar_update_subscription($subscription);
 }
Exemple #2
0
/**
 * Fetch a calendar subscription and update the events in the calendar.
 *
 * @param int $subscriptionid The course ID for the calendar.
 * @return string A log of the import progress, including errors.
 */
function calendar_update_subscription_events($subscriptionid)
{
    global $DB;
    $sub = calendar_get_subscription($subscriptionid);
    // Don't update a file subscription. TODO: Update from a new uploaded file.
    if (empty($sub->url)) {
        return 'File subscription not updated.';
    }
    $ical = calendar_get_icalendar($sub->url);
    $return = calendar_import_icalendar_events($ical, $sub->courseid, $subscriptionid);
    $sub->lastupdated = time();
    calendar_update_subscription($sub);
    return $return;
}
Exemple #3
0
 /**
  * Tests for calendar_subscription_updated event.
  */
 public function test_calendar_subscription_updated()
 {
     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);
     // Now edit it.
     $subscription->name = 'awesome';
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     calendar_update_subscription($subscription);
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event data is valid.
     $this->assertInstanceOf('\\core\\event\\calendar_subscription_updated', $event);
     $this->assertEquals($subscription->id, $event->objectid);
     $this->assertEquals($subscription->courseid, $event->other['courseid']);
     $this->assertEquals($subscription->eventtype, $event->other['eventtype']);
     $this->assertDebuggingNotCalled();
     $sink->close();
 }