"Fossies" - the Fresh Open Source Software Archive

Member "dav-4.0.3/tests/Sabre/CalDAV/Issue203Test.php" (10 Jan 2020, 4075 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 "Issue203Test.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 find out why an overwritten DAILY event has wrong DTSTART, DTEND, SUMMARY and RECURRENCEID.
   12  *
   13  * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
   14  * @author Evert Pot (http://evertpot.com/)
   15  * @license http://sabre.io/license/ Modified BSD License
   16  */
   17 class Issue203Test extends \Sabre\DAVServerTest
   18 {
   19     protected $setupCalDAV = true;
   20 
   21     protected $caldavCalendars = [
   22         [
   23             'id' => 1,
   24             'name' => 'Calendar',
   25             'principaluri' => 'principals/user1',
   26             'uri' => 'calendar1',
   27         ],
   28     ];
   29 
   30     protected $caldavCalendarObjects = [
   31         1 => [
   32             'event.ics' => [
   33                 'calendardata' => 'BEGIN:VCALENDAR
   34 VERSION:2.0
   35 BEGIN:VEVENT
   36 UID:20120330T155305CEST-6585fBUVgV
   37 DTSTAMP:20120330T135305Z
   38 DTSTART;TZID=Europe/Berlin:20120326T155200
   39 DTEND;TZID=Europe/Berlin:20120326T165200
   40 RRULE:FREQ=DAILY;COUNT=2;INTERVAL=1
   41 SUMMARY:original summary
   42 TRANSP:OPAQUE
   43 END:VEVENT
   44 BEGIN:VEVENT
   45 UID:20120330T155305CEST-6585fBUVgV
   46 DTSTAMP:20120330T135352Z
   47 DESCRIPTION:
   48 DTSTART;TZID=Europe/Berlin:20120328T155200
   49 DTEND;TZID=Europe/Berlin:20120328T165200
   50 RECURRENCE-ID;TZID=Europe/Berlin:20120327T155200
   51 SEQUENCE:1
   52 SUMMARY:overwritten summary
   53 TRANSP:OPAQUE
   54 END:VEVENT
   55 END:VCALENDAR
   56 ',
   57             ],
   58         ],
   59     ];
   60 
   61     public function testIssue203()
   62     {
   63         $request = HTTP\Sapi::createFromServerArray([
   64             'REQUEST_METHOD' => 'REPORT',
   65             'HTTP_CONTENT_TYPE' => 'application/xml',
   66             'REQUEST_URI' => '/calendars/user1/calendar1',
   67             'HTTP_DEPTH' => '1',
   68         ]);
   69 
   70         $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
   71 <C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
   72     <D:prop>
   73         <C:calendar-data>
   74             <C:expand start="20120325T220000Z" end="20120401T215959Z"/>
   75         </C:calendar-data>
   76         <D:getetag/>
   77     </D:prop>
   78     <C:filter>
   79         <C:comp-filter name="VCALENDAR">
   80             <C:comp-filter name="VEVENT">
   81                 <C:time-range start="20120325T220000Z" end="20120401T215959Z"/>
   82             </C:comp-filter>
   83         </C:comp-filter>
   84     </C:filter>
   85 </C:calendar-query>');
   86 
   87         $response = $this->request($request);
   88 
   89         $bodyAsString = $response->getBodyAsString();
   90         // Everts super awesome xml parser.
   91         $body = substr(
   92             $bodyAsString,
   93             $start = strpos($bodyAsString, 'BEGIN:VCALENDAR'),
   94             strpos($bodyAsString, 'END:VCALENDAR') - $start + 13
   95         );
   96         $body = str_replace('&#13;', '', $body);
   97 
   98         $vObject = VObject\Reader::read($body);
   99 
  100         $this->assertEquals(2, count($vObject->VEVENT));
  101 
  102         $expectedEvents = [
  103             [
  104                 'DTSTART' => '20120326T135200Z',
  105                 'DTEND' => '20120326T145200Z',
  106                 'SUMMARY' => 'original summary',
  107             ],
  108             [
  109                 'DTSTART' => '20120328T135200Z',
  110                 'DTEND' => '20120328T145200Z',
  111                 'SUMMARY' => 'overwritten summary',
  112                 'RECURRENCE-ID' => '20120327T135200Z',
  113             ],
  114         ];
  115 
  116         // try to match agains $expectedEvents array
  117         foreach ($expectedEvents as $expectedEvent) {
  118             $matching = false;
  119 
  120             foreach ($vObject->VEVENT as $vevent) {
  121                 /** @var $vevent Sabre\VObject\Component\VEvent */
  122                 foreach ($vevent->children() as $child) {
  123                     /** @var $child Sabre\VObject\Property */
  124                     if (isset($expectedEvent[$child->name])) {
  125                         if ($expectedEvent[$child->name] != $child->getValue()) {
  126                             continue 2;
  127                         }
  128                     }
  129                 }
  130 
  131                 $matching = true;
  132                 break;
  133             }
  134 
  135             $this->assertTrue($matching, 'Did not find the following event in the response: '.var_export($expectedEvent, true));
  136         }
  137     }
  138 }