xref: /plugin/davcal/vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\CalDAV;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehleruse Sabre\DAV;
6*a1a3b679SAndreas Boehleruse Sabre\HTTP;
7*a1a3b679SAndreas Boehleruse Sabre\VObject;
8*a1a3b679SAndreas Boehleruse Sabre\DAVACL;
9*a1a3b679SAndreas Boehler
10*a1a3b679SAndreas Boehlerrequire_once 'Sabre/CalDAV/TestUtil.php';
11*a1a3b679SAndreas Boehlerrequire_once 'Sabre/HTTP/ResponseMock.php';
12*a1a3b679SAndreas Boehler
13*a1a3b679SAndreas Boehlerclass ICSExportPluginTest extends \PHPUnit_Framework_TestCase {
14*a1a3b679SAndreas Boehler
15*a1a3b679SAndreas Boehler    function setUp() {
16*a1a3b679SAndreas Boehler
17*a1a3b679SAndreas Boehler        if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
18*a1a3b679SAndreas Boehler
19*a1a3b679SAndreas Boehler    }
20*a1a3b679SAndreas Boehler
21*a1a3b679SAndreas Boehler    function testInit() {
22*a1a3b679SAndreas Boehler
23*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
24*a1a3b679SAndreas Boehler        $s = new DAV\Server();
25*a1a3b679SAndreas Boehler        $s->addPlugin($p);
26*a1a3b679SAndreas Boehler        $this->assertEquals($p, $s->getPlugin('ics-export'));
27*a1a3b679SAndreas Boehler
28*a1a3b679SAndreas Boehler    }
29*a1a3b679SAndreas Boehler
30*a1a3b679SAndreas Boehler    function testBeforeMethod() {
31*a1a3b679SAndreas Boehler
32*a1a3b679SAndreas Boehler        $cbackend = TestUtil::getBackend();
33*a1a3b679SAndreas Boehler
34*a1a3b679SAndreas Boehler        $props = [
35*a1a3b679SAndreas Boehler            'uri'=>'UUID-123467',
36*a1a3b679SAndreas Boehler            'principaluri' => 'admin',
37*a1a3b679SAndreas Boehler            'id' => 1,
38*a1a3b679SAndreas Boehler            '{DAV:}displayname' => 'Hello!',
39*a1a3b679SAndreas Boehler            '{http://apple.com/ns/ical/}calendar-color' => '#AA0000FF',
40*a1a3b679SAndreas Boehler        ];
41*a1a3b679SAndreas Boehler        $tree = [
42*a1a3b679SAndreas Boehler            new Calendar($cbackend,$props),
43*a1a3b679SAndreas Boehler        ];
44*a1a3b679SAndreas Boehler
45*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
46*a1a3b679SAndreas Boehler
47*a1a3b679SAndreas Boehler        $s = new DAV\Server($tree);
48*a1a3b679SAndreas Boehler        $s->addPlugin($p);
49*a1a3b679SAndreas Boehler        $s->addPlugin(new Plugin());
50*a1a3b679SAndreas Boehler
51*a1a3b679SAndreas Boehler        $h = HTTP\Sapi::createFromServerArray([
52*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/UUID-123467?export',
53*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'GET',
54*a1a3b679SAndreas Boehler        ]);
55*a1a3b679SAndreas Boehler
56*a1a3b679SAndreas Boehler        $s->httpRequest = $h;
57*a1a3b679SAndreas Boehler        $s->httpResponse = new HTTP\ResponseMock();
58*a1a3b679SAndreas Boehler
59*a1a3b679SAndreas Boehler        $this->assertFalse($p->httpGet($h, $s->httpResponse));
60*a1a3b679SAndreas Boehler
61*a1a3b679SAndreas Boehler        $this->assertEquals(200, $s->httpResponse->status);
62*a1a3b679SAndreas Boehler        $this->assertEquals([
63*a1a3b679SAndreas Boehler            'Content-Type' => ['text/calendar'],
64*a1a3b679SAndreas Boehler        ], $s->httpResponse->getHeaders());
65*a1a3b679SAndreas Boehler
66*a1a3b679SAndreas Boehler        $obj = VObject\Reader::read($s->httpResponse->body);
67*a1a3b679SAndreas Boehler
68*a1a3b679SAndreas Boehler        $this->assertEquals(7,count($obj->children()));
69*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->VERSION));
70*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->CALSCALE));
71*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->PRODID));
72*a1a3b679SAndreas Boehler        $this->assertTrue(strpos((string)$obj->PRODID, DAV\Version::VERSION)!==false);
73*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->VTIMEZONE));
74*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->VEVENT));
75*a1a3b679SAndreas Boehler        $this->assertEquals("Hello!", $obj->{"X-WR-CALNAME"});
76*a1a3b679SAndreas Boehler        $this->assertEquals("#AA0000FF", $obj->{"X-APPLE-CALENDAR-COLOR"});
77*a1a3b679SAndreas Boehler
78*a1a3b679SAndreas Boehler    }
79*a1a3b679SAndreas Boehler    function testBeforeMethodNoVersion() {
80*a1a3b679SAndreas Boehler
81*a1a3b679SAndreas Boehler        if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
82*a1a3b679SAndreas Boehler        $cbackend = TestUtil::getBackend();
83*a1a3b679SAndreas Boehler
84*a1a3b679SAndreas Boehler        $props = [
85*a1a3b679SAndreas Boehler            'uri'=>'UUID-123467',
86*a1a3b679SAndreas Boehler            'principaluri' => 'admin',
87*a1a3b679SAndreas Boehler            'id' => 1,
88*a1a3b679SAndreas Boehler        ];
89*a1a3b679SAndreas Boehler        $tree = [
90*a1a3b679SAndreas Boehler            new Calendar($cbackend,$props),
91*a1a3b679SAndreas Boehler        ];
92*a1a3b679SAndreas Boehler
93*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
94*a1a3b679SAndreas Boehler
95*a1a3b679SAndreas Boehler        $s = new DAV\Server($tree);
96*a1a3b679SAndreas Boehler
97*a1a3b679SAndreas Boehler        $s->addPlugin($p);
98*a1a3b679SAndreas Boehler        $s->addPlugin(new Plugin());
99*a1a3b679SAndreas Boehler
100*a1a3b679SAndreas Boehler        $h = HTTP\Sapi::createFromServerArray([
101*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/UUID-123467?export',
102*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'GET',
103*a1a3b679SAndreas Boehler        ]);
104*a1a3b679SAndreas Boehler
105*a1a3b679SAndreas Boehler        $s->httpRequest = $h;
106*a1a3b679SAndreas Boehler        $s->httpResponse = new HTTP\ResponseMock();
107*a1a3b679SAndreas Boehler
108*a1a3b679SAndreas Boehler        DAV\Server::$exposeVersion = false;
109*a1a3b679SAndreas Boehler        $this->assertFalse($p->httpGet($h, $s->httpResponse));
110*a1a3b679SAndreas Boehler        DAV\Server::$exposeVersion = true;
111*a1a3b679SAndreas Boehler
112*a1a3b679SAndreas Boehler        $this->assertEquals(200, $s->httpResponse->status);
113*a1a3b679SAndreas Boehler        $this->assertEquals([
114*a1a3b679SAndreas Boehler            'Content-Type' => ['text/calendar'],
115*a1a3b679SAndreas Boehler        ], $s->httpResponse->getHeaders());
116*a1a3b679SAndreas Boehler
117*a1a3b679SAndreas Boehler        $obj = VObject\Reader::read($s->httpResponse->body);
118*a1a3b679SAndreas Boehler
119*a1a3b679SAndreas Boehler        $this->assertEquals(5,count($obj->children()));
120*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->VERSION));
121*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->CALSCALE));
122*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->PRODID));
123*a1a3b679SAndreas Boehler        $this->assertFalse(strpos((string)$obj->PRODID, DAV\Version::VERSION)!==false);
124*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->VTIMEZONE));
125*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->VEVENT));
126*a1a3b679SAndreas Boehler
127*a1a3b679SAndreas Boehler    }
128*a1a3b679SAndreas Boehler
129*a1a3b679SAndreas Boehler    function testBeforeMethodNoExport() {
130*a1a3b679SAndreas Boehler
131*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
132*a1a3b679SAndreas Boehler
133*a1a3b679SAndreas Boehler        $s = new DAV\Server();
134*a1a3b679SAndreas Boehler        $s->addPlugin($p);
135*a1a3b679SAndreas Boehler
136*a1a3b679SAndreas Boehler        $h = HTTP\Sapi::createFromServerArray([
137*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/UUID-123467',
138*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'GET',
139*a1a3b679SAndreas Boehler        ]);
140*a1a3b679SAndreas Boehler        $this->assertNull($p->httpGet($h, $s->httpResponse));
141*a1a3b679SAndreas Boehler
142*a1a3b679SAndreas Boehler    }
143*a1a3b679SAndreas Boehler
144*a1a3b679SAndreas Boehler    function testACLIntegrationBlocked() {
145*a1a3b679SAndreas Boehler
146*a1a3b679SAndreas Boehler        $cbackend = TestUtil::getBackend();
147*a1a3b679SAndreas Boehler
148*a1a3b679SAndreas Boehler        $props = array(
149*a1a3b679SAndreas Boehler            'uri'=>'UUID-123467',
150*a1a3b679SAndreas Boehler            'principaluri' => 'admin',
151*a1a3b679SAndreas Boehler            'id' => 1,
152*a1a3b679SAndreas Boehler        );
153*a1a3b679SAndreas Boehler        $tree = array(
154*a1a3b679SAndreas Boehler            new Calendar($cbackend,$props),
155*a1a3b679SAndreas Boehler        );
156*a1a3b679SAndreas Boehler
157*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
158*a1a3b679SAndreas Boehler
159*a1a3b679SAndreas Boehler        $s = new DAV\Server($tree);
160*a1a3b679SAndreas Boehler        $s->addPlugin($p);
161*a1a3b679SAndreas Boehler        $s->addPlugin(new Plugin());
162*a1a3b679SAndreas Boehler        $s->addPlugin(new DAVACL\Plugin());
163*a1a3b679SAndreas Boehler
164*a1a3b679SAndreas Boehler        $h = HTTP\Sapi::createFromServerArray([
165*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/UUID-123467?export',
166*a1a3b679SAndreas Boehler        ]);
167*a1a3b679SAndreas Boehler
168*a1a3b679SAndreas Boehler        $s->httpRequest = $h;
169*a1a3b679SAndreas Boehler        $s->httpResponse = new HTTP\ResponseMock();
170*a1a3b679SAndreas Boehler
171*a1a3b679SAndreas Boehler        $p->httpGet($h, $s->httpResponse);
172*a1a3b679SAndreas Boehler
173*a1a3b679SAndreas Boehler        // If the ACL system blocked this request, the effect will be that
174*a1a3b679SAndreas Boehler        // there's no response, because the calendar information could not be
175*a1a3b679SAndreas Boehler        // fetched.
176*a1a3b679SAndreas Boehler        $this->assertNull($s->httpResponse->getStatus());
177*a1a3b679SAndreas Boehler
178*a1a3b679SAndreas Boehler    }
179*a1a3b679SAndreas Boehler
180*a1a3b679SAndreas Boehler    function testACLIntegrationNotBlocked() {
181*a1a3b679SAndreas Boehler
182*a1a3b679SAndreas Boehler        $cbackend = TestUtil::getBackend();
183*a1a3b679SAndreas Boehler        $pbackend = new DAVACL\PrincipalBackend\Mock();
184*a1a3b679SAndreas Boehler
185*a1a3b679SAndreas Boehler        $props = array(
186*a1a3b679SAndreas Boehler            'uri'=>'UUID-123467',
187*a1a3b679SAndreas Boehler            'principaluri' => 'admin',
188*a1a3b679SAndreas Boehler            'id' => 1,
189*a1a3b679SAndreas Boehler        );
190*a1a3b679SAndreas Boehler        $tree = array(
191*a1a3b679SAndreas Boehler            new Calendar($cbackend,$props),
192*a1a3b679SAndreas Boehler            new DAVACL\PrincipalCollection($pbackend),
193*a1a3b679SAndreas Boehler        );
194*a1a3b679SAndreas Boehler
195*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
196*a1a3b679SAndreas Boehler
197*a1a3b679SAndreas Boehler        $s = new DAV\Server($tree);
198*a1a3b679SAndreas Boehler        $s->sapi = new HTTP\SapiMock();
199*a1a3b679SAndreas Boehler        $s->addPlugin($p);
200*a1a3b679SAndreas Boehler        $s->addPlugin(new Plugin());
201*a1a3b679SAndreas Boehler        $s->addPlugin(new DAVACL\Plugin());
202*a1a3b679SAndreas Boehler        $s->addPlugin(new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'SabreDAV'));
203*a1a3b679SAndreas Boehler
204*a1a3b679SAndreas Boehler        // Forcing login
205*a1a3b679SAndreas Boehler        $s->getPlugin('acl')->adminPrincipals = array('principals/admin');
206*a1a3b679SAndreas Boehler
207*a1a3b679SAndreas Boehler
208*a1a3b679SAndreas Boehler        $h = HTTP\Sapi::createFromServerArray([
209*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/UUID-123467?export',
210*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'GET',
211*a1a3b679SAndreas Boehler        ]);
212*a1a3b679SAndreas Boehler
213*a1a3b679SAndreas Boehler        $s->httpRequest = $h;
214*a1a3b679SAndreas Boehler        $s->httpResponse = new HTTP\ResponseMock();
215*a1a3b679SAndreas Boehler
216*a1a3b679SAndreas Boehler        $s->exec();
217*a1a3b679SAndreas Boehler
218*a1a3b679SAndreas Boehler        $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
219*a1a3b679SAndreas Boehler        $this->assertEquals(array(
220*a1a3b679SAndreas Boehler            'X-Sabre-Version' => [DAV\Version::VERSION],
221*a1a3b679SAndreas Boehler            'Content-Type' => ['text/calendar'],
222*a1a3b679SAndreas Boehler        ), $s->httpResponse->getHeaders());
223*a1a3b679SAndreas Boehler
224*a1a3b679SAndreas Boehler        $obj = VObject\Reader::read($s->httpResponse->body);
225*a1a3b679SAndreas Boehler
226*a1a3b679SAndreas Boehler        $this->assertEquals(5,count($obj->children()));
227*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->VERSION));
228*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->CALSCALE));
229*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->PRODID));
230*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->VTIMEZONE));
231*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->VEVENT));
232*a1a3b679SAndreas Boehler
233*a1a3b679SAndreas Boehler    }
234*a1a3b679SAndreas Boehler
235*a1a3b679SAndreas Boehler    function testBadStartParam() {
236*a1a3b679SAndreas Boehler
237*a1a3b679SAndreas Boehler        $cbackend = TestUtil::getBackend();
238*a1a3b679SAndreas Boehler        $pbackend = new DAVACL\PrincipalBackend\Mock();
239*a1a3b679SAndreas Boehler
240*a1a3b679SAndreas Boehler        $props = array(
241*a1a3b679SAndreas Boehler            'uri'=>'UUID-123467',
242*a1a3b679SAndreas Boehler            'principaluri' => 'admin',
243*a1a3b679SAndreas Boehler            'id' => 1,
244*a1a3b679SAndreas Boehler        );
245*a1a3b679SAndreas Boehler        $tree = array(
246*a1a3b679SAndreas Boehler            new Calendar($cbackend,$props),
247*a1a3b679SAndreas Boehler            new DAVACL\PrincipalCollection($pbackend),
248*a1a3b679SAndreas Boehler        );
249*a1a3b679SAndreas Boehler
250*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
251*a1a3b679SAndreas Boehler
252*a1a3b679SAndreas Boehler        $s = new DAV\Server($tree);
253*a1a3b679SAndreas Boehler        $s->sapi = new HTTP\SapiMock();
254*a1a3b679SAndreas Boehler        $s->addPlugin($p);
255*a1a3b679SAndreas Boehler        $s->addPlugin(new Plugin());
256*a1a3b679SAndreas Boehler
257*a1a3b679SAndreas Boehler        $h = HTTP\Sapi::createFromServerArray([
258*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/UUID-123467?export&start=foo',
259*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'GET',
260*a1a3b679SAndreas Boehler        ]);
261*a1a3b679SAndreas Boehler
262*a1a3b679SAndreas Boehler        $s->httpRequest = $h;
263*a1a3b679SAndreas Boehler        $s->httpResponse = new HTTP\ResponseMock();
264*a1a3b679SAndreas Boehler
265*a1a3b679SAndreas Boehler        $s->exec();
266*a1a3b679SAndreas Boehler
267*a1a3b679SAndreas Boehler        $this->assertEquals(400, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
268*a1a3b679SAndreas Boehler
269*a1a3b679SAndreas Boehler    }
270*a1a3b679SAndreas Boehler
271*a1a3b679SAndreas Boehler    function testBadEndParam() {
272*a1a3b679SAndreas Boehler
273*a1a3b679SAndreas Boehler        $cbackend = TestUtil::getBackend();
274*a1a3b679SAndreas Boehler        $pbackend = new DAVACL\PrincipalBackend\Mock();
275*a1a3b679SAndreas Boehler
276*a1a3b679SAndreas Boehler        $props = array(
277*a1a3b679SAndreas Boehler            'uri'=>'UUID-123467',
278*a1a3b679SAndreas Boehler            'principaluri' => 'admin',
279*a1a3b679SAndreas Boehler            'id' => 1,
280*a1a3b679SAndreas Boehler        );
281*a1a3b679SAndreas Boehler        $tree = array(
282*a1a3b679SAndreas Boehler            new Calendar($cbackend,$props),
283*a1a3b679SAndreas Boehler            new DAVACL\PrincipalCollection($pbackend),
284*a1a3b679SAndreas Boehler        );
285*a1a3b679SAndreas Boehler
286*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
287*a1a3b679SAndreas Boehler
288*a1a3b679SAndreas Boehler        $s = new DAV\Server($tree);
289*a1a3b679SAndreas Boehler        $s->sapi = new HTTP\SapiMock();
290*a1a3b679SAndreas Boehler        $s->addPlugin($p);
291*a1a3b679SAndreas Boehler        $s->addPlugin(new Plugin());
292*a1a3b679SAndreas Boehler
293*a1a3b679SAndreas Boehler        $h = HTTP\Sapi::createFromServerArray([
294*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/UUID-123467?export&end=foo',
295*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'GET',
296*a1a3b679SAndreas Boehler        ]);
297*a1a3b679SAndreas Boehler
298*a1a3b679SAndreas Boehler        $s->httpRequest = $h;
299*a1a3b679SAndreas Boehler        $s->httpResponse = new HTTP\ResponseMock();
300*a1a3b679SAndreas Boehler
301*a1a3b679SAndreas Boehler        $s->exec();
302*a1a3b679SAndreas Boehler
303*a1a3b679SAndreas Boehler        $this->assertEquals(400, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
304*a1a3b679SAndreas Boehler
305*a1a3b679SAndreas Boehler    }
306*a1a3b679SAndreas Boehler
307*a1a3b679SAndreas Boehler    function testFilterStartEnd() {
308*a1a3b679SAndreas Boehler
309*a1a3b679SAndreas Boehler        $cbackend = TestUtil::getBackend();
310*a1a3b679SAndreas Boehler        $pbackend = new DAVACL\PrincipalBackend\Mock();
311*a1a3b679SAndreas Boehler
312*a1a3b679SAndreas Boehler        $props = array(
313*a1a3b679SAndreas Boehler            'uri'=>'UUID-123467',
314*a1a3b679SAndreas Boehler            'principaluri' => 'admin',
315*a1a3b679SAndreas Boehler            'id' => 1,
316*a1a3b679SAndreas Boehler        );
317*a1a3b679SAndreas Boehler        $tree = array(
318*a1a3b679SAndreas Boehler            new Calendar($cbackend,$props),
319*a1a3b679SAndreas Boehler            new DAVACL\PrincipalCollection($pbackend),
320*a1a3b679SAndreas Boehler        );
321*a1a3b679SAndreas Boehler
322*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
323*a1a3b679SAndreas Boehler
324*a1a3b679SAndreas Boehler        $s = new DAV\Server($tree);
325*a1a3b679SAndreas Boehler        $s->sapi = new HTTP\SapiMock();
326*a1a3b679SAndreas Boehler        $s->addPlugin($p);
327*a1a3b679SAndreas Boehler        $s->addPlugin(new Plugin());
328*a1a3b679SAndreas Boehler
329*a1a3b679SAndreas Boehler        $h = HTTP\Sapi::createFromServerArray([
330*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/UUID-123467?export&start=1&end=2',
331*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'GET',
332*a1a3b679SAndreas Boehler        ]);
333*a1a3b679SAndreas Boehler
334*a1a3b679SAndreas Boehler        $s->httpRequest = $h;
335*a1a3b679SAndreas Boehler        $s->httpResponse = new HTTP\ResponseMock();
336*a1a3b679SAndreas Boehler
337*a1a3b679SAndreas Boehler        $s->exec();
338*a1a3b679SAndreas Boehler
339*a1a3b679SAndreas Boehler        $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
340*a1a3b679SAndreas Boehler        $obj = VObject\Reader::read($s->httpResponse->body);
341*a1a3b679SAndreas Boehler
342*a1a3b679SAndreas Boehler        $this->assertEquals(0,count($obj->VTIMEZONE));
343*a1a3b679SAndreas Boehler        $this->assertEquals(0,count($obj->VEVENT));
344*a1a3b679SAndreas Boehler
345*a1a3b679SAndreas Boehler    }
346*a1a3b679SAndreas Boehler
347*a1a3b679SAndreas Boehler    function testExpandNoStart() {
348*a1a3b679SAndreas Boehler
349*a1a3b679SAndreas Boehler        $cbackend = TestUtil::getBackend();
350*a1a3b679SAndreas Boehler        $pbackend = new DAVACL\PrincipalBackend\Mock();
351*a1a3b679SAndreas Boehler
352*a1a3b679SAndreas Boehler        $props = array(
353*a1a3b679SAndreas Boehler            'uri'=>'UUID-123467',
354*a1a3b679SAndreas Boehler            'principaluri' => 'admin',
355*a1a3b679SAndreas Boehler            'id' => 1,
356*a1a3b679SAndreas Boehler        );
357*a1a3b679SAndreas Boehler        $tree = array(
358*a1a3b679SAndreas Boehler            new Calendar($cbackend,$props),
359*a1a3b679SAndreas Boehler            new DAVACL\PrincipalCollection($pbackend),
360*a1a3b679SAndreas Boehler        );
361*a1a3b679SAndreas Boehler
362*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
363*a1a3b679SAndreas Boehler
364*a1a3b679SAndreas Boehler        $s = new DAV\Server($tree);
365*a1a3b679SAndreas Boehler        $s->sapi = new HTTP\SapiMock();
366*a1a3b679SAndreas Boehler        $s->addPlugin($p);
367*a1a3b679SAndreas Boehler        $s->addPlugin(new Plugin());
368*a1a3b679SAndreas Boehler
369*a1a3b679SAndreas Boehler        $h = HTTP\Sapi::createFromServerArray([
370*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/UUID-123467?export&expand=1&end=1',
371*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'GET',
372*a1a3b679SAndreas Boehler        ]);
373*a1a3b679SAndreas Boehler
374*a1a3b679SAndreas Boehler        $s->httpRequest = $h;
375*a1a3b679SAndreas Boehler        $s->httpResponse = new HTTP\ResponseMock();
376*a1a3b679SAndreas Boehler
377*a1a3b679SAndreas Boehler        $s->exec();
378*a1a3b679SAndreas Boehler
379*a1a3b679SAndreas Boehler        $this->assertEquals(400, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
380*a1a3b679SAndreas Boehler
381*a1a3b679SAndreas Boehler    }
382*a1a3b679SAndreas Boehler
383*a1a3b679SAndreas Boehler    function testExpand() {
384*a1a3b679SAndreas Boehler
385*a1a3b679SAndreas Boehler        $cbackend = TestUtil::getBackend();
386*a1a3b679SAndreas Boehler        $pbackend = new DAVACL\PrincipalBackend\Mock();
387*a1a3b679SAndreas Boehler
388*a1a3b679SAndreas Boehler        $props = array(
389*a1a3b679SAndreas Boehler            'uri'=>'UUID-123467',
390*a1a3b679SAndreas Boehler            'principaluri' => 'admin',
391*a1a3b679SAndreas Boehler            'id' => 1,
392*a1a3b679SAndreas Boehler        );
393*a1a3b679SAndreas Boehler        $tree = array(
394*a1a3b679SAndreas Boehler            new Calendar($cbackend,$props),
395*a1a3b679SAndreas Boehler            new DAVACL\PrincipalCollection($pbackend),
396*a1a3b679SAndreas Boehler        );
397*a1a3b679SAndreas Boehler
398*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
399*a1a3b679SAndreas Boehler
400*a1a3b679SAndreas Boehler        $s = new DAV\Server($tree);
401*a1a3b679SAndreas Boehler        $s->sapi = new HTTP\SapiMock();
402*a1a3b679SAndreas Boehler        $s->addPlugin($p);
403*a1a3b679SAndreas Boehler        $s->addPlugin(new Plugin());
404*a1a3b679SAndreas Boehler
405*a1a3b679SAndreas Boehler        $h = HTTP\Sapi::createFromServerArray([
406*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/UUID-123467?export&start=1&end=2000000000&expand=1',
407*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'GET',
408*a1a3b679SAndreas Boehler        ]);
409*a1a3b679SAndreas Boehler
410*a1a3b679SAndreas Boehler        $s->httpRequest = $h;
411*a1a3b679SAndreas Boehler        $s->httpResponse = new HTTP\ResponseMock();
412*a1a3b679SAndreas Boehler
413*a1a3b679SAndreas Boehler        $s->exec();
414*a1a3b679SAndreas Boehler
415*a1a3b679SAndreas Boehler        $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
416*a1a3b679SAndreas Boehler        $obj = VObject\Reader::read($s->httpResponse->body);
417*a1a3b679SAndreas Boehler
418*a1a3b679SAndreas Boehler        $this->assertEquals(0,count($obj->VTIMEZONE));
419*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->VEVENT));
420*a1a3b679SAndreas Boehler
421*a1a3b679SAndreas Boehler    }
422*a1a3b679SAndreas Boehler
423*a1a3b679SAndreas Boehler    function testJCal() {
424*a1a3b679SAndreas Boehler
425*a1a3b679SAndreas Boehler        $cbackend = TestUtil::getBackend();
426*a1a3b679SAndreas Boehler        $pbackend = new DAVACL\PrincipalBackend\Mock();
427*a1a3b679SAndreas Boehler
428*a1a3b679SAndreas Boehler        $props = array(
429*a1a3b679SAndreas Boehler            'uri'=>'UUID-123467',
430*a1a3b679SAndreas Boehler            'principaluri' => 'admin',
431*a1a3b679SAndreas Boehler            'id' => 1,
432*a1a3b679SAndreas Boehler        );
433*a1a3b679SAndreas Boehler        $tree = array(
434*a1a3b679SAndreas Boehler            new Calendar($cbackend,$props),
435*a1a3b679SAndreas Boehler            new DAVACL\PrincipalCollection($pbackend),
436*a1a3b679SAndreas Boehler        );
437*a1a3b679SAndreas Boehler
438*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
439*a1a3b679SAndreas Boehler
440*a1a3b679SAndreas Boehler        $s = new DAV\Server($tree);
441*a1a3b679SAndreas Boehler        $s->sapi = new HTTP\SapiMock();
442*a1a3b679SAndreas Boehler        $s->addPlugin($p);
443*a1a3b679SAndreas Boehler        $s->addPlugin(new Plugin());
444*a1a3b679SAndreas Boehler
445*a1a3b679SAndreas Boehler        $h = HTTP\Sapi::createFromServerArray([
446*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/UUID-123467?export',
447*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'GET',
448*a1a3b679SAndreas Boehler            'HTTP_ACCEPT' => 'application/calendar+json',
449*a1a3b679SAndreas Boehler        ]);
450*a1a3b679SAndreas Boehler
451*a1a3b679SAndreas Boehler        $s->httpRequest = $h;
452*a1a3b679SAndreas Boehler        $s->httpResponse = new HTTP\ResponseMock();
453*a1a3b679SAndreas Boehler
454*a1a3b679SAndreas Boehler        $s->exec();
455*a1a3b679SAndreas Boehler
456*a1a3b679SAndreas Boehler        $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
457*a1a3b679SAndreas Boehler        $this->assertEquals('application/calendar+json', $s->httpResponse->getHeader('Content-Type'));
458*a1a3b679SAndreas Boehler
459*a1a3b679SAndreas Boehler    }
460*a1a3b679SAndreas Boehler
461*a1a3b679SAndreas Boehler    function testJCalInUrl() {
462*a1a3b679SAndreas Boehler
463*a1a3b679SAndreas Boehler        $cbackend = TestUtil::getBackend();
464*a1a3b679SAndreas Boehler        $pbackend = new DAVACL\PrincipalBackend\Mock();
465*a1a3b679SAndreas Boehler
466*a1a3b679SAndreas Boehler        $props = array(
467*a1a3b679SAndreas Boehler            'uri'=>'UUID-123467',
468*a1a3b679SAndreas Boehler            'principaluri' => 'admin',
469*a1a3b679SAndreas Boehler            'id' => 1,
470*a1a3b679SAndreas Boehler        );
471*a1a3b679SAndreas Boehler        $tree = array(
472*a1a3b679SAndreas Boehler            new Calendar($cbackend,$props),
473*a1a3b679SAndreas Boehler            new DAVACL\PrincipalCollection($pbackend),
474*a1a3b679SAndreas Boehler        );
475*a1a3b679SAndreas Boehler
476*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
477*a1a3b679SAndreas Boehler
478*a1a3b679SAndreas Boehler        $s = new DAV\Server($tree);
479*a1a3b679SAndreas Boehler        $s->sapi = new HTTP\SapiMock();
480*a1a3b679SAndreas Boehler        $s->addPlugin($p);
481*a1a3b679SAndreas Boehler        $s->addPlugin(new Plugin());
482*a1a3b679SAndreas Boehler
483*a1a3b679SAndreas Boehler        $h = HTTP\Sapi::createFromServerArray([
484*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/UUID-123467?export&accept=jcal',
485*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'GET',
486*a1a3b679SAndreas Boehler        ]);
487*a1a3b679SAndreas Boehler
488*a1a3b679SAndreas Boehler        $s->httpRequest = $h;
489*a1a3b679SAndreas Boehler        $s->httpResponse = new HTTP\ResponseMock();
490*a1a3b679SAndreas Boehler
491*a1a3b679SAndreas Boehler        $s->exec();
492*a1a3b679SAndreas Boehler
493*a1a3b679SAndreas Boehler        $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
494*a1a3b679SAndreas Boehler        $this->assertEquals('application/calendar+json', $s->httpResponse->getHeader('Content-Type'));
495*a1a3b679SAndreas Boehler
496*a1a3b679SAndreas Boehler    }
497*a1a3b679SAndreas Boehler
498*a1a3b679SAndreas Boehler    function testNegotiateDefault() {
499*a1a3b679SAndreas Boehler
500*a1a3b679SAndreas Boehler        $cbackend = TestUtil::getBackend();
501*a1a3b679SAndreas Boehler        $pbackend = new DAVACL\PrincipalBackend\Mock();
502*a1a3b679SAndreas Boehler
503*a1a3b679SAndreas Boehler        $props = array(
504*a1a3b679SAndreas Boehler            'uri'=>'UUID-123467',
505*a1a3b679SAndreas Boehler            'principaluri' => 'admin',
506*a1a3b679SAndreas Boehler            'id' => 1,
507*a1a3b679SAndreas Boehler        );
508*a1a3b679SAndreas Boehler        $tree = array(
509*a1a3b679SAndreas Boehler            new Calendar($cbackend,$props),
510*a1a3b679SAndreas Boehler            new DAVACL\PrincipalCollection($pbackend),
511*a1a3b679SAndreas Boehler        );
512*a1a3b679SAndreas Boehler
513*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
514*a1a3b679SAndreas Boehler
515*a1a3b679SAndreas Boehler        $s = new DAV\Server($tree);
516*a1a3b679SAndreas Boehler        $s->sapi = new HTTP\SapiMock();
517*a1a3b679SAndreas Boehler        $s->addPlugin($p);
518*a1a3b679SAndreas Boehler        $s->addPlugin(new Plugin());
519*a1a3b679SAndreas Boehler
520*a1a3b679SAndreas Boehler        $h = HTTP\Sapi::createFromServerArray([
521*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/UUID-123467?export',
522*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'GET',
523*a1a3b679SAndreas Boehler            'HTTP_ACCEPT' => 'text/plain',
524*a1a3b679SAndreas Boehler        ]);
525*a1a3b679SAndreas Boehler
526*a1a3b679SAndreas Boehler        $s->httpRequest = $h;
527*a1a3b679SAndreas Boehler        $s->httpResponse = new HTTP\ResponseMock();
528*a1a3b679SAndreas Boehler
529*a1a3b679SAndreas Boehler        $s->exec();
530*a1a3b679SAndreas Boehler
531*a1a3b679SAndreas Boehler        $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
532*a1a3b679SAndreas Boehler        $this->assertEquals('text/calendar', $s->httpResponse->getHeader('Content-Type'));
533*a1a3b679SAndreas Boehler
534*a1a3b679SAndreas Boehler    }
535*a1a3b679SAndreas Boehler
536*a1a3b679SAndreas Boehler    function testFilterComponentVEVENT() {
537*a1a3b679SAndreas Boehler
538*a1a3b679SAndreas Boehler        $cbackend = TestUtil::getBackend();
539*a1a3b679SAndreas Boehler        $pbackend = new DAVACL\PrincipalBackend\Mock();
540*a1a3b679SAndreas Boehler
541*a1a3b679SAndreas Boehler        $props = array(
542*a1a3b679SAndreas Boehler            'uri'=>'UUID-123467',
543*a1a3b679SAndreas Boehler            'principaluri' => 'admin',
544*a1a3b679SAndreas Boehler            'id' => 1,
545*a1a3b679SAndreas Boehler        );
546*a1a3b679SAndreas Boehler        // add a todo to the calendar (see /tests/Sabre/TestUtil)
547*a1a3b679SAndreas Boehler        $cbackend->createCalendarObject(1, 'UUID-3456', TestUtil::getTestTODO());
548*a1a3b679SAndreas Boehler
549*a1a3b679SAndreas Boehler        $tree = array(
550*a1a3b679SAndreas Boehler            new Calendar($cbackend,$props),
551*a1a3b679SAndreas Boehler            new DAVACL\PrincipalCollection($pbackend),
552*a1a3b679SAndreas Boehler        );
553*a1a3b679SAndreas Boehler
554*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
555*a1a3b679SAndreas Boehler
556*a1a3b679SAndreas Boehler        $s = new DAV\Server($tree);
557*a1a3b679SAndreas Boehler        $s->sapi = new HTTP\SapiMock();
558*a1a3b679SAndreas Boehler        $s->addPlugin($p);
559*a1a3b679SAndreas Boehler        $s->addPlugin(new Plugin());
560*a1a3b679SAndreas Boehler
561*a1a3b679SAndreas Boehler        $h = HTTP\Sapi::createFromServerArray([
562*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/UUID-123467?export&componentType=VEVENT',
563*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'GET',
564*a1a3b679SAndreas Boehler        ]);
565*a1a3b679SAndreas Boehler
566*a1a3b679SAndreas Boehler        $s->httpRequest = $h;
567*a1a3b679SAndreas Boehler        $s->httpResponse = new HTTP\ResponseMock();
568*a1a3b679SAndreas Boehler
569*a1a3b679SAndreas Boehler        $s->exec();
570*a1a3b679SAndreas Boehler
571*a1a3b679SAndreas Boehler        $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
572*a1a3b679SAndreas Boehler        $obj = VObject\Reader::read($s->httpResponse->body);
573*a1a3b679SAndreas Boehler
574*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->VTIMEZONE));
575*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->VEVENT));
576*a1a3b679SAndreas Boehler        $this->assertEquals(0,count($obj->VTODO));
577*a1a3b679SAndreas Boehler
578*a1a3b679SAndreas Boehler    }
579*a1a3b679SAndreas Boehler
580*a1a3b679SAndreas Boehler    function testFilterComponentVTODO() {
581*a1a3b679SAndreas Boehler
582*a1a3b679SAndreas Boehler        $cbackend = TestUtil::getBackend();
583*a1a3b679SAndreas Boehler        $pbackend = new DAVACL\PrincipalBackend\Mock();
584*a1a3b679SAndreas Boehler
585*a1a3b679SAndreas Boehler        $props = [
586*a1a3b679SAndreas Boehler            'uri'=>'UUID-123467',
587*a1a3b679SAndreas Boehler            'principaluri' => 'admin',
588*a1a3b679SAndreas Boehler            'id' => 1,
589*a1a3b679SAndreas Boehler        ];
590*a1a3b679SAndreas Boehler        // add a todo to the calendar (see /tests/Sabre/TestUtil)
591*a1a3b679SAndreas Boehler        $cbackend->createCalendarObject(1, 'UUID-3456', TestUtil::getTestTODO());
592*a1a3b679SAndreas Boehler
593*a1a3b679SAndreas Boehler        $tree = [
594*a1a3b679SAndreas Boehler            new Calendar($cbackend,$props),
595*a1a3b679SAndreas Boehler            new DAVACL\PrincipalCollection($pbackend),
596*a1a3b679SAndreas Boehler        ];
597*a1a3b679SAndreas Boehler
598*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
599*a1a3b679SAndreas Boehler
600*a1a3b679SAndreas Boehler        $s = new DAV\Server($tree);
601*a1a3b679SAndreas Boehler        $s->sapi = new HTTP\SapiMock();
602*a1a3b679SAndreas Boehler        $s->addPlugin($p);
603*a1a3b679SAndreas Boehler        $s->addPlugin(new Plugin());
604*a1a3b679SAndreas Boehler
605*a1a3b679SAndreas Boehler        $h = HTTP\Sapi::createFromServerArray([
606*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/UUID-123467?export&componentType=VTODO',
607*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'GET',
608*a1a3b679SAndreas Boehler        ]);
609*a1a3b679SAndreas Boehler
610*a1a3b679SAndreas Boehler        $s->httpRequest = $h;
611*a1a3b679SAndreas Boehler        $s->httpResponse = new HTTP\ResponseMock();
612*a1a3b679SAndreas Boehler
613*a1a3b679SAndreas Boehler        $s->exec();
614*a1a3b679SAndreas Boehler
615*a1a3b679SAndreas Boehler        $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
616*a1a3b679SAndreas Boehler        $obj = VObject\Reader::read($s->httpResponse->body);
617*a1a3b679SAndreas Boehler
618*a1a3b679SAndreas Boehler        $this->assertEquals(0,count($obj->VTIMEZONE));
619*a1a3b679SAndreas Boehler        $this->assertEquals(0,count($obj->VEVENT));
620*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($obj->VTODO));
621*a1a3b679SAndreas Boehler
622*a1a3b679SAndreas Boehler    }
623*a1a3b679SAndreas Boehler
624*a1a3b679SAndreas Boehler    function testFilterComponentBadComponent() {
625*a1a3b679SAndreas Boehler
626*a1a3b679SAndreas Boehler        $cbackend = TestUtil::getBackend();
627*a1a3b679SAndreas Boehler        $pbackend = new DAVACL\PrincipalBackend\Mock();
628*a1a3b679SAndreas Boehler
629*a1a3b679SAndreas Boehler        $props = [
630*a1a3b679SAndreas Boehler            'uri'=>'UUID-123467',
631*a1a3b679SAndreas Boehler            'principaluri' => 'admin',
632*a1a3b679SAndreas Boehler            'id' => 1,
633*a1a3b679SAndreas Boehler        ];
634*a1a3b679SAndreas Boehler        // add a todo to the calendar (see /tests/Sabre/TestUtil)
635*a1a3b679SAndreas Boehler        $cbackend->createCalendarObject(1, 'UUID-3456', TestUtil::getTestTODO());
636*a1a3b679SAndreas Boehler
637*a1a3b679SAndreas Boehler        $tree = [
638*a1a3b679SAndreas Boehler            new Calendar($cbackend,$props),
639*a1a3b679SAndreas Boehler            new DAVACL\PrincipalCollection($pbackend),
640*a1a3b679SAndreas Boehler        ];
641*a1a3b679SAndreas Boehler
642*a1a3b679SAndreas Boehler        $p = new ICSExportPlugin();
643*a1a3b679SAndreas Boehler
644*a1a3b679SAndreas Boehler        $s = new DAV\Server($tree);
645*a1a3b679SAndreas Boehler        $s->sapi = new HTTP\SapiMock();
646*a1a3b679SAndreas Boehler        $s->addPlugin($p);
647*a1a3b679SAndreas Boehler        $s->addPlugin(new Plugin());
648*a1a3b679SAndreas Boehler
649*a1a3b679SAndreas Boehler        $h = HTTP\Sapi::createFromServerArray([
650*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/UUID-123467?export&componentType=VVOODOO',
651*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'GET',
652*a1a3b679SAndreas Boehler        ]);
653*a1a3b679SAndreas Boehler
654*a1a3b679SAndreas Boehler        $s->httpRequest = $h;
655*a1a3b679SAndreas Boehler        $s->httpResponse = new HTTP\ResponseMock();
656*a1a3b679SAndreas Boehler
657*a1a3b679SAndreas Boehler        $s->exec();
658*a1a3b679SAndreas Boehler
659*a1a3b679SAndreas Boehler        $this->assertEquals(400, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body);
660*a1a3b679SAndreas Boehler
661*a1a3b679SAndreas Boehler    }
662*a1a3b679SAndreas Boehler}
663