/**
  * Calendar attachment constructor
  *
  * @param Calendar $calendar
  */
 public function __construct(Calendar $calendar)
 {
     $data = $calendar->createCalendar();
     $filename = $calendar->getConfig('filename');
     $contentType = $calendar->getContentType();
     parent::__construct($data, $filename, $contentType);
 }
 /**
  * Test creating new event for calendar
  */
 public function testNewEvent()
 {
     $calendar = new Calendar();
     $this->assertEmpty($calendar->getComponent('vevent'));
     $event = $calendar->newEvent();
     $this->assertInstanceOf('vevent', $event);
     $this->assertEquals($event, $calendar->getComponent('vevent'));
 }
 /**
  * Get default response headers for a calendar
  *
  * @return array
  */
 protected function getDefaultHeaders()
 {
     $headers = array();
     $mimeType = $this->calendar->getContentType();
     $headers['Content-Type'] = sprintf('%s; charset=utf-8', $mimeType);
     $filename = $this->calendar->getConfig('filename');
     $headers['Content-Disposition'] = sprintf('attachment; filename="%s', $filename);
     return $headers;
 }
 /**
  * Testing calendar attachment
  *
  * @param Calendar $calendar
  *
  * @dataProvider getCalendarTestData
  */
 public function testCalendarAttachment(Calendar $calendar)
 {
     $attachment = new CalendarAttachment($calendar);
     $this->assertInstanceOf('Swift_Attachment', $attachment);
     $this->assertInstanceOf('Dyvelop\\ICalCreatorBundle\\Mailer\\CalendarAttachment', $attachment);
     $this->assertEquals($calendar->createCalendar(), $attachment->getBody());
     $this->assertEquals($calendar->getConfig('filename'), $attachment->getFilename());
     $this->assertEquals($calendar->getContentType(), $attachment->getContentType());
 }
Example #5
0
 /**
  * Create new calendar
  *
  * @param array $config
  *
  * @return Calendar
  */
 public function create($config = array())
 {
     // merge with default configs
     $config = array_merge($this->defaultConfig, $config);
     $calendar = new Calendar($config);
     if (!is_null($this->timezone)) {
         $calendar->setTimezone($this->timezone);
     }
     return $calendar;
 }
 /**
  * Testing calendar response
  *
  * @param Calendar $calendar Calendar
  * @param array    $headers  Additional response headers
  *
  * @dataProvider getCalendarTestData
  */
 public function testCalendarResponse(Calendar $calendar, $headers = array())
 {
     $response = new CalendarResponse($calendar, 200, $headers);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
     $this->assertInstanceOf('Dyvelop\\ICalCreatorBundle\\Response\\CalendarResponse', $response);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals($calendar->createCalendar(), $response->getContent());
     foreach ($headers as $key => $value) {
         $this->assertEquals($value, $response->headers->get($key));
     }
     $this->assertContains($calendar->getContentType(), $response->headers->get('Content-Type'));
     $this->assertContains($calendar->getConfig('filename'), $response->headers->get('Content-Disposition'));
 }