1<?php
2
3namespace Sabre\CalDAV;
4use Sabre\HTTP;
5use Sabre\VObject;
6
7/**
8 * This unittest is created to check if a VALARM TRIGGER of PT0S is supported
9 *
10 * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
11 * @author Evert Pot (http://evertpot.com/)
12 * @license http://sabre.io/license/ Modified BSD License
13 */
14class Issue205Test extends \Sabre\DAVServerTest {
15
16    protected $setupCalDAV = true;
17
18    protected $caldavCalendars = array(
19        array(
20            'id' => 1,
21            'name' => 'Calendar',
22            'principaluri' => 'principals/user1',
23            'uri' => 'calendar1',
24        )
25    );
26
27    protected $caldavCalendarObjects = array(
28        1 => array(
29            'event.ics' => array(
30                'calendardata' => 'BEGIN:VCALENDAR
31VERSION:2.0
32BEGIN:VEVENT
33UID:20120330T155305CEST-6585fBUVgV
34DTSTAMP:20120330T135305Z
35DTSTART;TZID=Europe/Berlin:20120326T155200
36DTEND;TZID=Europe/Berlin:20120326T165200
37SUMMARY:original summary
38TRANSP:OPAQUE
39BEGIN:VALARM
40ACTION:AUDIO
41ATTACH;VALUE=URI:Basso
42TRIGGER:PT0S
43END:VALARM
44END:VEVENT
45END:VCALENDAR
46',
47            ),
48        ),
49    );
50
51    function testIssue205() {
52
53        $request = HTTP\Sapi::createFromServerArray(array(
54            'REQUEST_METHOD' => 'REPORT',
55            'HTTP_CONTENT_TYPE' => 'application/xml',
56            'REQUEST_URI' => '/calendars/user1/calendar1',
57            'HTTP_DEPTH' => '1',
58        ));
59
60        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
61<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
62    <D:prop>
63        <C:calendar-data>
64            <C:expand start="20120325T220000Z" end="20120401T215959Z"/>
65        </C:calendar-data>
66        <D:getetag/>
67    </D:prop>
68    <C:filter>
69        <C:comp-filter name="VCALENDAR">
70            <C:comp-filter name="VEVENT">
71                <C:comp-filter name="VALARM">
72                    <C:time-range start="20120325T220000Z" end="20120401T215959Z"/>
73                </C:comp-filter>
74            </C:comp-filter>
75        </C:comp-filter>
76    </C:filter>
77</C:calendar-query>');
78
79        $response = $this->request($request);
80
81        $this->assertFalse(strpos($response->body, '<s:exception>Exception</s:exception>'), 'Exception occurred: ' . $response->body);
82        $this->assertFalse(strpos($response->body, 'Unknown or bad format'), 'DateTime unknown format Exception: ' . $response->body);
83
84        // Everts super awesome xml parser.
85        $body = substr(
86            $response->body,
87            $start = strpos($response->body, 'BEGIN:VCALENDAR'),
88            strpos($response->body, 'END:VCALENDAR') - $start + 13
89        );
90        $body = str_replace('&#13;','',$body);
91
92        $vObject = VObject\Reader::read($body);
93
94        $this->assertEquals(1, count($vObject->VEVENT));
95
96    }
97}
98