<?php

set_include_path(realpath("../lib") . PATH_SEPARATOR . get_include_path());
require_once "../tests/convenience.php";
/**
 * Parse an iCalendar file
 */
$filepath = realpath('../tests/files');
$parser = new qCal_Parser(array('searchpath' => $filepath));
// parse a file
$ical = $parser->parseFile('simple.ics');
// parse raw data
// $rawdata = file_get_contents($filepath . '/simple.ics');
// $ical->parse($rawdata);
/**
 * Render an iCal object as an icalendar file
 */
$iCalData = $ical->render();
// eventually we can use other renderers as well...
// $xCal = $ical->render(new qCal_Renderer_xCal()); // xCal is an implementation of icalendar in xml
// $hCal = $ical->render(new qCal_Renderer_hCal()); // hCal is a microformat (html version of icalendar format)
/**
 * Build an iCal object from scratch
 */
$calendar = new qCal(array('prodid' => '-//Some Calendar Company//Calendar Program v0.1//EN'));
$todo = new qCal_Component_Vtodo(array('class' => 'private', 'dtstart' => '20090909', 'description' => 'Eat some bacon!!', 'summary' => 'Eat bacon', 'priority' => 1));
$todo->attach(new qCal_Component_Valarm(array('action' => 'audio', 'trigger' => '20090423', 'attach' => 'http://www.example.com/foo.wav')));
$calendar->attach($todo);
// now you can render the calendar if you want, or just echo it out
 /**
  * Test that all components have access to their root component
  */
 public function testComponentsHaveAccessToRootComponent()
 {
     $cal = new qCal_Component_Vcalendar();
     $todo = new qCal_Component_Vtodo();
     $alarm = new qCal_Component_Valarm();
     $todo->attach($alarm);
     $cal->attach($todo);
     $this->assertIdentical($alarm->getRootComponent(), $cal);
 }
 /**
  * "VALARM" calendar components
  * cannot be nested. Multiple mutually independent "VALARM" calendar
  * components can be specified for a single "VEVENT" or "VTODO" calendar
  * component.
  */
 public function testValarmCannotBeNestedAndCanOccurMultipleTimes()
 {
     $alarm = new qCal_Component_Valarm(array('action' => 'audio', 'trigger' => 'P15M'));
     $alarm2 = new qCal_Component_Valarm(array('action' => 'audio', 'trigger' => 'P25M'));
     $todo = new qCal_Component_Vtodo();
     $this->expectException(new qCal_Exception_InvalidComponent('VALARM cannot be attached to VALARM'));
     $alarm2->attach($alarm);
     $todo->attach($alarm);
     $todo->attach($alarm2);
 }