1<?php
2
3namespace Sabre\CalDAV;
4
5use
6    Sabre\DAV\MkCol,
7    Sabre\DAVACL;
8
9class CalendarHomeSubscriptionsTest extends \PHPUnit_Framework_TestCase {
10
11    protected $backend;
12
13    function getInstance() {
14
15        $props = [
16            '{DAV:}displayname' => 'baz',
17            '{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/test.ics'),
18        ];
19        $principal = [
20            'uri' => 'principals/user1'
21        ];
22        $this->backend = new Backend\MockSubscriptionSupport([], []);
23        $this->backend->createSubscription('principals/user1', 'uri', $props);
24
25        return new CalendarHome($this->backend, $principal);
26
27    }
28
29    function testSimple() {
30
31        $instance = $this->getInstance();
32        $this->assertEquals('user1', $instance->getName());
33
34    }
35
36    function testGetChildren() {
37
38        $instance = $this->getInstance();
39        $children = $instance->getChildren();
40        $this->assertEquals(1, count($children));
41        foreach($children as $child) {
42            if ($child instanceof Subscriptions\Subscription) {
43                return;
44            }
45        }
46        $this->fail('There were no subscription nodes in the calendar home');
47
48    }
49
50    function testCreateSubscription() {
51
52        $instance = $this->getInstance();
53        $rt = ['{DAV:}collection', '{http://calendarserver.org/ns/}subscribed'];
54
55        $props = [
56            '{DAV:}displayname' => 'baz',
57            '{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/test2.ics'),
58        ];
59        $instance->createExtendedCollection('sub2', new MkCol($rt, $props));
60
61        $children = $instance->getChildren();
62        $this->assertEquals(2, count($children));
63
64    }
65
66    /**
67     * @expectedException \Sabre\DAV\Exception\InvalidResourceType
68     */
69    function testNoSubscriptionSupport() {
70
71        $principal = [
72            'uri' => 'principals/user1'
73        ];
74        $backend = new Backend\Mock([], []);
75        $uC = new CalendarHome($backend, $principal);
76
77        $rt = ['{DAV:}collection', '{http://calendarserver.org/ns/}subscribed'];
78
79        $props = [
80            '{DAV:}displayname' => 'baz',
81            '{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/test2.ics'),
82        ];
83        $uC->createExtendedCollection('sub2', new MkCol($rt, $props));
84
85    }
86
87}
88