1<?php
2
3namespace Sabre\CalDAV\Backend;
4
5use
6    Sabre\DAV\PropPatch;
7
8class AbstractTest extends \PHPUnit_Framework_TestCase {
9
10    function testUpdateCalendar() {
11
12        $abstract = new AbstractMock();
13        $propPatch = new PropPatch( ['{DAV:}displayname' => 'anything'] );
14
15        $abstract->updateCalendar('randomid', $propPatch);
16        $result = $propPatch->commit();
17
18        $this->assertFalse($result);
19
20    }
21
22    function testCalendarQuery() {
23
24        $abstract = new AbstractMock();
25        $filters = array(
26            'name' => 'VCALENDAR',
27            'comp-filters' => array(
28                array(
29                    'name' => 'VEVENT',
30                    'comp-filters' => array(),
31                    'prop-filters' => array(),
32                    'is-not-defined' => false,
33                    'time-range' => null,
34                ),
35            ),
36            'prop-filters' => array(),
37            'is-not-defined' => false,
38            'time-range' => null,
39        );
40
41        $this->assertEquals(array(
42            'event1.ics',
43        ), $abstract->calendarQuery(1, $filters));
44
45    }
46
47    function testGetCalendarObjectByUID() {
48
49        $abstract = new AbstractMock();
50        $this->assertNull(
51            $abstract->getCalendarObjectByUID('principal1', 'zim')
52        );
53        $this->assertEquals(
54            'cal1/event1.ics',
55            $abstract->getCalendarObjectByUID('principal1', 'foo')
56        );
57        $this->assertNull(
58            $abstract->getCalendarObjectByUID('principal3', 'foo')
59        );
60        $this->assertNull(
61            $abstract->getCalendarObjectByUID('principal1', 'shared')
62        );
63
64    }
65
66    function testGetMultipleCalendarObjects() {
67
68        $abstract = new AbstractMock();
69        $result = $abstract->getMultipleCalendarObjects(1, [
70            'event1.ics',
71            'task1.ics',
72        ]);
73
74        $expected = [
75            array(
76                'id' => 1,
77                'calendarid' => 1,
78                'uri' => 'event1.ics',
79                'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
80            ),
81            array(
82                'id' => 2,
83                'calendarid' => 1,
84                'uri' => 'task1.ics',
85                'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n",
86            ),
87        ];
88
89        $this->assertEquals($expected, $result);
90
91
92    }
93
94}
95
96class AbstractMock extends AbstractBackend {
97
98    function getCalendarsForUser($principalUri) {
99
100        return array(
101            array(
102                'id' => 1,
103                'principaluri' => 'principal1',
104                'uri' => 'cal1',
105            ),
106            array(
107                'id' => 2,
108                'principaluri' => 'principal1',
109                '{http://sabredav.org/ns}owner-principal' => 'principal2',
110                'uri' => 'cal1',
111            ),
112        );
113
114    }
115    function createCalendar($principalUri,$calendarUri,array $properties) { }
116    function deleteCalendar($calendarId) { }
117    function getCalendarObjects($calendarId) {
118
119        switch($calendarId) {
120            case 1:
121                return [
122                    [
123                        'id' => 1,
124                        'calendarid' => 1,
125                        'uri' => 'event1.ics',
126                    ],
127                    [
128                        'id' => 2,
129                        'calendarid' => 1,
130                        'uri' => 'task1.ics',
131                    ],
132                ];
133            case 2:
134                return [
135                    [
136                        'id' => 3,
137                        'calendarid' => 2,
138                        'uri' => 'shared-event.ics',
139                    ]
140                ];
141        }
142
143    }
144
145    function getCalendarObject($calendarId, $objectUri) {
146
147        switch($objectUri) {
148
149            case 'event1.ics' :
150                return array(
151                    'id' => 1,
152                    'calendarid' => 1,
153                    'uri' => 'event1.ics',
154                    'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
155                );
156            case 'task1.ics' :
157                return array(
158                    'id' => 2,
159                    'calendarid' => 1,
160                    'uri' => 'task1.ics',
161                    'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n",
162                );
163            case 'shared-event.ics' :
164                return array(
165                    'id' => 3,
166                    'calendarid' => 2,
167                    'uri' => 'event1.ics',
168                    'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:shared\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
169                );
170
171        }
172
173    }
174    function createCalendarObject($calendarId,$objectUri,$calendarData) { }
175    function updateCalendarObject($calendarId,$objectUri,$calendarData) { }
176    function deleteCalendarObject($calendarId,$objectUri) { }
177
178}
179