1<?php 2 3namespace Sabre\CalDAV; 4use Sabre\HTTP; 5use Sabre\VObject; 6 7/** 8 * This unittests is created to find out why recurring events have wrong DTSTART value 9 * 10 * 11 * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/). 12 * @author Evert Pot (http://evertpot.com/) 13 * @license http://sabre.io/license/ Modified BSD License 14 */ 15class ExpandEventsDTSTARTandDTENDTest extends \Sabre\DAVServerTest { 16 17 protected $setupCalDAV = true; 18 19 protected $caldavCalendars = array( 20 array( 21 'id' => 1, 22 'name' => 'Calendar', 23 'principaluri' => 'principals/user1', 24 'uri' => 'calendar1', 25 ) 26 ); 27 28 protected $caldavCalendarObjects = array( 29 1 => array( 30 'event.ics' => array( 31 'calendardata' => 'BEGIN:VCALENDAR 32VERSION:2.0 33BEGIN:VEVENT 34UID:foobar 35DTEND;TZID=Europe/Berlin:20120207T191500 36RRULE:FREQ=DAILY;INTERVAL=1;COUNT=3 37SUMMARY:RecurringEvents 3 times 38DTSTART;TZID=Europe/Berlin:20120207T181500 39END:VEVENT 40BEGIN:VEVENT 41CREATED:20120207T111900Z 42UID:foobar 43DTEND;TZID=Europe/Berlin:20120208T191500 44SUMMARY:RecurringEvents 3 times OVERWRITTEN 45DTSTART;TZID=Europe/Berlin:20120208T181500 46RECURRENCE-ID;TZID=Europe/Berlin:20120208T181500 47END:VEVENT 48END:VCALENDAR 49', 50 ), 51 ), 52 ); 53 54 function testExpand() { 55 56 $request = HTTP\Sapi::createFromServerArray([ 57 'REQUEST_METHOD' => 'REPORT', 58 'HTTP_CONTENT_TYPE' => 'application/xml', 59 'REQUEST_URI' => '/calendars/user1/calendar1', 60 'HTTP_DEPTH' => '1', 61 ]); 62 63 $request->setBody('<?xml version="1.0" encoding="utf-8" ?> 64<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav"> 65 <D:prop> 66 <C:calendar-data> 67 <C:expand start="20120205T230000Z" end="20120212T225959Z"/> 68 </C:calendar-data> 69 <D:getetag/> 70 </D:prop> 71 <C:filter> 72 <C:comp-filter name="VCALENDAR"> 73 <C:comp-filter name="VEVENT"> 74 <C:time-range start="20120205T230000Z" end="20120212T225959Z"/> 75 </C:comp-filter> 76 </C:comp-filter> 77 </C:filter> 78</C:calendar-query>'); 79 80 $response = $this->request($request); 81 82 // Everts super awesome xml parser. 83 $body = substr( 84 $response->body, 85 $start = strpos($response->body, 'BEGIN:VCALENDAR'), 86 strpos($response->body, 'END:VCALENDAR') - $start + 13 87 ); 88 $body = str_replace(' ','',$body); 89 90 try { 91 $vObject = VObject\Reader::read($body); 92 } catch (VObject\ParseException $e) { 93 $this->fail('Could not parse object. Error:' . $e->getMessage(). ' full object: ' . $response->getBodyAsString()); 94 } 95 96 // check if DTSTARTs and DTENDs are correct 97 foreach ($vObject->VEVENT as $vevent) { 98 /** @var $vevent Sabre\VObject\Component\VEvent */ 99 foreach ($vevent->children as $child) { 100 /** @var $child Sabre\VObject\Property */ 101 102 if ($child->name == 'DTSTART') { 103 // DTSTART has to be one of three valid values 104 $this->assertContains($child->getValue(), ['20120207T171500Z', '20120208T171500Z', '20120209T171500Z'], 'DTSTART is not a valid value: '.$child->getValue()); 105 } elseif ($child->name == 'DTEND') { 106 // DTEND has to be one of three valid values 107 $this->assertContains($child->getValue(), ['20120207T181500Z', '20120208T181500Z', '20120209T181500Z'], 'DTEND is not a valid value: '.$child->getValue()); 108 } 109 } 110 } 111 } 112 113} 114 115