"Fossies" - the Fresh Open Source Software Archive

Member "dav-4.0.3/tests/Sabre/CalDAV/ExpandEventsDoubleEventsTest.php" (10 Jan 2020, 2932 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 "ExpandEventsDoubleEventsTest.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 unittests is created to find out why certain events show up twice.
   12  *
   13  * Hopefully, by the time I'm done with this, I've both found the problem, and
   14  * fixed it :)
   15  *
   16  * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
   17  * @author Evert Pot (http://evertpot.com/)
   18  * @license http://sabre.io/license/ Modified BSD License
   19  */
   20 class ExpandEventsDoubleEventsTest extends \Sabre\DAVServerTest
   21 {
   22     protected $setupCalDAV = true;
   23 
   24     protected $caldavCalendars = [
   25         [
   26             'id' => 1,
   27             'name' => 'Calendar',
   28             'principaluri' => 'principals/user1',
   29             'uri' => 'calendar1',
   30         ],
   31     ];
   32 
   33     protected $caldavCalendarObjects = [
   34         1 => [
   35            'event.ics' => [
   36                 'calendardata' => 'BEGIN:VCALENDAR
   37 VERSION:2.0
   38 BEGIN:VEVENT
   39 UID:foobar
   40 DTEND;TZID=Europe/Berlin:20120207T191500
   41 RRULE:FREQ=DAILY;INTERVAL=1;COUNT=3
   42 SUMMARY:RecurringEvents 3 times
   43 DTSTART;TZID=Europe/Berlin:20120207T181500
   44 END:VEVENT
   45 BEGIN:VEVENT
   46 CREATED:20120207T111900Z
   47 UID:foobar
   48 DTEND;TZID=Europe/Berlin:20120208T191500
   49 SUMMARY:RecurringEvents 3 times OVERWRITTEN
   50 DTSTART;TZID=Europe/Berlin:20120208T181500
   51 RECURRENCE-ID;TZID=Europe/Berlin:20120208T181500
   52 END:VEVENT
   53 END:VCALENDAR
   54 ',
   55             ],
   56         ],
   57     ];
   58 
   59     public function testExpand()
   60     {
   61         $request = HTTP\Sapi::createFromServerArray([
   62             'REQUEST_METHOD' => 'REPORT',
   63             'HTTP_CONTENT_TYPE' => 'application/xml',
   64             'REQUEST_URI' => '/calendars/user1/calendar1',
   65             'HTTP_DEPTH' => '1',
   66         ]);
   67 
   68         $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
   69 <C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
   70     <D:prop>
   71         <C:calendar-data>
   72             <C:expand start="20120205T230000Z" end="20120212T225959Z"/>
   73         </C:calendar-data>
   74         <D:getetag/>
   75     </D:prop>
   76     <C:filter>
   77         <C:comp-filter name="VCALENDAR">
   78             <C:comp-filter name="VEVENT">
   79                 <C:time-range start="20120205T230000Z" end="20120212T225959Z"/>
   80             </C:comp-filter>
   81         </C:comp-filter>
   82     </C:filter>
   83 </C:calendar-query>');
   84 
   85         $response = $this->request($request);
   86 
   87         $bodyAsString = $response->getBodyAsString();
   88         // Everts super awesome xml parser.
   89         $body = substr(
   90             $bodyAsString,
   91             $start = strpos($bodyAsString, 'BEGIN:VCALENDAR'),
   92             strpos($bodyAsString, 'END:VCALENDAR') - $start + 13
   93         );
   94         $body = str_replace('&#13;', '', $body);
   95 
   96         $vObject = VObject\Reader::read($body);
   97 
   98         // We only expect 3 events
   99         $this->assertEquals(3, count($vObject->VEVENT), 'We got 6 events instead of 3. Output: '.$body);
  100 
  101         // TZID should be gone
  102         $this->assertFalse(isset($vObject->VEVENT->DTSTART['TZID']));
  103     }
  104 }