"Fossies" - the Fresh Open Source Software Archive

Member "dav-4.0.3/tests/Sabre/CalDAV/ExpandEventsFloatingTimeTest.php" (10 Jan 2020, 6838 Bytes) of package /linux/www/dav-4.0.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "ExpandEventsFloatingTimeTest.php": 4.0.2_vs_4.0.3.

    1 <?php
    2 
    3 declare(strict_types=1);
    4 
    5 namespace Sabre\CalDAV;
    6 
    7 use Sabre\HTTP;
    8 use Sabre\VObject;
    9 
   10 /**
   11  * This unittest is created to check if expand() works correctly with
   12  * floating times (using calendar-timezone information).
   13  */
   14 class ExpandEventsFloatingTimeTest extends \Sabre\DAVServerTest
   15 {
   16     protected $setupCalDAV = true;
   17 
   18     protected $setupCalDAVICSExport = true;
   19 
   20     protected $caldavCalendars = [
   21         [
   22             'id' => 1,
   23             'name' => 'Calendar',
   24             'principaluri' => 'principals/user1',
   25             'uri' => 'calendar1',
   26             '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'BEGIN:VCALENDAR
   27 VERSION:2.0
   28 CALSCALE:GREGORIAN
   29 BEGIN:VTIMEZONE
   30 TZID:Europe/Berlin
   31 BEGIN:DAYLIGHT
   32 TZOFFSETFROM:+0100
   33 RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
   34 DTSTART:19810329T020000
   35 TZNAME:GMT+2
   36 TZOFFSETTO:+0200
   37 END:DAYLIGHT
   38 BEGIN:STANDARD
   39 TZOFFSETFROM:+0200
   40 RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
   41 DTSTART:19961027T030000
   42 TZNAME:GMT+1
   43 TZOFFSETTO:+0100
   44 END:STANDARD
   45 END:VTIMEZONE
   46 END:VCALENDAR',
   47         ],
   48     ];
   49 
   50     protected $caldavCalendarObjects = [
   51         1 => [
   52            'event.ics' => [
   53                 'calendardata' => 'BEGIN:VCALENDAR
   54 VERSION:2.0
   55 CALSCALE:GREGORIAN
   56 BEGIN:VEVENT
   57 CREATED:20140701T143658Z
   58 UID:dba46fe8-1631-4d98-a575-97963c364dfe
   59 DTEND:20141108T073000
   60 TRANSP:OPAQUE
   61 SUMMARY:Floating Time event, starting 05:30am Europe/Berlin
   62 DTSTART:20141108T053000
   63 DTSTAMP:20140701T143706Z
   64 SEQUENCE:1
   65 END:VEVENT
   66 END:VCALENDAR
   67 ',
   68             ],
   69         ],
   70     ];
   71 
   72     public function testExpandCalendarQuery()
   73     {
   74         $request = new HTTP\Request('REPORT', '/calendars/user1/calendar1', [
   75             'Depth' => 1,
   76             'Content-Type' => 'application/xml',
   77         ]);
   78 
   79         $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
   80 <C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
   81     <D:prop>
   82         <C:calendar-data>
   83             <C:expand start="20141107T230000Z" end="20141108T225959Z"/>
   84         </C:calendar-data>
   85         <D:getetag/>
   86     </D:prop>
   87     <C:filter>
   88         <C:comp-filter name="VCALENDAR">
   89             <C:comp-filter name="VEVENT">
   90                 <C:time-range start="20141107T230000Z" end="20141108T225959Z"/>
   91             </C:comp-filter>
   92         </C:comp-filter>
   93     </C:filter>
   94 </C:calendar-query>');
   95 
   96         $response = $this->request($request);
   97 
   98         $bodyAsString = $response->getBodyAsString();
   99         // Everts super awesome xml parser.
  100         $body = substr(
  101             $bodyAsString,
  102             $start = strpos($bodyAsString, 'BEGIN:VCALENDAR'),
  103             strpos($bodyAsString, 'END:VCALENDAR') - $start + 13
  104         );
  105         $body = str_replace('&#13;', '', $body);
  106 
  107         $vObject = VObject\Reader::read($body);
  108 
  109         // check if DTSTARTs and DTENDs are correct
  110         foreach ($vObject->VEVENT as $vevent) {
  111             /** @var $vevent Sabre\VObject\Component\VEvent */
  112             foreach ($vevent->children() as $child) {
  113                 /** @var $child Sabre\VObject\Property */
  114                 if ('DTSTART' == $child->name) {
  115                     // DTSTART should be the UTC equivalent of given floating time
  116                     $this->assertEquals('20141108T043000Z', $child->getValue());
  117                 } elseif ('DTEND' == $child->name) {
  118                     // DTEND should be the UTC equivalent of given floating time
  119                     $this->assertEquals('20141108T063000Z', $child->getValue());
  120                 }
  121             }
  122         }
  123     }
  124 
  125     public function testExpandMultiGet()
  126     {
  127         $request = new HTTP\Request('REPORT', '/calendars/user1/calendar1', [
  128             'Depth' => 1,
  129             'Content-Type' => 'application/xml',
  130         ]);
  131 
  132         $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
  133 <C:calendar-multiget xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
  134     <D:prop>
  135         <C:calendar-data>
  136             <C:expand start="20141107T230000Z" end="20141108T225959Z"/>
  137         </C:calendar-data>
  138         <D:getetag/>
  139     </D:prop>
  140     <D:href>/calendars/user1/calendar1/event.ics</D:href>
  141 </C:calendar-multiget>');
  142 
  143         $response = $this->request($request);
  144 
  145         $this->assertEquals(207, $response->getStatus());
  146 
  147         $bodyAsString = $response->getBodyAsString();
  148         // Everts super awesome xml parser.
  149         $body = substr(
  150             $bodyAsString,
  151             $start = strpos($bodyAsString, 'BEGIN:VCALENDAR'),
  152             strpos($bodyAsString, 'END:VCALENDAR') - $start + 13
  153         );
  154         $body = str_replace('&#13;', '', $body);
  155 
  156         $vObject = VObject\Reader::read($body);
  157 
  158         // check if DTSTARTs and DTENDs are correct
  159         foreach ($vObject->VEVENT as $vevent) {
  160             /** @var $vevent Sabre\VObject\Component\VEvent */
  161             foreach ($vevent->children() as $child) {
  162                 /** @var $child Sabre\VObject\Property */
  163                 if ('DTSTART' == $child->name) {
  164                     // DTSTART should be the UTC equivalent of given floating time
  165                     $this->assertEquals($child->getValue(), '20141108T043000Z');
  166                 } elseif ('DTEND' == $child->name) {
  167                     // DTEND should be the UTC equivalent of given floating time
  168                     $this->assertEquals($child->getValue(), '20141108T063000Z');
  169                 }
  170             }
  171         }
  172     }
  173 
  174     public function testExpandExport()
  175     {
  176         $request = new HTTP\Request('GET', '/calendars/user1/calendar1?export&start=1&end=2000000000&expand=1', [
  177             'Depth' => 1,
  178             'Content-Type' => 'application/xml',
  179         ]);
  180 
  181         $response = $this->request($request);
  182 
  183         $this->assertEquals(200, $response->getStatus());
  184 
  185         // Everts super awesome xml parser.
  186         $body = substr(
  187             $response->getBodyAsString(),
  188             $start = strpos($response->getBodyAsString(), 'BEGIN:VCALENDAR'),
  189             strpos($response->getBodyAsString(), 'END:VCALENDAR') - $start + 13
  190         );
  191         $body = str_replace('&#13;', '', $body);
  192 
  193         $vObject = VObject\Reader::read($body);
  194 
  195         // check if DTSTARTs and DTENDs are correct
  196         foreach ($vObject->VEVENT as $vevent) {
  197             /** @var $vevent Sabre\VObject\Component\VEvent */
  198             foreach ($vevent->children() as $child) {
  199                 /** @var $child Sabre\VObject\Property */
  200                 if ('DTSTART' == $child->name) {
  201                     // DTSTART should be the UTC equivalent of given floating time
  202                     $this->assertEquals('20141108T043000Z', $child->getValue());
  203                 } elseif ('DTEND' == $child->name) {
  204                     // DTEND should be the UTC equivalent of given floating time
  205                     $this->assertEquals('20141108T063000Z', $child->getValue());
  206                 }
  207             }
  208         }
  209     }
  210 }