aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/AbstractTest.php
blob: 166de1daba45f08504cabd0ea44ef4c1f99072d9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php

declare(strict_types=1);

namespace Sabre\CalDAV\Backend;

use
    Sabre\DAV\PropPatch;

class AbstractTest extends \PHPUnit\Framework\TestCase
{
    public function testUpdateCalendar()
    {
        $abstract = new AbstractMock();
        $propPatch = new PropPatch(['{DAV:}displayname' => 'anything']);

        $abstract->updateCalendar('randomid', $propPatch);
        $result = $propPatch->commit();

        $this->assertFalse($result);
    }

    public function testCalendarQuery()
    {
        $abstract = new AbstractMock();
        $filters = [
            'name' => 'VCALENDAR',
            'comp-filters' => [
                [
                    'name' => 'VEVENT',
                    'comp-filters' => [],
                    'prop-filters' => [],
                    'is-not-defined' => false,
                    'time-range' => null,
                ],
            ],
            'prop-filters' => [],
            'is-not-defined' => false,
            'time-range' => null,
        ];

        $this->assertEquals([
            'event1.ics',
        ], $abstract->calendarQuery(1, $filters));
    }

    public function testGetCalendarObjectByUID()
    {
        $abstract = new AbstractMock();
        $this->assertNull(
            $abstract->getCalendarObjectByUID('principal1', 'zim')
        );
        $this->assertEquals(
            'cal1/event1.ics',
            $abstract->getCalendarObjectByUID('principal1', 'foo')
        );
        $this->assertNull(
            $abstract->getCalendarObjectByUID('principal3', 'foo')
        );
        $this->assertNull(
            $abstract->getCalendarObjectByUID('principal1', 'shared')
        );
    }

    public function testGetMultipleCalendarObjects()
    {
        $abstract = new AbstractMock();
        $result = $abstract->getMultipleCalendarObjects(1, [
            'event1.ics',
            'task1.ics',
        ]);

        $expected = [
            [
                'id' => 1,
                'calendarid' => 1,
                'uri' => 'event1.ics',
                'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
            ],
            [
                'id' => 2,
                'calendarid' => 1,
                'uri' => 'task1.ics',
                'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n",
            ],
        ];

        $this->assertEquals($expected, $result);
    }
}

class AbstractMock extends AbstractBackend
{
    public function getCalendarsForUser($principalUri)
    {
        return [
            [
                'id' => 1,
                'principaluri' => 'principal1',
                'uri' => 'cal1',
            ],
            [
                'id' => 2,
                'principaluri' => 'principal1',
                '{http://sabredav.org/ns}owner-principal' => 'principal2',
                'uri' => 'cal1',
            ],
        ];
    }

    public function createCalendar($principalUri, $calendarUri, array $properties)
    {
    }

    public function deleteCalendar($calendarId)
    {
    }

    public function getCalendarObjects($calendarId)
    {
        switch ($calendarId) {
            case 1:
                return [
                    [
                        'id' => 1,
                        'calendarid' => 1,
                        'uri' => 'event1.ics',
                    ],
                    [
                        'id' => 2,
                        'calendarid' => 1,
                        'uri' => 'task1.ics',
                    ],
                ];
            case 2:
                return [
                    [
                        'id' => 3,
                        'calendarid' => 2,
                        'uri' => 'shared-event.ics',
                    ],
                ];
        }
    }

    public function getCalendarObject($calendarId, $objectUri)
    {
        switch ($objectUri) {
            case 'event1.ics':
                return [
                    'id' => 1,
                    'calendarid' => 1,
                    'uri' => 'event1.ics',
                    'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
                ];
            case 'task1.ics':
                return [
                    'id' => 2,
                    'calendarid' => 1,
                    'uri' => 'task1.ics',
                    'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n",
                ];
            case 'shared-event.ics':
                return [
                    'id' => 3,
                    'calendarid' => 2,
                    'uri' => 'event1.ics',
                    'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:shared\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
                ];
        }
    }

    public function createCalendarObject($calendarId, $objectUri, $calendarData)
    {
    }

    public function updateCalendarObject($calendarId, $objectUri, $calendarData)
    {
    }

    public function deleteCalendarObject($calendarId, $objectUri)
    {
    }
}